OLD | NEW |
1 // Copyright 2015 the V8 project authors. All rights reserved. | 1 // Copyright 2015 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "src/api-natives.h" | 5 #include "src/api-natives.h" |
6 #include "src/api.h" | 6 #include "src/api.h" |
7 #include "src/asmjs/asm-js.h" | 7 #include "src/asmjs/asm-js.h" |
8 #include "src/asmjs/asm-typer.h" | 8 #include "src/asmjs/asm-typer.h" |
9 #include "src/asmjs/asm-wasm-builder.h" | 9 #include "src/asmjs/asm-wasm-builder.h" |
10 #include "src/assert-scope.h" | 10 #include "src/assert-scope.h" |
(...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
225 i_isolate, thrower, i_module_obj, ffi, memory); | 225 i_isolate, thrower, i_module_obj, ffi, memory); |
226 if (instance.is_null()) { | 226 if (instance.is_null()) { |
227 if (!thrower->error()) | 227 if (!thrower->error()) |
228 thrower->RuntimeError("Could not instantiate module"); | 228 thrower->RuntimeError("Could not instantiate module"); |
229 return nothing; | 229 return nothing; |
230 } | 230 } |
231 DCHECK(!i_isolate->has_pending_exception()); | 231 DCHECK(!i_isolate->has_pending_exception()); |
232 return Utils::ToLocal(instance.ToHandleChecked()); | 232 return Utils::ToLocal(instance.ToHandleChecked()); |
233 } | 233 } |
234 | 234 |
| 235 void WebAssemblyModuleImports(const v8::FunctionCallbackInfo<v8::Value>& args) { |
| 236 HandleScope scope(args.GetIsolate()); |
| 237 v8::Isolate* isolate = args.GetIsolate(); |
| 238 i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate); |
| 239 |
| 240 ErrorThrower thrower(i_isolate, "WebAssembly.Instance()"); |
| 241 |
| 242 if (args.Length() < 1) { |
| 243 thrower.TypeError("Argument 0 must be a WebAssembly.Module"); |
| 244 return; |
| 245 } |
| 246 |
| 247 Local<Context> context = isolate->GetCurrentContext(); |
| 248 i::Handle<i::Context> i_context = Utils::OpenHandle(*context); |
| 249 if (!BrandCheck(isolate, Utils::OpenHandle(*args[0]), |
| 250 i::Handle<i::Symbol>(i_context->wasm_module_sym()), |
| 251 "Argument 0 must be a WebAssembly.Module")) { |
| 252 return; |
| 253 } |
| 254 |
| 255 Local<Object> module_obj = Local<Object>::Cast(args[0]); |
| 256 i::Handle<i::WasmModuleObject> i_module_obj = |
| 257 i::Handle<i::WasmModuleObject>::cast(v8::Utils::OpenHandle(*module_obj)); |
| 258 |
| 259 i::Handle<i::JSArray> imports = i::wasm::GetImports(i_isolate, i_module_obj); |
| 260 |
| 261 v8::ReturnValue<v8::Value> return_value = args.GetReturnValue(); |
| 262 return_value.Set(Utils::ToLocal(imports)); |
| 263 } |
| 264 |
235 void WebAssemblyInstanceCtor(const v8::FunctionCallbackInfo<v8::Value>& args) { | 265 void WebAssemblyInstanceCtor(const v8::FunctionCallbackInfo<v8::Value>& args) { |
236 HandleScope scope(args.GetIsolate()); | 266 HandleScope scope(args.GetIsolate()); |
237 v8::Isolate* isolate = args.GetIsolate(); | 267 v8::Isolate* isolate = args.GetIsolate(); |
238 i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate); | 268 i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate); |
239 | 269 |
240 ErrorThrower thrower(i_isolate, "WebAssembly.Instance()"); | 270 ErrorThrower thrower(i_isolate, "WebAssembly.Instance()"); |
241 | 271 |
242 if (args.Length() < 1) { | 272 if (args.Length() < 1) { |
243 thrower.TypeError("Argument 0 must be a WebAssembly.Module"); | 273 thrower.TypeError("Argument 0 must be a WebAssembly.Module"); |
244 return; | 274 return; |
(...skipping 469 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
714 InstallFunc(isolate, webassembly, "Module", WebAssemblyModule, 1); | 744 InstallFunc(isolate, webassembly, "Module", WebAssemblyModule, 1); |
715 context->set_wasm_module_constructor(*module_constructor); | 745 context->set_wasm_module_constructor(*module_constructor); |
716 Handle<JSObject> module_proto = | 746 Handle<JSObject> module_proto = |
717 factory->NewJSObject(module_constructor, TENURED); | 747 factory->NewJSObject(module_constructor, TENURED); |
718 i::Handle<i::Map> map = isolate->factory()->NewMap( | 748 i::Handle<i::Map> map = isolate->factory()->NewMap( |
719 i::JS_OBJECT_TYPE, i::JSObject::kHeaderSize + | 749 i::JS_OBJECT_TYPE, i::JSObject::kHeaderSize + |
720 WasmModuleObject::kFieldCount * i::kPointerSize); | 750 WasmModuleObject::kFieldCount * i::kPointerSize); |
721 JSFunction::SetInitialMap(module_constructor, map, module_proto); | 751 JSFunction::SetInitialMap(module_constructor, map, module_proto); |
722 JSObject::AddProperty(module_proto, isolate->factory()->constructor_string(), | 752 JSObject::AddProperty(module_proto, isolate->factory()->constructor_string(), |
723 module_constructor, DONT_ENUM); | 753 module_constructor, DONT_ENUM); |
| 754 InstallFunc(isolate, module_constructor, "imports", WebAssemblyModuleImports, |
| 755 1); |
724 | 756 |
725 // Setup Instance | 757 // Setup Instance |
726 Handle<JSFunction> instance_constructor = | 758 Handle<JSFunction> instance_constructor = |
727 InstallFunc(isolate, webassembly, "Instance", WebAssemblyInstanceCtor, 1); | 759 InstallFunc(isolate, webassembly, "Instance", WebAssemblyInstanceCtor, 1); |
728 context->set_wasm_instance_constructor(*instance_constructor); | 760 context->set_wasm_instance_constructor(*instance_constructor); |
729 | 761 |
730 // Setup Table | 762 // Setup Table |
731 Handle<JSFunction> table_constructor = | 763 Handle<JSFunction> table_constructor = |
732 InstallFunc(isolate, webassembly, "Table", WebAssemblyTable, 1); | 764 InstallFunc(isolate, webassembly, "Table", WebAssemblyTable, 1); |
733 context->set_wasm_table_constructor(*table_constructor); | 765 context->set_wasm_table_constructor(*table_constructor); |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
832 i::Handle<i::Symbol> symbol(isolate->context()->wasm_memory_sym(), isolate); | 864 i::Handle<i::Symbol> symbol(isolate->context()->wasm_memory_sym(), isolate); |
833 return HasBrand(value, symbol); | 865 return HasBrand(value, symbol); |
834 } | 866 } |
835 | 867 |
836 bool WasmJs::IsWasmTableObject(Isolate* isolate, Handle<Object> value) { | 868 bool WasmJs::IsWasmTableObject(Isolate* isolate, Handle<Object> value) { |
837 i::Handle<i::Symbol> symbol(isolate->context()->wasm_table_sym(), isolate); | 869 i::Handle<i::Symbol> symbol(isolate->context()->wasm_table_sym(), isolate); |
838 return HasBrand(value, symbol); | 870 return HasBrand(value, symbol); |
839 } | 871 } |
840 } // namespace internal | 872 } // namespace internal |
841 } // namespace v8 | 873 } // namespace v8 |
OLD | NEW |