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/base/atomic-utils.h" | 5 #include "src/base/atomic-utils.h" |
6 #include "src/macro-assembler.h" | 6 #include "src/macro-assembler.h" |
7 #include "src/objects.h" | 7 #include "src/objects.h" |
8 #include "src/property-descriptor.h" | 8 #include "src/property-descriptor.h" |
9 #include "src/v8.h" | 9 #include "src/v8.h" |
10 | 10 |
(...skipping 568 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
579 ModuleEnv& module_env, uint32_t& total_code_size, | 579 ModuleEnv& module_env, uint32_t& total_code_size, |
580 PropertyDescriptor& desc) { | 580 PropertyDescriptor& desc) { |
581 for (uint32_t i = FLAG_skip_compiling_wasm_funcs; | 581 for (uint32_t i = FLAG_skip_compiling_wasm_funcs; |
582 i < module->functions.size(); i++) { | 582 i < module->functions.size(); i++) { |
583 const WasmFunction& func = module->functions[i]; | 583 const WasmFunction& func = module->functions[i]; |
584 if (thrower.error()) break; | 584 if (thrower.error()) break; |
585 | 585 |
586 DCHECK_EQ(i, func.func_index); | 586 DCHECK_EQ(i, func.func_index); |
587 WasmName str = module->GetName(func.name_offset, func.name_length); | 587 WasmName str = module->GetName(func.name_offset, func.name_length); |
588 WasmName str_null = {nullptr, 0}; | 588 WasmName str_null = {nullptr, 0}; |
589 Handle<String> name = factory->InternalizeUtf8String(str); | |
590 Handle<Code> code = Handle<Code>::null(); | 589 Handle<Code> code = Handle<Code>::null(); |
591 Handle<JSFunction> function = Handle<JSFunction>::null(); | 590 Handle<JSFunction> function = Handle<JSFunction>::null(); |
| 591 Handle<String> function_name = Handle<String>::null(); |
592 if (func.external) { | 592 if (func.external) { |
593 // Lookup external function in FFI object. | 593 // Lookup external function in FFI object. |
594 MaybeHandle<JSFunction> function = | 594 MaybeHandle<JSFunction> function = |
595 LookupFunction(thrower, factory, ffi, i, str, str_null); | 595 LookupFunction(thrower, factory, ffi, i, str, str_null); |
596 if (function.is_null()) { | 596 if (function.is_null()) { |
597 return false; | 597 return false; |
598 } | 598 } |
599 code = compiler::CompileWasmToJSWrapper(isolate, &module_env, | 599 code = compiler::CompileWasmToJSWrapper(isolate, &module_env, |
600 function.ToHandleChecked(), | 600 function.ToHandleChecked(), |
601 func.sig, str, str_null); | 601 func.sig, str, str_null); |
602 } else { | 602 } else { |
603 if (FLAG_wasm_num_compilation_tasks != 0) { | 603 if (FLAG_wasm_num_compilation_tasks != 0) { |
604 code = results[i]; | 604 code = results[i]; |
605 } else { | 605 } else { |
606 // Compile the function. | 606 // Compile the function. |
607 code = compiler::CompileWasmFunction(&thrower, isolate, &module_env, | 607 code = compiler::CompileWasmFunction(&thrower, isolate, &module_env, |
608 &func); | 608 &func); |
609 } | 609 } |
610 if (code.is_null()) { | 610 if (code.is_null()) { |
611 thrower.Error("Compilation of #%d:%.*s failed.", i, str.length(), | 611 thrower.Error("Compilation of #%d:%.*s failed.", i, str.length(), |
612 str.start()); | 612 str.start()); |
613 return false; | 613 return false; |
614 } | 614 } |
615 if (func.exported) { | 615 if (func.exported) { |
| 616 function_name = factory->InternalizeUtf8String(str); |
616 function = compiler::CompileJSToWasmWrapper( | 617 function = compiler::CompileJSToWasmWrapper( |
617 isolate, &module_env, name, code, instance.js_object, i); | 618 isolate, &module_env, function_name, code, instance.js_object, i); |
618 record_code_size(total_code_size, function->code()); | 619 record_code_size(total_code_size, function->code()); |
619 } | 620 } |
620 } | 621 } |
621 if (!code.is_null()) { | 622 if (!code.is_null()) { |
622 // Install the code into the linker table. | 623 // Install the code into the linker table. |
623 module_env.linker->Finish(i, code); | 624 module_env.linker->Finish(i, code); |
624 code_table->set(i, *code); | 625 code_table->set(i, *code); |
625 record_code_size(total_code_size, *code); | 626 record_code_size(total_code_size, *code); |
626 } | 627 } |
627 if (func.exported) { | 628 if (func.exported) { |
628 // Exported functions are installed as read-only properties on the | 629 // Exported functions are installed as read-only properties on the |
629 // module. | 630 // module. |
630 desc.set_value(function); | 631 desc.set_value(function); |
631 Maybe<bool> status = JSReceiver::DefineOwnProperty( | 632 Maybe<bool> status = JSReceiver::DefineOwnProperty( |
632 isolate, instance.js_object, name, &desc, Object::THROW_ON_ERROR); | 633 isolate, instance.js_object, function_name, &desc, |
| 634 Object::THROW_ON_ERROR); |
633 if (!status.IsJust()) | 635 if (!status.IsJust()) |
634 thrower.Error("export of %.*s failed.", str.length(), str.start()); | 636 thrower.Error("export of %.*s failed.", str.length(), str.start()); |
635 } | 637 } |
636 } | 638 } |
637 return true; | 639 return true; |
638 } | 640 } |
639 } // namespace | 641 } // namespace |
640 | 642 |
641 // Instantiates a wasm module as a JSObject. | 643 // Instantiates a wasm module as a JSObject. |
642 // * allocates a backing store of {mem_size} bytes. | 644 // * allocates a backing store of {mem_size} bytes. |
(...skipping 364 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1007 wasm->GetInternalField(kWasmFunctionNamesArray), wasm->GetIsolate()); | 1009 wasm->GetInternalField(kWasmFunctionNamesArray), wasm->GetIsolate()); |
1008 if (func_names_arr_obj->IsUndefined()) | 1010 if (func_names_arr_obj->IsUndefined()) |
1009 return func_names_arr_obj; // Return undefined. | 1011 return func_names_arr_obj; // Return undefined. |
1010 return GetWasmFunctionNameFromTable( | 1012 return GetWasmFunctionNameFromTable( |
1011 Handle<ByteArray>::cast(func_names_arr_obj), func_index); | 1013 Handle<ByteArray>::cast(func_names_arr_obj), func_index); |
1012 } | 1014 } |
1013 | 1015 |
1014 } // namespace wasm | 1016 } // namespace wasm |
1015 } // namespace internal | 1017 } // namespace internal |
1016 } // namespace v8 | 1018 } // namespace v8 |
OLD | NEW |