Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(632)

Unified Diff: src/wasm/wasm-module.cc

Issue 2629523007: [wasm] JS-API: enable WebAssembly.instantiate tests; fix LinkError (Closed)
Patch Set: moved import validation Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/wasm/wasm-module.h ('k') | test/cctest/wasm/test-run-wasm-module.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/wasm/wasm-module.cc
diff --git a/src/wasm/wasm-module.cc b/src/wasm/wasm-module.cc
index 6f44991cf979be0404a21542e43ce0bc3e633c7e..baefafeca7c97c9af37a1adb847cf6edad95f97d 100644
--- a/src/wasm/wasm-module.cc
+++ b/src/wasm/wasm-module.cc
@@ -1121,8 +1121,8 @@ void wasm::UpdateDispatchTables(Isolate* isolate,
class WasmInstanceBuilder {
public:
WasmInstanceBuilder(Isolate* isolate, ErrorThrower* thrower,
- Handle<JSObject> module_object, Handle<JSReceiver> ffi,
- Handle<JSArrayBuffer> memory)
+ Handle<WasmModuleObject> module_object,
+ Handle<JSReceiver> ffi, Handle<JSArrayBuffer> memory)
: isolate_(isolate),
thrower_(thrower),
module_object_(module_object),
@@ -1132,6 +1132,16 @@ class WasmInstanceBuilder {
// Build an instance, in all of its glory.
MaybeHandle<WasmInstanceObject> Build() {
MaybeHandle<WasmInstanceObject> nothing;
+
+ // Check that an imports argument was provided, if the module requires it.
+ // No point in continuing otherwise.
+ if (!module_object_->compiled_module()->module()->import_table.empty() &&
titzer 2017/01/13 17:20:43 Can you do this check after we extract the module_
Mircea Trofin 2017/01/13 20:17:18 we can actually initialize module_ at construction
+ ffi_.is_null()) {
+ thrower_->TypeError(
+ "Imports argument must be present and must be an object");
+ return nothing;
+ }
+
HistogramTimerScope wasm_instantiate_module_time_scope(
isolate_->counters()->wasm_instantiate_module_time());
Factory* factory = isolate_->factory();
@@ -1154,8 +1164,7 @@ class WasmInstanceBuilder {
Handle<WasmCompiledModule> original;
{
DisallowHeapAllocation no_gc;
- original = handle(
- WasmCompiledModule::cast(module_object_->GetInternalField(0)));
+ original = handle(module_object_->compiled_module());
if (original->has_weak_owning_instance()) {
owner = handle(WasmInstanceObject::cast(
original->weak_owning_instance()->value()));
@@ -1442,7 +1451,7 @@ class WasmInstanceBuilder {
DCHECK(!isolate_->has_pending_exception());
TRACE("Finishing instance %d\n", compiled_module_->instance_id());
- TRACE_CHAIN(WasmCompiledModule::cast(module_object_->GetInternalField(0)));
+ TRACE_CHAIN(module_object_->compiled_module());
return instance;
}
@@ -1458,7 +1467,7 @@ class WasmInstanceBuilder {
Isolate* isolate_;
WasmModule* module_;
ErrorThrower* thrower_;
- Handle<JSObject> module_object_;
+ Handle<WasmModuleObject> module_object_;
Handle<JSReceiver> ffi_;
Handle<JSArrayBuffer> memory_;
Handle<JSArrayBuffer> globals_;
@@ -1475,9 +1484,9 @@ class WasmInstanceBuilder {
import_name->length(), import_name->ToCString().get(), error);
}
- MaybeHandle<Object> ReportTypeError(const char* error, uint32_t index,
+ MaybeHandle<Object> ReportLinkError(const char* error, uint32_t index,
Handle<String> module_name) {
- thrower_->TypeError("Import #%d module=\"%.*s\" error: %s", index,
+ thrower_->LinkError("Import #%d module=\"%.*s\" error: %s", index,
module_name->length(), module_name->ToCString().get(),
error);
return MaybeHandle<Object>();
@@ -1486,22 +1495,22 @@ class WasmInstanceBuilder {
// Look up an import value in the {ffi_} object.
MaybeHandle<Object> LookupImport(uint32_t index, Handle<String> module_name,
Handle<String> import_name) {
- if (ffi_.is_null()) {
- return ReportTypeError("FFI is not an object", index, module_name);
- }
+ // We pre-validated in the js-api layer that the ffi object is present, and
+ // a JSObject, if the module has imports.
+ DCHECK(!ffi_.is_null());
// Look up the module first.
MaybeHandle<Object> result =
Object::GetPropertyOrElement(ffi_, module_name);
if (result.is_null()) {
- return ReportTypeError("module not found", index, module_name);
+ return ReportLinkError("module not found", index, module_name);
}
Handle<Object> module = result.ToHandleChecked();
// Look up the value in the module.
if (!module->IsJSReceiver()) {
- return ReportTypeError("module is not an object or function", index,
+ return ReportLinkError("module is not an object or function", index,
module_name);
}
@@ -2082,8 +2091,9 @@ class WasmInstanceBuilder {
// Instantiates a WASM module, creating a WebAssembly.Instance from a
// WebAssembly.Module.
MaybeHandle<WasmInstanceObject> WasmModule::Instantiate(
- Isolate* isolate, ErrorThrower* thrower, Handle<JSObject> wasm_module,
- Handle<JSReceiver> ffi, Handle<JSArrayBuffer> memory) {
+ Isolate* isolate, ErrorThrower* thrower,
+ Handle<WasmModuleObject> wasm_module, Handle<JSReceiver> ffi,
+ Handle<JSArrayBuffer> memory) {
WasmInstanceBuilder builder(isolate, thrower, wasm_module, ffi, memory);
return builder.Build();
}
« no previous file with comments | « src/wasm/wasm-module.h ('k') | test/cctest/wasm/test-run-wasm-module.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698