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.h" | 5 #include "src/api.h" |
6 #include "src/api-natives.h" | 6 #include "src/api-natives.h" |
7 #include "src/assert-scope.h" | 7 #include "src/assert-scope.h" |
8 #include "src/ast/ast.h" | 8 #include "src/ast/ast.h" |
9 #include "src/ast/scopes.h" | 9 #include "src/ast/scopes.h" |
10 #include "src/factory.h" | 10 #include "src/factory.h" |
(...skipping 289 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
300 Handle<JSFunction> function = | 300 Handle<JSFunction> function = |
301 ApiNatives::InstantiateFunction(temp).ToHandleChecked(); | 301 ApiNatives::InstantiateFunction(temp).ToHandleChecked(); |
302 PropertyAttributes attributes = | 302 PropertyAttributes attributes = |
303 static_cast<PropertyAttributes>(DONT_DELETE | READ_ONLY); | 303 static_cast<PropertyAttributes>(DONT_DELETE | READ_ONLY); |
304 JSObject::AddProperty(object, name, function, attributes); | 304 JSObject::AddProperty(object, name, function, attributes); |
305 } | 305 } |
306 | 306 |
307 | 307 |
308 void WasmJs::Install(Isolate* isolate, Handle<JSGlobalObject> global) { | 308 void WasmJs::Install(Isolate* isolate, Handle<JSGlobalObject> global) { |
309 // Setup wasm function map. | 309 // Setup wasm function map. |
310 Handle<Context> context(global->native_context(), isolate); | 310 Handle<Map> wasm_function_map = isolate->factory()->NewMap( |
311 InstallWasmFunctionMap(isolate, context); | 311 JS_FUNCTION_TYPE, JSFunction::kSize + kPointerSize); |
| 312 wasm_function_map->set_is_callable(); |
| 313 global->native_context()->set_wasm_function_map(*wasm_function_map); |
312 | 314 |
313 // Bind the WASM object. | 315 // Bind the WASM object. |
314 Factory* factory = isolate->factory(); | 316 Factory* factory = isolate->factory(); |
315 Handle<String> name = v8_str(isolate, "_WASMEXP_"); | 317 Handle<String> name = v8_str(isolate, "_WASMEXP_"); |
316 Handle<JSFunction> cons = factory->NewFunction(name); | 318 Handle<JSFunction> cons = factory->NewFunction(name); |
317 JSFunction::SetInstancePrototype( | 319 JSFunction::SetInstancePrototype( |
318 cons, Handle<Object>(context->initial_object_prototype(), isolate)); | 320 cons, Handle<Object>(global->native_context()->initial_object_prototype(), |
| 321 isolate)); |
319 cons->shared()->set_instance_class_name(*name); | 322 cons->shared()->set_instance_class_name(*name); |
320 Handle<JSObject> wasm_object = factory->NewJSObject(cons, TENURED); | 323 Handle<JSObject> wasm_object = factory->NewJSObject(cons, TENURED); |
321 PropertyAttributes attributes = static_cast<PropertyAttributes>(DONT_ENUM); | 324 PropertyAttributes attributes = static_cast<PropertyAttributes>(DONT_ENUM); |
322 JSObject::AddProperty(global, name, wasm_object, attributes); | 325 JSObject::AddProperty(global, name, wasm_object, attributes); |
323 | 326 |
324 // Install functions on the WASM object. | 327 // Install functions on the WASM object. |
325 InstallFunc(isolate, wasm_object, "instantiateModule", InstantiateModule); | 328 InstallFunc(isolate, wasm_object, "instantiateModule", InstantiateModule); |
326 InstallFunc(isolate, wasm_object, "verifyModule", VerifyModule); | 329 InstallFunc(isolate, wasm_object, "verifyModule", VerifyModule); |
327 InstallFunc(isolate, wasm_object, "verifyFunction", VerifyFunction); | 330 InstallFunc(isolate, wasm_object, "verifyFunction", VerifyFunction); |
328 InstallFunc(isolate, wasm_object, "compileRun", CompileRun); | 331 InstallFunc(isolate, wasm_object, "compileRun", CompileRun); |
329 InstallFunc(isolate, wasm_object, "asmCompileRun", AsmCompileRun); | 332 InstallFunc(isolate, wasm_object, "asmCompileRun", AsmCompileRun); |
330 InstallFunc(isolate, wasm_object, "instantiateModuleFromAsm", | 333 InstallFunc(isolate, wasm_object, "instantiateModuleFromAsm", |
331 InstantiateModuleFromAsm); | 334 InstantiateModuleFromAsm); |
332 } | 335 } |
333 | |
334 | |
335 void WasmJs::InstallWasmFunctionMap(Isolate* isolate, Handle<Context> context) { | |
336 if (!context->get(Context::WASM_FUNCTION_MAP_INDEX)->IsMap()) { | |
337 Handle<Map> wasm_function_map = isolate->factory()->NewMap( | |
338 JS_FUNCTION_TYPE, JSFunction::kSize + kPointerSize); | |
339 wasm_function_map->set_is_callable(); | |
340 context->set_wasm_function_map(*wasm_function_map); | |
341 } | |
342 } | |
343 | |
344 } // namespace internal | 336 } // namespace internal |
345 } // namespace v8 | 337 } // namespace v8 |
OLD | NEW |