Commit 022635bf authored by rossberg's avatar rossberg Committed by Commit bot

Implement Instance instances correctly; fix a few error cases

R=titzer@chromium.org
BUG=

Review-Url: https://codereview.chromium.org/2620263003
Cr-Commit-Position: refs/heads/master@{#42288}
parent 1d32a398
......@@ -4166,8 +4166,6 @@ bool Genesis::InstallSpecialObjects(Handle<Context> native_context) {
Factory* factory = isolate->factory();
HandleScope scope(isolate);
Handle<JSGlobalObject> global(JSGlobalObject::cast(
native_context->global_object()));
Handle<JSObject> Error = isolate->error_function();
Handle<String> name =
......@@ -4175,7 +4173,9 @@ bool Genesis::InstallSpecialObjects(Handle<Context> native_context) {
Handle<Smi> stack_trace_limit(Smi::FromInt(FLAG_stack_trace_limit), isolate);
JSObject::AddProperty(Error, name, stack_trace_limit, NONE);
WasmJs::Install(isolate, global);
if (FLAG_expose_wasm || FLAG_validate_asm) {
WasmJs::Install(isolate);
}
return true;
}
......
This diff is collapsed.
......@@ -13,16 +13,7 @@ namespace internal {
// Exposes a WASM API to JavaScript through the V8 API.
class WasmJs {
public:
static void Install(Isolate* isolate, Handle<JSGlobalObject> global_object);
V8_EXPORT_PRIVATE static void InstallWasmModuleSymbolIfNeeded(
Isolate* isolate, Handle<JSGlobalObject> global, Handle<Context> context);
V8_EXPORT_PRIVATE static void InstallWasmMapsIfNeeded(
Isolate* isolate, Handle<Context> context);
static void InstallWasmConstructors(Isolate* isolate,
Handle<JSGlobalObject> global,
Handle<Context> context);
V8_EXPORT_PRIVATE static void Install(Isolate* isolate);
// WebAssembly.Table.
static bool IsWasmTableObject(Isolate* isolate, Handle<Object> value);
......
......@@ -398,6 +398,8 @@ V8_EXPORT_PRIVATE MaybeHandle<WasmModuleObject> CreateModuleObjectFromBytes(
V8_EXPORT_PRIVATE Handle<JSArray> GetImports(Isolate* isolate,
Handle<WasmModuleObject> module);
V8_EXPORT_PRIVATE Handle<JSArray> GetExports(Isolate* isolate,
Handle<WasmModuleObject> module);
V8_EXPORT_PRIVATE Handle<JSArray> GetExports(Isolate* isolate,
Handle<WasmModuleObject> module);
......
......@@ -292,12 +292,15 @@ bool WasmInstanceObject::IsWasmInstanceObject(Object* object) {
Handle<WasmInstanceObject> WasmInstanceObject::New(
Isolate* isolate, Handle<WasmCompiledModule> compiled_module) {
Handle<Map> map = isolate->factory()->NewMap(
JS_OBJECT_TYPE, JSObject::kHeaderSize + kFieldCount * kPointerSize);
Handle<JSFunction> instance_cons(
isolate->native_context()->wasm_instance_constructor());
Handle<JSObject> instance_object =
isolate->factory()->NewJSObject(instance_cons, TENURED);
Handle<Symbol> instance_sym(isolate->native_context()->wasm_instance_sym());
Object::SetProperty(instance_object, instance_sym, instance_object, STRICT)
.Check();
Handle<WasmInstanceObject> instance(
reinterpret_cast<WasmInstanceObject*>(
*isolate->factory()->NewJSObjectFromMap(map, TENURED)),
isolate);
reinterpret_cast<WasmInstanceObject*>(*instance_object), isolate);
instance->SetInternalField(kCompiledModule, *compiled_module);
instance->SetInternalField(kMemoryObject, isolate->heap()->undefined_value());
......
......@@ -85,6 +85,7 @@ class TestingModule : public ModuleEnv {
Vector<const byte>::empty()),
zone->allocator())
: nullptr) {
WasmJs::Install(isolate_);
instance->module = &module_;
instance->globals_start = global_data;
module_.globals_size = kMaxGlobalsSize;
......@@ -223,7 +224,6 @@ class TestingModule : public ModuleEnv {
// Wrap the code so it can be called as a JS function.
Handle<WasmInstanceObject> instance_obj(0, isolate_);
Handle<Code> code = instance->function_code[index];
WasmJs::InstallWasmMapsIfNeeded(isolate_, isolate_->native_context());
Handle<Code> ret_code =
compiler::CompileJSToWasmWrapper(isolate_, &module_, code, index);
Handle<JSFunction> ret = WasmExportedFunction::New(
......
......@@ -205,9 +205,7 @@ int32_t CallWasmFunctionForTesting(Isolate* isolate, Handle<JSObject> instance,
}
void SetupIsolateForWasmModule(Isolate* isolate) {
WasmJs::InstallWasmMapsIfNeeded(isolate, isolate->native_context());
WasmJs::InstallWasmModuleSymbolIfNeeded(isolate, isolate->global_object(),
isolate->native_context());
WasmJs::Install(isolate);
}
} // namespace testing
} // namespace wasm
......
......@@ -134,8 +134,8 @@ assertErrorMessage(() => new Module(), TypeError, /requires more than 0 argument
assertErrorMessage(() => new Module(undefined), TypeError, "first argument must be an ArrayBuffer or typed array object");
assertErrorMessage(() => new Module(1), TypeError, "first argument must be an ArrayBuffer or typed array object");
assertErrorMessage(() => new Module({}), TypeError, "first argument must be an ArrayBuffer or typed array object");
//TODO assertErrorMessage(() => new Module(new Uint8Array()), CompileError, /failed to match magic number/);
//TODO assertErrorMessage(() => new Module(new ArrayBuffer()), CompileError, /failed to match magic number/);
assertErrorMessage(() => new Module(new Uint8Array()), CompileError, /failed to match magic number/);
assertErrorMessage(() => new Module(new ArrayBuffer()), CompileError, /failed to match magic number/);
assertEq(new Module(emptyModuleBinary) instanceof Module, true);
assertEq(new Module(emptyModuleBinary.buffer) instanceof Module, true);
......@@ -259,9 +259,9 @@ assertEq(Instance.name, "Instance");
assertErrorMessage(() => Instance(), TypeError, /constructor without new is forbidden/);
assertErrorMessage(() => new Instance(1), TypeError, "first argument must be a WebAssembly.Module");
assertErrorMessage(() => new Instance({}), TypeError, "first argument must be a WebAssembly.Module");
//TODO assertErrorMessage(() => new Instance(emptyModule, null), TypeError, "second argument must be an object");
//TODO assertEq(new Instance(emptyModule) instanceof Instance, true);
//TODO assertEq(new Instance(emptyModule, {}) instanceof Instance, true);
assertErrorMessage(() => new Instance(emptyModule, null), TypeError, "second argument must be an object");
assertEq(new Instance(emptyModule) instanceof Instance, true);
assertEq(new Instance(emptyModule, {}) instanceof Instance, true);
// 'WebAssembly.Instance.prototype' data property
let instanceProtoDesc = Object.getOwnPropertyDescriptor(Instance, 'prototype');
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment