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/asmjs/asm-js.h" | 5 #include "src/asmjs/asm-js.h" |
6 | 6 |
7 #include "src/api-natives.h" | 7 #include "src/api-natives.h" |
8 #include "src/api.h" | 8 #include "src/api.h" |
9 #include "src/asmjs/asm-typer.h" | 9 #include "src/asmjs/asm-typer.h" |
10 #include "src/asmjs/asm-wasm-builder.h" | 10 #include "src/asmjs/asm-wasm-builder.h" |
(...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
249 Handle<JSReceiver> foreign) { | 249 Handle<JSReceiver> foreign) { |
250 base::ElapsedTimer instantiate_timer; | 250 base::ElapsedTimer instantiate_timer; |
251 instantiate_timer.Start(); | 251 instantiate_timer.Start(); |
252 i::Handle<i::JSObject> module( | 252 i::Handle<i::JSObject> module( |
253 i::JSObject::cast(wasm_data->get(kWasmDataCompiledModule))); | 253 i::JSObject::cast(wasm_data->get(kWasmDataCompiledModule))); |
254 i::Handle<i::FixedArray> foreign_globals( | 254 i::Handle<i::FixedArray> foreign_globals( |
255 i::FixedArray::cast(wasm_data->get(kWasmDataForeignGlobals))); | 255 i::FixedArray::cast(wasm_data->get(kWasmDataForeignGlobals))); |
256 | 256 |
257 ErrorThrower thrower(isolate, "Asm.js -> WebAssembly instantiation"); | 257 ErrorThrower thrower(isolate, "Asm.js -> WebAssembly instantiation"); |
258 | 258 |
| 259 // Create the ffi object for foreign functions {"": foreign}. |
| 260 Handle<JSObject> ffi_object; |
| 261 if (!foreign.is_null()) { |
| 262 Handle<JSFunction> object_function = Handle<JSFunction>( |
| 263 isolate->native_context()->object_function(), isolate); |
| 264 ffi_object = isolate->factory()->NewJSObject(object_function); |
| 265 JSObject::AddProperty(ffi_object, isolate->factory()->empty_string(), |
| 266 foreign, NONE); |
| 267 } |
| 268 |
259 i::MaybeHandle<i::JSObject> maybe_module_object = | 269 i::MaybeHandle<i::JSObject> maybe_module_object = |
260 i::wasm::WasmModule::Instantiate(isolate, &thrower, module, foreign, | 270 i::wasm::WasmModule::Instantiate(isolate, &thrower, module, ffi_object, |
261 memory); | 271 memory); |
262 if (maybe_module_object.is_null()) { | 272 if (maybe_module_object.is_null()) { |
263 return MaybeHandle<Object>(); | 273 return MaybeHandle<Object>(); |
264 } | 274 } |
265 | 275 |
266 i::Handle<i::Name> init_name(isolate->factory()->InternalizeUtf8String( | 276 i::Handle<i::Name> init_name(isolate->factory()->InternalizeUtf8String( |
267 wasm::AsmWasmBuilder::foreign_init_name)); | 277 wasm::AsmWasmBuilder::foreign_init_name)); |
268 | 278 |
269 i::Handle<i::Object> module_object = maybe_module_object.ToHandleChecked(); | 279 i::Handle<i::Object> module_object = maybe_module_object.ToHandleChecked(); |
270 i::MaybeHandle<i::Object> maybe_init = | 280 i::MaybeHandle<i::Object> maybe_init = |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
326 isolate, MessageTemplate::kAsmJsInstantiated, &location, stext, | 336 isolate, MessageTemplate::kAsmJsInstantiated, &location, stext, |
327 Handle<JSArray>::null()); | 337 Handle<JSArray>::null()); |
328 message->set_error_level(v8::Isolate::kMessageInfo); | 338 message->set_error_level(v8::Isolate::kMessageInfo); |
329 MessageHandler::ReportMessage(isolate, &location, message); | 339 MessageHandler::ReportMessage(isolate, &location, message); |
330 | 340 |
331 return module_object; | 341 return module_object; |
332 } | 342 } |
333 | 343 |
334 } // namespace internal | 344 } // namespace internal |
335 } // namespace v8 | 345 } // namespace v8 |
OLD | NEW |