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 245 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
256 Handle<JSReceiver> foreign) { | 256 Handle<JSReceiver> foreign) { |
257 base::ElapsedTimer instantiate_timer; | 257 base::ElapsedTimer instantiate_timer; |
258 instantiate_timer.Start(); | 258 instantiate_timer.Start(); |
259 i::Handle<i::WasmModuleObject> module( | 259 i::Handle<i::WasmModuleObject> module( |
260 i::WasmModuleObject::cast(wasm_data->get(kWasmDataCompiledModule))); | 260 i::WasmModuleObject::cast(wasm_data->get(kWasmDataCompiledModule))); |
261 i::Handle<i::FixedArray> foreign_globals( | 261 i::Handle<i::FixedArray> foreign_globals( |
262 i::FixedArray::cast(wasm_data->get(kWasmDataForeignGlobals))); | 262 i::FixedArray::cast(wasm_data->get(kWasmDataForeignGlobals))); |
263 | 263 |
264 ErrorThrower thrower(isolate, "Asm.js -> WebAssembly instantiation"); | 264 ErrorThrower thrower(isolate, "Asm.js -> WebAssembly instantiation"); |
265 | 265 |
| 266 Handle<JSFunction> object_function = |
| 267 Handle<JSFunction>(isolate->native_context()->object_function(), isolate); |
| 268 |
266 // Create the ffi object for foreign functions {"": foreign}. | 269 // Create the ffi object for foreign functions {"": foreign}. |
267 Handle<JSObject> ffi_object; | 270 Handle<JSObject> ffi_object; |
268 if (!foreign.is_null()) { | 271 if (!foreign.is_null()) { |
269 Handle<JSFunction> object_function = Handle<JSFunction>( | |
270 isolate->native_context()->object_function(), isolate); | |
271 ffi_object = isolate->factory()->NewJSObject(object_function); | 272 ffi_object = isolate->factory()->NewJSObject(object_function); |
272 JSObject::AddProperty(ffi_object, isolate->factory()->empty_string(), | 273 JSObject::AddProperty(ffi_object, isolate->factory()->empty_string(), |
273 foreign, NONE); | 274 foreign, NONE); |
274 } | 275 } |
275 | 276 |
276 i::MaybeHandle<i::JSObject> maybe_module_object = | 277 Handle<JSObject> exports = isolate->factory()->NewJSObject(object_function); |
| 278 i::MaybeHandle<i::WasmInstanceObject> maybe_module_object = |
277 i::wasm::WasmModule::Instantiate(isolate, &thrower, module, ffi_object, | 279 i::wasm::WasmModule::Instantiate(isolate, &thrower, module, ffi_object, |
278 memory); | 280 memory, exports); |
279 if (maybe_module_object.is_null()) { | 281 if (maybe_module_object.is_null()) { |
280 return MaybeHandle<Object>(); | 282 return MaybeHandle<Object>(); |
281 } | 283 } |
282 | 284 |
283 i::Handle<i::Name> init_name(isolate->factory()->InternalizeUtf8String( | 285 i::Handle<i::Name> init_name(isolate->factory()->InternalizeUtf8String( |
284 wasm::AsmWasmBuilder::foreign_init_name)); | 286 wasm::AsmWasmBuilder::foreign_init_name)); |
285 | 287 |
286 i::Handle<i::Object> module_object = maybe_module_object.ToHandleChecked(); | |
287 i::MaybeHandle<i::Object> maybe_init = | 288 i::MaybeHandle<i::Object> maybe_init = |
288 i::Object::GetProperty(module_object, init_name); | 289 i::Object::GetProperty(exports, init_name); |
289 DCHECK(!maybe_init.is_null()); | 290 DCHECK(!maybe_init.is_null()); |
290 | 291 |
291 i::Handle<i::Object> init = maybe_init.ToHandleChecked(); | 292 i::Handle<i::Object> init = maybe_init.ToHandleChecked(); |
292 i::Handle<i::Object> undefined(isolate->heap()->undefined_value(), isolate); | 293 i::Handle<i::Object> undefined(isolate->heap()->undefined_value(), isolate); |
293 i::Handle<i::Object>* foreign_args_array = | 294 i::Handle<i::Object>* foreign_args_array = |
294 new i::Handle<i::Object>[foreign_globals->length()]; | 295 new i::Handle<i::Object>[foreign_globals->length()]; |
295 for (int j = 0; j < foreign_globals->length(); j++) { | 296 for (int j = 0; j < foreign_globals->length(); j++) { |
296 if (!foreign.is_null()) { | 297 if (!foreign.is_null()) { |
297 i::MaybeHandle<i::Name> name = i::Object::ToName( | 298 i::MaybeHandle<i::Name> name = i::Object::ToName( |
298 isolate, i::Handle<i::Object>(foreign_globals->get(j), isolate)); | 299 isolate, i::Handle<i::Object>(foreign_globals->get(j), isolate)); |
(...skipping 10 matching lines...) Expand all Loading... |
309 } | 310 } |
310 i::MaybeHandle<i::Object> retval = i::Execution::Call( | 311 i::MaybeHandle<i::Object> retval = i::Execution::Call( |
311 isolate, init, undefined, foreign_globals->length(), foreign_args_array); | 312 isolate, init, undefined, foreign_globals->length(), foreign_args_array); |
312 delete[] foreign_args_array; | 313 delete[] foreign_args_array; |
313 DCHECK(!retval.is_null()); | 314 DCHECK(!retval.is_null()); |
314 | 315 |
315 i::Handle<i::Name> single_function_name( | 316 i::Handle<i::Name> single_function_name( |
316 isolate->factory()->InternalizeUtf8String( | 317 isolate->factory()->InternalizeUtf8String( |
317 wasm::AsmWasmBuilder::single_function_name)); | 318 wasm::AsmWasmBuilder::single_function_name)); |
318 i::MaybeHandle<i::Object> single_function = | 319 i::MaybeHandle<i::Object> single_function = |
319 i::Object::GetProperty(module_object, single_function_name); | 320 i::Object::GetProperty(exports, single_function_name); |
320 if (!single_function.is_null() && | 321 if (!single_function.is_null() && |
321 !single_function.ToHandleChecked()->IsUndefined(isolate)) { | 322 !single_function.ToHandleChecked()->IsUndefined(isolate)) { |
322 return single_function; | 323 return single_function; |
323 } | 324 } |
324 | 325 |
325 i::Handle<i::Script> script(i::Script::cast(wasm_data->get(kWasmDataScript))); | 326 i::Handle<i::Script> script(i::Script::cast(wasm_data->get(kWasmDataScript))); |
326 int32_t position = 0; | 327 int32_t position = 0; |
327 if (!wasm_data->get(kWasmDataScriptPosition)->ToInt32(&position)) { | 328 if (!wasm_data->get(kWasmDataScriptPosition)->ToInt32(&position)) { |
328 UNREACHABLE(); | 329 UNREACHABLE(); |
329 } | 330 } |
(...skipping 10 matching lines...) Expand all Loading... |
340 USE(length); | 341 USE(length); |
341 Handle<String> stext(isolate->factory()->InternalizeUtf8String(text)); | 342 Handle<String> stext(isolate->factory()->InternalizeUtf8String(text)); |
342 Handle<JSMessageObject> message = MessageHandler::MakeMessageObject( | 343 Handle<JSMessageObject> message = MessageHandler::MakeMessageObject( |
343 isolate, MessageTemplate::kAsmJsInstantiated, &location, stext, | 344 isolate, MessageTemplate::kAsmJsInstantiated, &location, stext, |
344 Handle<JSArray>::null()); | 345 Handle<JSArray>::null()); |
345 message->set_error_level(v8::Isolate::kMessageInfo); | 346 message->set_error_level(v8::Isolate::kMessageInfo); |
346 if (!FLAG_suppress_asm_messages && FLAG_trace_asm_time) { | 347 if (!FLAG_suppress_asm_messages && FLAG_trace_asm_time) { |
347 MessageHandler::ReportMessage(isolate, &location, message); | 348 MessageHandler::ReportMessage(isolate, &location, message); |
348 } | 349 } |
349 | 350 |
350 return module_object; | 351 return exports; |
351 } | 352 } |
352 | 353 |
353 } // namespace internal | 354 } // namespace internal |
354 } // namespace v8 | 355 } // namespace v8 |
OLD | NEW |