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 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
85 ErrorThrower* thrower) { | 85 ErrorThrower* thrower) { |
86 i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate); | 86 i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate); |
87 i::MaybeHandle<i::JSObject> nothing; | 87 i::MaybeHandle<i::JSObject> nothing; |
88 | 88 |
89 RawBuffer buffer = GetRawBufferSource(source, thrower); | 89 RawBuffer buffer = GetRawBufferSource(source, thrower); |
90 if (buffer.start == nullptr) return i::MaybeHandle<i::WasmModuleObject>(); | 90 if (buffer.start == nullptr) return i::MaybeHandle<i::WasmModuleObject>(); |
91 | 91 |
92 DCHECK(source->IsArrayBuffer() || source->IsTypedArray()); | 92 DCHECK(source->IsArrayBuffer() || source->IsTypedArray()); |
93 return i::wasm::CreateModuleObjectFromBytes( | 93 return i::wasm::CreateModuleObjectFromBytes( |
94 i_isolate, buffer.start, buffer.end, thrower, i::wasm::kWasmOrigin, | 94 i_isolate, buffer.start, buffer.end, thrower, i::wasm::kWasmOrigin, |
95 i::Handle<i::Script>::null(), nullptr, nullptr); | 95 i::Handle<i::Script>::null(), i::Vector<const byte>::empty()); |
96 } | 96 } |
97 | 97 |
98 static bool ValidateModule(v8::Isolate* isolate, | 98 static bool ValidateModule(v8::Isolate* isolate, |
99 const v8::Local<v8::Value> source, | 99 const v8::Local<v8::Value> source, |
100 ErrorThrower* thrower) { | 100 ErrorThrower* thrower) { |
101 i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate); | 101 i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate); |
102 i::MaybeHandle<i::JSObject> nothing; | 102 i::MaybeHandle<i::JSObject> nothing; |
103 | 103 |
104 RawBuffer buffer = GetRawBufferSource(source, thrower); | 104 RawBuffer buffer = GetRawBufferSource(source, thrower); |
105 if (buffer.start == nullptr) return false; | 105 if (buffer.start == nullptr) return false; |
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
214 Local<Object> obj = Local<Object>::Cast(args[1]); | 214 Local<Object> obj = Local<Object>::Cast(args[1]); |
215 ffi = i::Handle<i::JSReceiver>::cast(v8::Utils::OpenHandle(*obj)); | 215 ffi = i::Handle<i::JSReceiver>::cast(v8::Utils::OpenHandle(*obj)); |
216 } | 216 } |
217 | 217 |
218 i::Handle<i::JSArrayBuffer> memory = i::Handle<i::JSArrayBuffer>::null(); | 218 i::Handle<i::JSArrayBuffer> memory = i::Handle<i::JSArrayBuffer>::null(); |
219 if (args.Length() > 2 && args[2]->IsObject()) { | 219 if (args.Length() > 2 && args[2]->IsObject()) { |
220 Local<Object> obj = Local<Object>::Cast(args[2]); | 220 Local<Object> obj = Local<Object>::Cast(args[2]); |
221 i::Handle<i::Object> mem_obj = v8::Utils::OpenHandle(*obj); | 221 i::Handle<i::Object> mem_obj = v8::Utils::OpenHandle(*obj); |
222 if (i::WasmJs::IsWasmMemoryObject(i_isolate, mem_obj)) { | 222 if (i::WasmJs::IsWasmMemoryObject(i_isolate, mem_obj)) { |
223 memory = i::Handle<i::JSArrayBuffer>( | 223 memory = i::Handle<i::JSArrayBuffer>( |
224 i::Handle<i::WasmMemoryObject>::cast(mem_obj)->get_buffer(), | 224 i::Handle<i::WasmMemoryObject>::cast(mem_obj)->buffer(), i_isolate); |
225 i_isolate); | |
226 } else { | 225 } else { |
227 thrower.TypeError("Argument 2 must be a WebAssembly.Memory"); | 226 thrower.TypeError("Argument 2 must be a WebAssembly.Memory"); |
228 return; | 227 return; |
229 } | 228 } |
230 } | 229 } |
231 i::MaybeHandle<i::JSObject> instance = | 230 i::MaybeHandle<i::JSObject> instance = |
232 i::wasm::WasmModule::Instantiate(i_isolate, &thrower, i_obj, ffi, memory); | 231 i::wasm::WasmModule::Instantiate(i_isolate, &thrower, i_obj, ffi, memory); |
233 if (instance.is_null()) { | 232 if (instance.is_null()) { |
234 if (!thrower.error()) thrower.RuntimeError("Could not instantiate module"); | 233 if (!thrower.error()) thrower.RuntimeError("Could not instantiate module"); |
235 return; | 234 return; |
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
395 i::Handle<i::Context> i_context = Utils::OpenHandle(*context); | 394 i::Handle<i::Context> i_context = Utils::OpenHandle(*context); |
396 if (!BrandCheck(isolate, Utils::OpenHandle(*args.This()), | 395 if (!BrandCheck(isolate, Utils::OpenHandle(*args.This()), |
397 i::Handle<i::Symbol>(i_context->wasm_table_sym()), | 396 i::Handle<i::Symbol>(i_context->wasm_table_sym()), |
398 "Receiver is not a WebAssembly.Table")) { | 397 "Receiver is not a WebAssembly.Table")) { |
399 return; | 398 return; |
400 } | 399 } |
401 | 400 |
402 i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate); | 401 i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate); |
403 auto receiver = | 402 auto receiver = |
404 i::Handle<i::WasmTableObject>::cast(Utils::OpenHandle(*args.This())); | 403 i::Handle<i::WasmTableObject>::cast(Utils::OpenHandle(*args.This())); |
405 i::Handle<i::FixedArray> old_array(receiver->get_functions(), i_isolate); | 404 i::Handle<i::FixedArray> old_array(receiver->functions(), i_isolate); |
406 int old_size = old_array->length(); | 405 int old_size = old_array->length(); |
407 int64_t new_size64 = 0; | 406 int64_t new_size64 = 0; |
408 if (args.Length() > 0 && !args[0]->IntegerValue(context).To(&new_size64)) { | 407 if (args.Length() > 0 && !args[0]->IntegerValue(context).To(&new_size64)) { |
409 return; | 408 return; |
410 } | 409 } |
411 new_size64 += old_size; | 410 new_size64 += old_size; |
412 | 411 |
413 if (new_size64 < old_size || new_size64 > receiver->maximum_length()) { | 412 if (new_size64 < old_size || new_size64 > receiver->maximum_length()) { |
414 v8::Local<v8::Value> e = v8::Exception::RangeError( | 413 v8::Local<v8::Value> e = v8::Exception::RangeError( |
415 v8_str(isolate, new_size64 < old_size ? "trying to shrink table" | 414 v8_str(isolate, new_size64 < old_size ? "trying to shrink table" |
(...skipping 21 matching lines...) Expand all Loading... |
437 i::Handle<i::Context> i_context = Utils::OpenHandle(*context); | 436 i::Handle<i::Context> i_context = Utils::OpenHandle(*context); |
438 if (!BrandCheck(isolate, Utils::OpenHandle(*args.This()), | 437 if (!BrandCheck(isolate, Utils::OpenHandle(*args.This()), |
439 i::Handle<i::Symbol>(i_context->wasm_table_sym()), | 438 i::Handle<i::Symbol>(i_context->wasm_table_sym()), |
440 "Receiver is not a WebAssembly.Table")) { | 439 "Receiver is not a WebAssembly.Table")) { |
441 return; | 440 return; |
442 } | 441 } |
443 | 442 |
444 i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate); | 443 i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate); |
445 auto receiver = | 444 auto receiver = |
446 i::Handle<i::WasmTableObject>::cast(Utils::OpenHandle(*args.This())); | 445 i::Handle<i::WasmTableObject>::cast(Utils::OpenHandle(*args.This())); |
447 i::Handle<i::FixedArray> array(receiver->get_functions(), i_isolate); | 446 i::Handle<i::FixedArray> array(receiver->functions(), i_isolate); |
448 int i = 0; | 447 int i = 0; |
449 if (args.Length() > 0 && !args[0]->Int32Value(context).To(&i)) return; | 448 if (args.Length() > 0 && !args[0]->Int32Value(context).To(&i)) return; |
450 v8::ReturnValue<v8::Value> return_value = args.GetReturnValue(); | 449 v8::ReturnValue<v8::Value> return_value = args.GetReturnValue(); |
451 if (i < 0 || i >= array->length()) { | 450 if (i < 0 || i >= array->length()) { |
452 v8::Local<v8::Value> e = | 451 v8::Local<v8::Value> e = |
453 v8::Exception::RangeError(v8_str(isolate, "index out of bounds")); | 452 v8::Exception::RangeError(v8_str(isolate, "index out of bounds")); |
454 isolate->ThrowException(e); | 453 isolate->ThrowException(e); |
455 return; | 454 return; |
456 } | 455 } |
457 | 456 |
(...skipping 23 matching lines...) Expand all Loading... |
481 i::Handle<i::JSFunction>::cast(value)->code()->kind() != | 480 i::Handle<i::JSFunction>::cast(value)->code()->kind() != |
482 i::Code::JS_TO_WASM_FUNCTION)) { | 481 i::Code::JS_TO_WASM_FUNCTION)) { |
483 v8::Local<v8::Value> e = v8::Exception::TypeError( | 482 v8::Local<v8::Value> e = v8::Exception::TypeError( |
484 v8_str(isolate, "Argument 1 must be null or a WebAssembly function")); | 483 v8_str(isolate, "Argument 1 must be null or a WebAssembly function")); |
485 isolate->ThrowException(e); | 484 isolate->ThrowException(e); |
486 return; | 485 return; |
487 } | 486 } |
488 | 487 |
489 auto receiver = | 488 auto receiver = |
490 i::Handle<i::WasmTableObject>::cast(Utils::OpenHandle(*args.This())); | 489 i::Handle<i::WasmTableObject>::cast(Utils::OpenHandle(*args.This())); |
491 i::Handle<i::FixedArray> array(receiver->get_functions(), i_isolate); | 490 i::Handle<i::FixedArray> array(receiver->functions(), i_isolate); |
492 int i; | 491 int i; |
493 if (!args[0]->Int32Value(context).To(&i)) return; | 492 if (!args[0]->Int32Value(context).To(&i)) return; |
494 if (i < 0 || i >= array->length()) { | 493 if (i < 0 || i >= array->length()) { |
495 v8::Local<v8::Value> e = | 494 v8::Local<v8::Value> e = |
496 v8::Exception::RangeError(v8_str(isolate, "index out of bounds")); | 495 v8::Exception::RangeError(v8_str(isolate, "index out of bounds")); |
497 isolate->ThrowException(e); | 496 isolate->ThrowException(e); |
498 return; | 497 return; |
499 } | 498 } |
500 | 499 |
501 i::Handle<i::FixedArray> dispatch_tables(receiver->get_dispatch_tables(), | 500 i::Handle<i::FixedArray> dispatch_tables(receiver->dispatch_tables(), |
502 i_isolate); | 501 i_isolate); |
503 if (value->IsNull(i_isolate)) { | 502 if (value->IsNull(i_isolate)) { |
504 i::wasm::UpdateDispatchTables(i_isolate, dispatch_tables, i, | 503 i::wasm::UpdateDispatchTables(i_isolate, dispatch_tables, i, |
505 i::Handle<i::JSFunction>::null()); | 504 i::Handle<i::JSFunction>::null()); |
506 } else { | 505 } else { |
507 i::wasm::UpdateDispatchTables(i_isolate, dispatch_tables, i, | 506 i::wasm::UpdateDispatchTables(i_isolate, dispatch_tables, i, |
508 i::Handle<i::JSFunction>::cast(value)); | 507 i::Handle<i::JSFunction>::cast(value)); |
509 } | 508 } |
510 | 509 |
511 i::Handle<i::FixedArray>::cast(array)->set(i, *value); | 510 i::Handle<i::FixedArray>::cast(array)->set(i, *value); |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
548 Local<Context> context = isolate->GetCurrentContext(); | 547 Local<Context> context = isolate->GetCurrentContext(); |
549 i::Handle<i::Context> i_context = Utils::OpenHandle(*context); | 548 i::Handle<i::Context> i_context = Utils::OpenHandle(*context); |
550 if (!BrandCheck(isolate, Utils::OpenHandle(*args.This()), | 549 if (!BrandCheck(isolate, Utils::OpenHandle(*args.This()), |
551 i::Handle<i::Symbol>(i_context->wasm_memory_sym()), | 550 i::Handle<i::Symbol>(i_context->wasm_memory_sym()), |
552 "Receiver is not a WebAssembly.Memory")) { | 551 "Receiver is not a WebAssembly.Memory")) { |
553 return; | 552 return; |
554 } | 553 } |
555 i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate); | 554 i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate); |
556 i::Handle<i::WasmMemoryObject> receiver = | 555 i::Handle<i::WasmMemoryObject> receiver = |
557 i::Handle<i::WasmMemoryObject>::cast(Utils::OpenHandle(*args.This())); | 556 i::Handle<i::WasmMemoryObject>::cast(Utils::OpenHandle(*args.This())); |
558 i::Handle<i::Object> buffer(receiver->get_buffer(), i_isolate); | 557 i::Handle<i::Object> buffer(receiver->buffer(), i_isolate); |
559 DCHECK(buffer->IsJSArrayBuffer()); | 558 DCHECK(buffer->IsJSArrayBuffer()); |
560 v8::ReturnValue<v8::Value> return_value = args.GetReturnValue(); | 559 v8::ReturnValue<v8::Value> return_value = args.GetReturnValue(); |
561 return_value.Set(Utils::ToLocal(buffer)); | 560 return_value.Set(Utils::ToLocal(buffer)); |
562 } | 561 } |
563 } // namespace | 562 } // namespace |
564 | 563 |
565 // TODO(titzer): we use the API to create the function template because the | 564 // TODO(titzer): we use the API to create the function template because the |
566 // internal guts are too ugly to replicate here. | 565 // internal guts are too ugly to replicate here. |
567 static i::Handle<i::FunctionTemplateInfo> NewTemplate(i::Isolate* i_isolate, | 566 static i::Handle<i::FunctionTemplateInfo> NewTemplate(i::Isolate* i_isolate, |
568 FunctionCallback func) { | 567 FunctionCallback func) { |
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
765 i::Handle<i::Symbol> symbol(isolate->context()->wasm_memory_sym(), isolate); | 764 i::Handle<i::Symbol> symbol(isolate->context()->wasm_memory_sym(), isolate); |
766 return HasBrand(value, symbol); | 765 return HasBrand(value, symbol); |
767 } | 766 } |
768 | 767 |
769 bool WasmJs::IsWasmTableObject(Isolate* isolate, Handle<Object> value) { | 768 bool WasmJs::IsWasmTableObject(Isolate* isolate, Handle<Object> value) { |
770 i::Handle<i::Symbol> symbol(isolate->context()->wasm_table_sym(), isolate); | 769 i::Handle<i::Symbol> symbol(isolate->context()->wasm_table_sym(), isolate); |
771 return HasBrand(value, symbol); | 770 return HasBrand(value, symbol); |
772 } | 771 } |
773 } // namespace internal | 772 } // namespace internal |
774 } // namespace v8 | 773 } // namespace v8 |
OLD | NEW |