| 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/api-natives.h" | 5 #include "src/api-natives.h" |
| 6 #include "src/api.h" | 6 #include "src/api.h" |
| 7 #include "src/asmjs/asm-js.h" | 7 #include "src/asmjs/asm-js.h" |
| 8 #include "src/asmjs/asm-typer.h" | 8 #include "src/asmjs/asm-typer.h" |
| 9 #include "src/asmjs/asm-wasm-builder.h" | 9 #include "src/asmjs/asm-wasm-builder.h" |
| 10 #include "src/assert-scope.h" | 10 #include "src/assert-scope.h" |
| (...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 149 info->set_literal( | 149 info->set_literal( |
| 150 info->scope()->declarations()->at(0)->AsFunctionDeclaration()->fun()); | 150 info->scope()->declarations()->at(0)->AsFunctionDeclaration()->fun()); |
| 151 | 151 |
| 152 return i::AsmJs::ConvertAsmToWasm(info); | 152 return i::AsmJs::ConvertAsmToWasm(info); |
| 153 } | 153 } |
| 154 | 154 |
| 155 i::MaybeHandle<i::JSObject> InstantiateModule( | 155 i::MaybeHandle<i::JSObject> InstantiateModule( |
| 156 const v8::FunctionCallbackInfo<v8::Value>& args, const byte* start, | 156 const v8::FunctionCallbackInfo<v8::Value>& args, const byte* start, |
| 157 const byte* end, ErrorThrower* thrower, | 157 const byte* end, ErrorThrower* thrower, |
| 158 internal::wasm::ModuleOrigin origin = i::wasm::kWasmOrigin) { | 158 internal::wasm::ModuleOrigin origin = i::wasm::kWasmOrigin) { |
| 159 i::Handle<i::Context> context = |
| 160 v8::Utils::OpenHandle(*(args.GetIsolate()->GetCurrentContext())); |
| 159 i::Isolate* isolate = reinterpret_cast<i::Isolate*>(args.GetIsolate()); | 161 i::Isolate* isolate = reinterpret_cast<i::Isolate*>(args.GetIsolate()); |
| 160 | 162 |
| 161 // Decode but avoid a redundant pass over function bodies for verification. | 163 // Decode but avoid a redundant pass over function bodies for verification. |
| 162 // Verification will happen during compilation. | 164 // Verification will happen during compilation. |
| 163 i::Zone zone(isolate->allocator()); | 165 i::Zone zone(isolate->allocator()); |
| 164 internal::wasm::ModuleResult result = internal::wasm::DecodeWasmModule( | 166 internal::wasm::ModuleResult result = internal::wasm::DecodeWasmModule( |
| 165 isolate, &zone, start, end, false, origin); | 167 isolate, &zone, start, end, false, origin); |
| 166 | 168 |
| 167 i::MaybeHandle<i::JSObject> object; | 169 i::MaybeHandle<i::JSObject> object; |
| 168 if (result.failed()) { | 170 if (result.failed()) { |
| (...skipping 11 matching lines...) Expand all Loading... |
| 180 Local<Object> obj = Local<Object>::Cast(args[2]); | 182 Local<Object> obj = Local<Object>::Cast(args[2]); |
| 181 i::Handle<i::Object> mem_obj = v8::Utils::OpenHandle(*obj); | 183 i::Handle<i::Object> mem_obj = v8::Utils::OpenHandle(*obj); |
| 182 memory = i::Handle<i::JSArrayBuffer>(i::JSArrayBuffer::cast(*mem_obj)); | 184 memory = i::Handle<i::JSArrayBuffer>(i::JSArrayBuffer::cast(*mem_obj)); |
| 183 } | 185 } |
| 184 | 186 |
| 185 i::MaybeHandle<i::FixedArray> compiled_module = | 187 i::MaybeHandle<i::FixedArray> compiled_module = |
| 186 result.val->CompileFunctions(isolate, thrower); | 188 result.val->CompileFunctions(isolate, thrower); |
| 187 if (!thrower->error()) { | 189 if (!thrower->error()) { |
| 188 DCHECK(!compiled_module.is_null()); | 190 DCHECK(!compiled_module.is_null()); |
| 189 object = i::wasm::WasmModule::Instantiate( | 191 object = i::wasm::WasmModule::Instantiate( |
| 190 isolate, compiled_module.ToHandleChecked(), ffi, memory); | 192 isolate, context, compiled_module.ToHandleChecked(), ffi, memory); |
| 191 if (!object.is_null()) { | 193 if (!object.is_null()) { |
| 192 args.GetReturnValue().Set(v8::Utils::ToLocal(object.ToHandleChecked())); | 194 args.GetReturnValue().Set(v8::Utils::ToLocal(object.ToHandleChecked())); |
| 193 } | 195 } |
| 194 } | 196 } |
| 195 } | 197 } |
| 196 | 198 |
| 197 if (result.val) delete result.val; | 199 if (result.val) delete result.val; |
| 198 return object; | 200 return object; |
| 199 } | 201 } |
| 200 | 202 |
| (...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 387 Local<Object> obj = Local<Object>::Cast(args[1]); | 389 Local<Object> obj = Local<Object>::Cast(args[1]); |
| 388 ffi = i::Handle<i::JSReceiver>::cast(v8::Utils::OpenHandle(*obj)); | 390 ffi = i::Handle<i::JSReceiver>::cast(v8::Utils::OpenHandle(*obj)); |
| 389 } | 391 } |
| 390 | 392 |
| 391 i::Handle<i::JSArrayBuffer> memory = i::Handle<i::JSArrayBuffer>::null(); | 393 i::Handle<i::JSArrayBuffer> memory = i::Handle<i::JSArrayBuffer>::null(); |
| 392 if (args.Length() > 2 && args[2]->IsArrayBuffer()) { | 394 if (args.Length() > 2 && args[2]->IsArrayBuffer()) { |
| 393 Local<Object> obj = Local<Object>::Cast(args[2]); | 395 Local<Object> obj = Local<Object>::Cast(args[2]); |
| 394 i::Handle<i::Object> mem_obj = v8::Utils::OpenHandle(*obj); | 396 i::Handle<i::Object> mem_obj = v8::Utils::OpenHandle(*obj); |
| 395 memory = i::Handle<i::JSArrayBuffer>(i::JSArrayBuffer::cast(*mem_obj)); | 397 memory = i::Handle<i::JSArrayBuffer>(i::JSArrayBuffer::cast(*mem_obj)); |
| 396 } | 398 } |
| 397 i::MaybeHandle<i::JSObject> instance = | 399 i::MaybeHandle<i::JSObject> instance = i::wasm::WasmModule::Instantiate( |
| 398 i::wasm::WasmModule::Instantiate(i_isolate, compiled_code, ffi, memory); | 400 i_isolate, i_context, compiled_code, ffi, memory); |
| 399 if (instance.is_null()) { | 401 if (instance.is_null()) { |
| 400 thrower.Error("Could not instantiate module"); | 402 thrower.Error("Could not instantiate module"); |
| 401 return; | 403 return; |
| 402 } | 404 } |
| 403 v8::ReturnValue<v8::Value> return_value = args.GetReturnValue(); | 405 v8::ReturnValue<v8::Value> return_value = args.GetReturnValue(); |
| 404 return_value.Set(Utils::ToLocal(instance.ToHandleChecked())); | 406 return_value.Set(Utils::ToLocal(instance.ToHandleChecked())); |
| 405 } | 407 } |
| 406 } // namespace | 408 } // namespace |
| 407 | 409 |
| 408 // TODO(titzer): we use the API to create the function template because the | 410 // TODO(titzer): we use the API to create the function template because the |
| (...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 530 int unused_property_fields = in_object_properties - pre_allocated; | 532 int unused_property_fields = in_object_properties - pre_allocated; |
| 531 Handle<Map> map = Map::CopyInitialMap( | 533 Handle<Map> map = Map::CopyInitialMap( |
| 532 prev_map, instance_size, in_object_properties, unused_property_fields); | 534 prev_map, instance_size, in_object_properties, unused_property_fields); |
| 533 | 535 |
| 534 context->set_wasm_function_map(*map); | 536 context->set_wasm_function_map(*map); |
| 535 } | 537 } |
| 536 } | 538 } |
| 537 | 539 |
| 538 } // namespace internal | 540 } // namespace internal |
| 539 } // namespace v8 | 541 } // namespace v8 |
| OLD | NEW |