-
-
Notifications
You must be signed in to change notification settings - Fork 670
WIP: Indirect calls on null trapping #961
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -251,5 +251,6 @@ | |
end | ||
) | ||
(func $null (; 3 ;) (type $FUNCSIG$v) | ||
unreachable | ||
) | ||
) |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2225,5 +2225,6 @@ | |
global.set $~lib/rt/stub/offset | ||
) | ||
(func $null (; 24 ;) (type $FUNCSIG$v) | ||
unreachable | ||
) | ||
) |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -484,5 +484,6 @@ | |
end | ||
) | ||
(func $null (; 18 ;) (type $FUNCSIG$v) | ||
unreachable | ||
) | ||
) |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -749,5 +749,6 @@ | |
global.set $assembly/i64/hi | ||
) | ||
(func $null (; 31 ;) (type $FUNCSIG$v) | ||
unreachable | ||
) | ||
) |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -408,6 +408,11 @@ export class Compiler extends DiagnosticEmitter { | |
module.removeGlobal(BuiltinSymbols.rtti_base); | ||
if (this.runtimeFeatures & RuntimeFeatures.RTTI) compileRTTI(this); | ||
|
||
// set up function table | ||
var functionTable = this.functionTable; | ||
module.setFunctionTable(functionTable.length, 0xffffffff, functionTable, module.i32(0)); | ||
this.addNullPointerExceptionHandling(module); | ||
|
||
// update the heap base pointer | ||
var memoryOffset = this.memoryOffset; | ||
memoryOffset = i64_align(memoryOffset, options.usizeType.byteSize); | ||
|
@@ -447,11 +452,6 @@ export class Compiler extends DiagnosticEmitter { | |
// import memory if requested (default memory is named '0' by Binaryen) | ||
if (options.importMemory) module.addMemoryImport("0", "env", "memory", isSharedMemory); | ||
|
||
// set up function table | ||
var functionTable = this.functionTable; | ||
module.setFunctionTable(functionTable.length, 0xffffffff, functionTable, module.i32(0)); | ||
module.addFunction("null", this.ensureFunctionType(null, Type.void), null, module.block(null, [])); | ||
|
||
// import table if requested (default table is named '0' by Binaryen) | ||
if (options.importTable) module.addTableImport("0", "env", "table"); | ||
|
||
|
@@ -462,6 +462,36 @@ export class Compiler extends DiagnosticEmitter { | |
return module; | ||
} | ||
|
||
addNullPointerExceptionHandling(module: Module) { | ||
if (this.options.hasFeature(Feature.EXCEPTION_HANDLING)) { | ||
let message = this.ensureStaticString("null is not a function"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Also, bikeshedding welcome on the error message, as always. |
||
let exceptionType = module.addFunctionType( | ||
"NullPointerException", | ||
NativeType.None, | ||
[NativeType.I32] | ||
); | ||
|
||
module.addEvent("NullPointerException", 0, exceptionType); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For that real Java There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. btw this string is only used as a .wat debugging symbol it isn't used at runtime. Wasm exceptions don't (currently) have names like JS exceptions do. They're all |
||
module.addFunction( | ||
"null", | ||
this.ensureFunctionType(null, Type.void), | ||
null, | ||
module.block(null, [ | ||
module.throw("NullPointerException", [message]) | ||
]) | ||
); | ||
} else { | ||
module.addFunction( | ||
"null", | ||
this.ensureFunctionType(null, Type.void), | ||
null, | ||
module.block(null, [ | ||
module.unreachable() | ||
]) | ||
); | ||
} | ||
} | ||
|
||
// === Exports ================================================================================== | ||
|
||
/** Applies the respective module exports for the specified file. */ | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I used the automated update feature and it did this. I'm guessing perhaps these files were generated by manual copy/paste or by hand previously maybe?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like the output is from an earlier version of Binaryen. It used to emit such whitespace and I guess the example fixtures haven't been updated since then. Most likely nothing to worry about :)