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 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
205 i::FixedArray::cast(wasm_data->get(1))); | 205 i::FixedArray::cast(wasm_data->get(1))); |
206 | 206 |
207 ErrorThrower thrower(isolate, "Asm.js -> WebAssembly instantiation"); | 207 ErrorThrower thrower(isolate, "Asm.js -> WebAssembly instantiation"); |
208 | 208 |
209 i::MaybeHandle<i::JSObject> maybe_module_object = | 209 i::MaybeHandle<i::JSObject> maybe_module_object = |
210 i::wasm::WasmModule::Instantiate(isolate, module, foreign, memory); | 210 i::wasm::WasmModule::Instantiate(isolate, module, foreign, memory); |
211 if (maybe_module_object.is_null()) { | 211 if (maybe_module_object.is_null()) { |
212 return MaybeHandle<Object>(); | 212 return MaybeHandle<Object>(); |
213 } | 213 } |
214 | 214 |
215 i::Handle<i::Name> name(isolate->factory()->InternalizeOneByteString( | 215 i::Handle<i::Name> init_name(isolate->factory()->InternalizeUtf8String( |
216 STATIC_CHAR_VECTOR("__foreign_init__"))); | 216 wasm::AsmWasmBuilder::foreign_init_name)); |
217 | 217 |
218 i::Handle<i::Object> module_object = maybe_module_object.ToHandleChecked(); | 218 i::Handle<i::Object> module_object = maybe_module_object.ToHandleChecked(); |
219 i::MaybeHandle<i::Object> maybe_init = | 219 i::MaybeHandle<i::Object> maybe_init = |
220 i::Object::GetProperty(module_object, name); | 220 i::Object::GetProperty(module_object, init_name); |
221 DCHECK(!maybe_init.is_null()); | 221 DCHECK(!maybe_init.is_null()); |
222 | 222 |
223 i::Handle<i::Object> init = maybe_init.ToHandleChecked(); | 223 i::Handle<i::Object> init = maybe_init.ToHandleChecked(); |
224 i::Handle<i::Object> undefined(isolate->heap()->undefined_value(), isolate); | 224 i::Handle<i::Object> undefined(isolate->heap()->undefined_value(), isolate); |
225 i::Handle<i::Object>* foreign_args_array = | 225 i::Handle<i::Object>* foreign_args_array = |
226 new i::Handle<i::Object>[foreign_globals->length()]; | 226 new i::Handle<i::Object>[foreign_globals->length()]; |
227 for (int j = 0; j < foreign_globals->length(); j++) { | 227 for (int j = 0; j < foreign_globals->length(); j++) { |
228 if (!foreign.is_null()) { | 228 if (!foreign.is_null()) { |
229 i::MaybeHandle<i::Name> name = i::Object::ToName( | 229 i::MaybeHandle<i::Name> name = i::Object::ToName( |
230 isolate, i::Handle<i::Object>(foreign_globals->get(j), isolate)); | 230 isolate, i::Handle<i::Object>(foreign_globals->get(j), isolate)); |
231 if (!name.is_null()) { | 231 if (!name.is_null()) { |
232 i::MaybeHandle<i::Object> val = | 232 i::MaybeHandle<i::Object> val = |
233 i::Object::GetProperty(foreign, name.ToHandleChecked()); | 233 i::Object::GetProperty(foreign, name.ToHandleChecked()); |
234 if (!val.is_null()) { | 234 if (!val.is_null()) { |
235 foreign_args_array[j] = val.ToHandleChecked(); | 235 foreign_args_array[j] = val.ToHandleChecked(); |
236 continue; | 236 continue; |
237 } | 237 } |
238 } | 238 } |
239 } | 239 } |
240 foreign_args_array[j] = undefined; | 240 foreign_args_array[j] = undefined; |
241 } | 241 } |
242 i::MaybeHandle<i::Object> retval = i::Execution::Call( | 242 i::MaybeHandle<i::Object> retval = i::Execution::Call( |
243 isolate, init, undefined, foreign_globals->length(), foreign_args_array); | 243 isolate, init, undefined, foreign_globals->length(), foreign_args_array); |
244 delete[] foreign_args_array; | 244 delete[] foreign_args_array; |
245 | |
246 DCHECK(!retval.is_null()); | 245 DCHECK(!retval.is_null()); |
247 | 246 |
248 return maybe_module_object; | 247 i::Handle<i::Name> single_function_name( |
| 248 isolate->factory()->InternalizeUtf8String( |
| 249 wasm::AsmWasmBuilder::single_function_name)); |
| 250 i::MaybeHandle<i::Object> single_function = |
| 251 i::Object::GetProperty(module_object, single_function_name); |
| 252 if (!single_function.is_null() && |
| 253 !single_function.ToHandleChecked()->IsUndefined(isolate)) { |
| 254 return single_function; |
| 255 } |
| 256 return module_object; |
249 } | 257 } |
250 | 258 |
251 } // namespace internal | 259 } // namespace internal |
252 } // namespace v8 | 260 } // namespace v8 |
OLD | NEW |