Chromium Code Reviews| 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-wasm-builder.h" | 9 #include "src/asmjs/asm-wasm-builder.h" |
| 10 #include "src/asmjs/typing-asm.h" | 10 #include "src/asmjs/typing-asm.h" |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 67 } | 67 } |
| 68 if (!typer.Validate()) { | 68 if (!typer.Validate()) { |
| 69 DCHECK(!info->isolate()->has_pending_exception()); | 69 DCHECK(!info->isolate()->has_pending_exception()); |
| 70 PrintF("Validation of asm.js module failed: %s", typer.error_message()); | 70 PrintF("Validation of asm.js module failed: %s", typer.error_message()); |
| 71 return MaybeHandle<FixedArray>(); | 71 return MaybeHandle<FixedArray>(); |
| 72 } | 72 } |
| 73 v8::internal::wasm::AsmWasmBuilder builder(info->isolate(), info->zone(), | 73 v8::internal::wasm::AsmWasmBuilder builder(info->isolate(), info->zone(), |
| 74 info->literal(), &typer); | 74 info->literal(), &typer); |
| 75 i::Handle<i::FixedArray> foreign_globals; | 75 i::Handle<i::FixedArray> foreign_globals; |
| 76 auto module = builder.Run(&foreign_globals); | 76 auto module = builder.Run(&foreign_globals); |
| 77 size_t byte_length = module->end() - module->begin(); | 77 |
| 78 Handle<JSArrayBuffer> buffer = info->isolate()->factory()->NewJSArrayBuffer(); | 78 i::MaybeHandle<i::FixedArray> compiled = |
| 79 JSArrayBuffer::SetupAllocatingData(buffer, info->isolate(), byte_length, | 79 CompileModule(info->isolate(), module->begin(), module->end(), &thrower, |
|
Mircea Trofin
2016/07/12 22:07:34
To echo our chat - this change moves compiling at
| |
| 80 false, SharedFlag::kNotShared); | 80 internal::wasm::kAsmJsOrigin); |
| 81 uint8_t* module_bytes = reinterpret_cast<uint8_t*>(buffer->backing_store()); | 81 DCHECK(!compiled.is_null()); |
| 82 memcpy(module_bytes, module->begin(), byte_length); | 82 |
| 83 Handle<FixedArray> result = info->isolate()->factory()->NewFixedArray(2); | 83 Handle<FixedArray> result = info->isolate()->factory()->NewFixedArray(2); |
| 84 result->set(0, *buffer); | 84 result->set(0, *compiled.ToHandleChecked()); |
| 85 result->set(1, *foreign_globals); | 85 result->set(1, *foreign_globals); |
| 86 return result; | 86 return result; |
| 87 } | 87 } |
| 88 | 88 |
| 89 MaybeHandle<Object> AsmJs::InstantiateAsmWasm(i::Isolate* isolate, | 89 MaybeHandle<Object> AsmJs::InstantiateAsmWasm(i::Isolate* isolate, |
| 90 Handle<FixedArray> wasm_data, | 90 Handle<FixedArray> wasm_data, |
| 91 Handle<JSArrayBuffer> memory, | 91 Handle<JSArrayBuffer> memory, |
| 92 Handle<JSObject> foreign) { | 92 Handle<JSObject> foreign) { |
| 93 i::Handle<i::JSArrayBuffer> module_bytes( | 93 i::Handle<i::FixedArray> compiled(i::FixedArray::cast(wasm_data->get(0))); |
| 94 i::JSArrayBuffer::cast(wasm_data->get(0))); | |
| 95 i::Handle<i::FixedArray> foreign_globals( | 94 i::Handle<i::FixedArray> foreign_globals( |
| 96 i::FixedArray::cast(wasm_data->get(1))); | 95 i::FixedArray::cast(wasm_data->get(1))); |
| 97 | 96 |
| 98 ErrorThrower thrower(isolate, "Asm.js -> WebAssembly instantiation"); | 97 ErrorThrower thrower(isolate, "Asm.js -> WebAssembly instantiation"); |
| 99 | 98 |
| 100 const byte* module_start = | |
| 101 reinterpret_cast<const byte*>(module_bytes->backing_store()); | |
| 102 size_t module_length = | |
| 103 static_cast<size_t>(module_bytes->byte_length()->Number()); | |
| 104 const byte* module_end = module_start + module_length; | |
| 105 i::MaybeHandle<i::FixedArray> compiled = | |
| 106 CompileModule(isolate, module_start, module_end, &thrower, | |
| 107 internal::wasm::kAsmJsOrigin); | |
| 108 if (compiled.is_null()) { | |
| 109 return MaybeHandle<Object>(); | |
| 110 } | |
| 111 i::MaybeHandle<i::JSObject> maybe_module_object = | 99 i::MaybeHandle<i::JSObject> maybe_module_object = |
| 112 i::wasm::WasmModule::Instantiate(isolate, compiled.ToHandleChecked(), | 100 i::wasm::WasmModule::Instantiate(isolate, compiled, foreign, memory); |
| 113 foreign, memory); | |
| 114 if (maybe_module_object.is_null()) { | 101 if (maybe_module_object.is_null()) { |
| 115 return MaybeHandle<Object>(); | 102 return MaybeHandle<Object>(); |
| 116 } | 103 } |
| 117 | 104 |
| 118 i::Handle<i::Name> name(isolate->factory()->InternalizeOneByteString( | 105 i::Handle<i::Name> name(isolate->factory()->InternalizeOneByteString( |
| 119 STATIC_CHAR_VECTOR("__foreign_init__"))); | 106 STATIC_CHAR_VECTOR("__foreign_init__"))); |
| 120 | 107 |
| 121 i::Handle<i::Object> module_object = maybe_module_object.ToHandleChecked(); | 108 i::Handle<i::Object> module_object = maybe_module_object.ToHandleChecked(); |
| 122 i::MaybeHandle<i::Object> maybe_init = | 109 i::MaybeHandle<i::Object> maybe_init = |
| 123 i::Object::GetProperty(module_object, name); | 110 i::Object::GetProperty(module_object, name); |
| (...skipping 25 matching lines...) Expand all Loading... | |
| 149 if (retval.is_null()) { | 136 if (retval.is_null()) { |
| 150 thrower.Error( | 137 thrower.Error( |
| 151 "WASM.instantiateModuleFromAsm(): foreign init function failed"); | 138 "WASM.instantiateModuleFromAsm(): foreign init function failed"); |
| 152 return MaybeHandle<Object>(); | 139 return MaybeHandle<Object>(); |
| 153 } | 140 } |
| 154 return maybe_module_object; | 141 return maybe_module_object; |
| 155 } | 142 } |
| 156 | 143 |
| 157 } // namespace internal | 144 } // namespace internal |
| 158 } // namespace v8 | 145 } // namespace v8 |
| OLD | NEW |