Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(479)

Side by Side Diff: src/wasm/wasm-js.cc

Issue 2971093003: [wasm] Remove the use of private symbols for branding. (Closed)
Patch Set: [wasm] Remove the use of private symbols for branding. Created 3 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/wasm/module-compiler.cc ('k') | src/wasm/wasm-objects.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/assert-scope.h" 7 #include "src/assert-scope.h"
8 #include "src/ast/ast.h" 8 #include "src/ast/ast.h"
9 #include "src/execution.h" 9 #include "src/execution.h"
10 #include "src/factory.h" 10 #include "src/factory.h"
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
62 Reset(); 62 Reset();
63 } else if (isolate()->has_pending_exception()) { 63 } else if (isolate()->has_pending_exception()) {
64 Reset(); 64 Reset();
65 isolate()->OptionalRescheduleException(false); 65 isolate()->OptionalRescheduleException(false);
66 } else if (error()) { 66 } else if (error()) {
67 isolate()->ScheduleThrow(*Reify()); 67 isolate()->ScheduleThrow(*Reify());
68 } 68 }
69 } 69 }
70 }; 70 };
71 71
72 // TODO(titzer): move brand check to the respective types, and don't throw
73 // in it, rather, use a provided ErrorThrower, or let caller handle it.
74 static bool HasBrand(i::Handle<i::Object> value, i::Handle<i::Symbol> sym) {
75 if (!value->IsJSObject()) return false;
76 i::Handle<i::JSObject> object = i::Handle<i::JSObject>::cast(value);
77 Maybe<bool> has_brand = i::JSObject::HasOwnProperty(object, sym);
78 return has_brand.FromMaybe(false);
79 }
80
81 static bool BrandCheck(i::Handle<i::Object> value, i::Handle<i::Symbol> sym,
82 ErrorThrower* thrower, const char* msg) {
83 return HasBrand(value, sym) ? true : (thrower->TypeError("%s", msg), false);
84 }
85
86 i::Handle<i::String> v8_str(i::Isolate* isolate, const char* str) { 72 i::Handle<i::String> v8_str(i::Isolate* isolate, const char* str) {
87 return isolate->factory()->NewStringFromAsciiChecked(str); 73 return isolate->factory()->NewStringFromAsciiChecked(str);
88 } 74 }
89 Local<String> v8_str(Isolate* isolate, const char* str) { 75 Local<String> v8_str(Isolate* isolate, const char* str) {
90 return Utils::ToLocal(v8_str(reinterpret_cast<i::Isolate*>(isolate), str)); 76 return Utils::ToLocal(v8_str(reinterpret_cast<i::Isolate*>(isolate), str));
91 } 77 }
92 78
93 i::MaybeHandle<i::WasmModuleObject> GetFirstArgumentAsModule( 79 i::MaybeHandle<i::WasmModuleObject> GetFirstArgumentAsModule(
94 const v8::FunctionCallbackInfo<v8::Value>& args, ErrorThrower* thrower) { 80 const v8::FunctionCallbackInfo<v8::Value>& args, ErrorThrower* thrower) {
95 v8::Isolate* isolate = args.GetIsolate();
96 if (args.Length() < 1) { 81 if (args.Length() < 1) {
97 thrower->TypeError("Argument 0 must be a WebAssembly.Module"); 82 thrower->TypeError("Argument 0 must be a WebAssembly.Module");
98 return {}; 83 return {};
99 } 84 }
100 85
101 Local<Context> context = isolate->GetCurrentContext(); 86 i::Handle<i::Object> arg0 = Utils::OpenHandle(*args[0]);
102 i::Handle<i::Context> i_context = Utils::OpenHandle(*context); 87 if (!arg0->IsWasmModuleObject()) {
103 if (!BrandCheck(Utils::OpenHandle(*args[0]), 88 thrower->TypeError("Argument 0 must be a WebAssembly.Module");
104 i::handle(i_context->wasm_module_sym()), thrower,
105 "Argument 0 must be a WebAssembly.Module")) {
106 return {}; 89 return {};
107 } 90 }
108 91
109 Local<Object> module_obj = Local<Object>::Cast(args[0]); 92 Local<Object> module_obj = Local<Object>::Cast(args[0]);
110 return i::Handle<i::WasmModuleObject>::cast( 93 return i::Handle<i::WasmModuleObject>::cast(
111 v8::Utils::OpenHandle(*module_obj)); 94 v8::Utils::OpenHandle(*module_obj));
112 } 95 }
113 96
114 i::wasm::ModuleWireBytes GetFirstArgumentAsBytes( 97 i::wasm::ModuleWireBytes GetFirstArgumentAsBytes(
115 const v8::FunctionCallbackInfo<v8::Value>& args, ErrorThrower* thrower) { 98 const v8::FunctionCallbackInfo<v8::Value>& args, ErrorThrower* thrower) {
(...skipping 315 matching lines...) Expand 10 before | Expand all | Expand 10 after
431 void WebAssemblyInstantiate(const v8::FunctionCallbackInfo<v8::Value>& args) { 414 void WebAssemblyInstantiate(const v8::FunctionCallbackInfo<v8::Value>& args) {
432 v8::Isolate* isolate = args.GetIsolate(); 415 v8::Isolate* isolate = args.GetIsolate();
433 i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate); 416 i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate);
434 MicrotasksScope runs_microtasks(isolate, MicrotasksScope::kRunMicrotasks); 417 MicrotasksScope runs_microtasks(isolate, MicrotasksScope::kRunMicrotasks);
435 418
436 ScheduledErrorThrower thrower(i_isolate, "WebAssembly.instantiate()"); 419 ScheduledErrorThrower thrower(i_isolate, "WebAssembly.instantiate()");
437 420
438 HandleScope scope(isolate); 421 HandleScope scope(isolate);
439 422
440 Local<Context> context = isolate->GetCurrentContext(); 423 Local<Context> context = isolate->GetCurrentContext();
441 i::Handle<i::Context> i_context = Utils::OpenHandle(*context);
442 424
443 ASSIGN(Promise::Resolver, resolver, Promise::Resolver::New(context)); 425 ASSIGN(Promise::Resolver, resolver, Promise::Resolver::New(context));
444 Local<Promise> module_promise = resolver->GetPromise(); 426 Local<Promise> module_promise = resolver->GetPromise();
445 args.GetReturnValue().Set(module_promise); 427 args.GetReturnValue().Set(module_promise);
446 428
447 if (args.Length() < 1) { 429 if (args.Length() < 1) {
448 thrower.TypeError( 430 thrower.TypeError(
449 "Argument 0 must be provided and must be either a buffer source or a " 431 "Argument 0 must be provided and must be either a buffer source or a "
450 "WebAssembly.Module object"); 432 "WebAssembly.Module object");
451 auto maybe = resolver->Reject(context, Utils::ToLocal(thrower.Reify())); 433 auto maybe = resolver->Reject(context, Utils::ToLocal(thrower.Reify()));
452 CHECK_IMPLIES(!maybe.FromMaybe(false), 434 CHECK_IMPLIES(!maybe.FromMaybe(false),
453 i_isolate->has_scheduled_exception()); 435 i_isolate->has_scheduled_exception());
454 return; 436 return;
455 } 437 }
456 438
457 Local<Value> first_arg_value = args[0]; 439 Local<Value> first_arg_value = args[0];
458 i::Handle<i::Object> first_arg = Utils::OpenHandle(*first_arg_value); 440 i::Handle<i::Object> first_arg = Utils::OpenHandle(*first_arg_value);
459 if (!first_arg->IsJSObject()) { 441 if (!first_arg->IsJSObject()) {
460 thrower.TypeError( 442 thrower.TypeError(
461 "Argument 0 must be a buffer source or a WebAssembly.Module object"); 443 "Argument 0 must be a buffer source or a WebAssembly.Module object");
462 auto maybe = resolver->Reject(context, Utils::ToLocal(thrower.Reify())); 444 auto maybe = resolver->Reject(context, Utils::ToLocal(thrower.Reify()));
463 CHECK_IMPLIES(!maybe.FromMaybe(false), 445 CHECK_IMPLIES(!maybe.FromMaybe(false),
464 i_isolate->has_scheduled_exception()); 446 i_isolate->has_scheduled_exception());
465 return; 447 return;
466 } 448 }
467 449
468 FunctionCallback instantiator = nullptr; 450 FunctionCallback instantiator = nullptr;
469 if (HasBrand(first_arg, i::Handle<i::Symbol>(i_context->wasm_module_sym()))) { 451 if (first_arg->IsWasmModuleObject()) {
470 module_promise = resolver->GetPromise(); 452 module_promise = resolver->GetPromise();
471 if (!resolver->Resolve(context, first_arg_value).IsJust()) return; 453 if (!resolver->Resolve(context, first_arg_value).IsJust()) return;
472 instantiator = WebAssemblyInstantiateImplCallback; 454 instantiator = WebAssemblyInstantiateImplCallback;
473 } else { 455 } else {
474 ASSIGN(Function, async_compile, Function::New(context, WebAssemblyCompile)); 456 ASSIGN(Function, async_compile, Function::New(context, WebAssemblyCompile));
475 ASSIGN(Value, async_compile_retval, 457 ASSIGN(Value, async_compile_retval,
476 async_compile->Call(context, args.Holder(), 1, &first_arg_value)); 458 async_compile->Call(context, args.Holder(), 1, &first_arg_value));
477 module_promise = Local<Promise>::Cast(async_compile_retval); 459 module_promise = Local<Promise>::Cast(async_compile_retval);
478 instantiator = WebAssemblyInstantiateToPairCallback; 460 instantiator = WebAssemblyInstantiateToPairCallback;
479 } 461 }
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after
605 i::wasm::NewArrayBuffer(i_isolate, size, i::FLAG_wasm_guard_pages); 587 i::wasm::NewArrayBuffer(i_isolate, size, i::FLAG_wasm_guard_pages);
606 if (buffer.is_null()) { 588 if (buffer.is_null()) {
607 thrower.RangeError("could not allocate memory"); 589 thrower.RangeError("could not allocate memory");
608 return; 590 return;
609 } 591 }
610 i::Handle<i::JSObject> memory_obj = 592 i::Handle<i::JSObject> memory_obj =
611 i::WasmMemoryObject::New(i_isolate, buffer, maximum); 593 i::WasmMemoryObject::New(i_isolate, buffer, maximum);
612 args.GetReturnValue().Set(Utils::ToLocal(memory_obj)); 594 args.GetReturnValue().Set(Utils::ToLocal(memory_obj));
613 } 595 }
614 596
597 #define NAME_OF_WasmMemoryObject "WebAssembly.Memory"
598 #define NAME_OF_WasmModuleObject "WebAssembly.Module"
599 #define NAME_OF_WasmInstanceObject "WebAssembly.Instance"
600 #define NAME_OF_WasmTableObject "WebAssembly.Table"
601
602 #define EXTRACT_THIS(var, WasmType) \
603 i::Handle<i::WasmType> var; \
604 { \
605 i::Handle<i::Object> this_arg = Utils::OpenHandle(*args.This()); \
606 if (!this_arg->Is##WasmType()) { \
607 thrower.TypeError("Receiver is not a " NAME_OF_##WasmType); \
608 return; \
609 } \
610 var = i::Handle<i::WasmType>::cast(this_arg); \
611 }
612
615 void WebAssemblyTableGetLength( 613 void WebAssemblyTableGetLength(
616 const v8::FunctionCallbackInfo<v8::Value>& args) { 614 const v8::FunctionCallbackInfo<v8::Value>& args) {
617 v8::Isolate* isolate = args.GetIsolate(); 615 v8::Isolate* isolate = args.GetIsolate();
618 i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate); 616 i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate);
619 HandleScope scope(isolate); 617 HandleScope scope(isolate);
620 ScheduledErrorThrower thrower(i_isolate, "WebAssembly.Table.length()"); 618 ScheduledErrorThrower thrower(i_isolate, "WebAssembly.Table.length()");
621 Local<Context> context = isolate->GetCurrentContext(); 619 EXTRACT_THIS(receiver, WasmTableObject);
622 i::Handle<i::Context> i_context = Utils::OpenHandle(*context);
623 if (!BrandCheck(Utils::OpenHandle(*args.This()),
624 i::Handle<i::Symbol>(i_context->wasm_table_sym()), &thrower,
625 "Receiver is not a WebAssembly.Table")) {
626 return;
627 }
628 auto receiver =
629 i::Handle<i::WasmTableObject>::cast(Utils::OpenHandle(*args.This()));
630 args.GetReturnValue().Set( 620 args.GetReturnValue().Set(
631 v8::Number::New(isolate, receiver->current_length())); 621 v8::Number::New(isolate, receiver->current_length()));
632 } 622 }
633 623
634 // WebAssembly.Table.grow(num) -> num 624 // WebAssembly.Table.grow(num) -> num
635 void WebAssemblyTableGrow(const v8::FunctionCallbackInfo<v8::Value>& args) { 625 void WebAssemblyTableGrow(const v8::FunctionCallbackInfo<v8::Value>& args) {
636 v8::Isolate* isolate = args.GetIsolate(); 626 v8::Isolate* isolate = args.GetIsolate();
637 i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate); 627 i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate);
638 HandleScope scope(isolate); 628 HandleScope scope(isolate);
639 ScheduledErrorThrower thrower(i_isolate, "WebAssembly.Table.grow()"); 629 ScheduledErrorThrower thrower(i_isolate, "WebAssembly.Table.grow()");
640 Local<Context> context = isolate->GetCurrentContext(); 630 Local<Context> context = isolate->GetCurrentContext();
641 i::Handle<i::Context> i_context = Utils::OpenHandle(*context); 631 EXTRACT_THIS(receiver, WasmTableObject);
642 if (!BrandCheck(Utils::OpenHandle(*args.This()),
643 i::Handle<i::Symbol>(i_context->wasm_table_sym()), &thrower,
644 "Receiver is not a WebAssembly.Table")) {
645 return;
646 }
647 632
648 auto receiver =
649 i::Handle<i::WasmTableObject>::cast(Utils::OpenHandle(*args.This()));
650 i::Handle<i::FixedArray> old_array(receiver->functions(), i_isolate); 633 i::Handle<i::FixedArray> old_array(receiver->functions(), i_isolate);
651 int old_size = old_array->length(); 634 int old_size = old_array->length();
652 int64_t new_size64 = 0; 635 int64_t new_size64 = 0;
653 if (args.Length() > 0 && !args[0]->IntegerValue(context).To(&new_size64)) { 636 if (args.Length() > 0 && !args[0]->IntegerValue(context).To(&new_size64)) {
654 return; 637 return;
655 } 638 }
656 new_size64 += old_size; 639 new_size64 += old_size;
657 640
658 int64_t max_size64 = receiver->maximum_length(); 641 int64_t max_size64 = receiver->maximum_length();
659 if (max_size64 < 0 || 642 if (max_size64 < 0 ||
(...skipping 24 matching lines...) Expand all
684 return_value.Set(old_size); 667 return_value.Set(old_size);
685 } 668 }
686 669
687 // WebAssembly.Table.get(num) -> JSFunction 670 // WebAssembly.Table.get(num) -> JSFunction
688 void WebAssemblyTableGet(const v8::FunctionCallbackInfo<v8::Value>& args) { 671 void WebAssemblyTableGet(const v8::FunctionCallbackInfo<v8::Value>& args) {
689 v8::Isolate* isolate = args.GetIsolate(); 672 v8::Isolate* isolate = args.GetIsolate();
690 i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate); 673 i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate);
691 HandleScope scope(isolate); 674 HandleScope scope(isolate);
692 ScheduledErrorThrower thrower(i_isolate, "WebAssembly.Table.get()"); 675 ScheduledErrorThrower thrower(i_isolate, "WebAssembly.Table.get()");
693 Local<Context> context = isolate->GetCurrentContext(); 676 Local<Context> context = isolate->GetCurrentContext();
694 i::Handle<i::Context> i_context = Utils::OpenHandle(*context); 677 EXTRACT_THIS(receiver, WasmTableObject);
695 if (!BrandCheck(Utils::OpenHandle(*args.This()),
696 i::Handle<i::Symbol>(i_context->wasm_table_sym()), &thrower,
697 "Receiver is not a WebAssembly.Table")) {
698 return;
699 }
700
701 auto receiver =
702 i::Handle<i::WasmTableObject>::cast(Utils::OpenHandle(*args.This()));
703 i::Handle<i::FixedArray> array(receiver->functions(), i_isolate); 678 i::Handle<i::FixedArray> array(receiver->functions(), i_isolate);
704 int i = 0; 679 int i = 0;
705 if (args.Length() > 0 && !args[0]->Int32Value(context).To(&i)) return; 680 if (args.Length() > 0 && !args[0]->Int32Value(context).To(&i)) return;
706 v8::ReturnValue<v8::Value> return_value = args.GetReturnValue(); 681 v8::ReturnValue<v8::Value> return_value = args.GetReturnValue();
707 if (i < 0 || i >= array->length()) { 682 if (i < 0 || i >= array->length()) {
708 thrower.RangeError("index out of bounds"); 683 thrower.RangeError("index out of bounds");
709 return; 684 return;
710 } 685 }
711 686
712 i::Handle<i::Object> value(array->get(i), i_isolate); 687 i::Handle<i::Object> value(array->get(i), i_isolate);
713 return_value.Set(Utils::ToLocal(value)); 688 return_value.Set(Utils::ToLocal(value));
714 } 689 }
715 690
716 // WebAssembly.Table.set(num, JSFunction) 691 // WebAssembly.Table.set(num, JSFunction)
717 void WebAssemblyTableSet(const v8::FunctionCallbackInfo<v8::Value>& args) { 692 void WebAssemblyTableSet(const v8::FunctionCallbackInfo<v8::Value>& args) {
718 v8::Isolate* isolate = args.GetIsolate(); 693 v8::Isolate* isolate = args.GetIsolate();
719 i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate); 694 i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate);
720 HandleScope scope(isolate); 695 HandleScope scope(isolate);
721 ScheduledErrorThrower thrower(i_isolate, "WebAssembly.Table.set()"); 696 ScheduledErrorThrower thrower(i_isolate, "WebAssembly.Table.set()");
722 Local<Context> context = isolate->GetCurrentContext(); 697 Local<Context> context = isolate->GetCurrentContext();
723 i::Handle<i::Context> i_context = Utils::OpenHandle(*context); 698 EXTRACT_THIS(receiver, WasmTableObject);
724 if (!BrandCheck(Utils::OpenHandle(*args.This()), 699
725 i::Handle<i::Symbol>(i_context->wasm_table_sym()), &thrower,
726 "Receiver is not a WebAssembly.Table")) {
727 return;
728 }
729 if (args.Length() < 2) { 700 if (args.Length() < 2) {
730 thrower.TypeError("Argument 1 must be null or a function"); 701 thrower.TypeError("Argument 1 must be null or a function");
731 return; 702 return;
732 } 703 }
733 704
734 // {This} parameter.
735 auto receiver =
736 i::Handle<i::WasmTableObject>::cast(Utils::OpenHandle(*args.This()));
737
738 // Parameter 0. 705 // Parameter 0.
739 int32_t index; 706 int32_t index;
740 if (!args[0]->Int32Value(context).To(&index)) return; 707 if (!args[0]->Int32Value(context).To(&index)) return;
741 708
742 // Parameter 1. 709 // Parameter 1.
743 i::Handle<i::Object> value = Utils::OpenHandle(*args[1]); 710 i::Handle<i::Object> value = Utils::OpenHandle(*args[1]);
744 if (!value->IsNull(i_isolate) && 711 if (!value->IsNull(i_isolate) &&
745 (!value->IsJSFunction() || 712 (!value->IsJSFunction() ||
746 i::Handle<i::JSFunction>::cast(value)->code()->kind() != 713 i::Handle<i::JSFunction>::cast(value)->code()->kind() !=
747 i::Code::JS_TO_WASM_FUNCTION)) { 714 i::Code::JS_TO_WASM_FUNCTION)) {
748 thrower.TypeError("Argument 1 must be null or a WebAssembly function"); 715 thrower.TypeError("Argument 1 must be null or a WebAssembly function");
749 return; 716 return;
750 } 717 }
751 718
752 i::wasm::TableSet(&thrower, i_isolate, receiver, index, 719 i::wasm::TableSet(&thrower, i_isolate, receiver, index,
753 value->IsNull(i_isolate) 720 value->IsNull(i_isolate)
754 ? i::Handle<i::JSFunction>::null() 721 ? i::Handle<i::JSFunction>::null()
755 : i::Handle<i::JSFunction>::cast(value)); 722 : i::Handle<i::JSFunction>::cast(value));
756 } 723 }
757 724
758 // WebAssembly.Memory.grow(num) -> num 725 // WebAssembly.Memory.grow(num) -> num
759 void WebAssemblyMemoryGrow(const v8::FunctionCallbackInfo<v8::Value>& args) { 726 void WebAssemblyMemoryGrow(const v8::FunctionCallbackInfo<v8::Value>& args) {
760 v8::Isolate* isolate = args.GetIsolate(); 727 v8::Isolate* isolate = args.GetIsolate();
761 i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate); 728 i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate);
762 HandleScope scope(isolate); 729 HandleScope scope(isolate);
763 ScheduledErrorThrower thrower(i_isolate, "WebAssembly.Memory.grow()"); 730 ScheduledErrorThrower thrower(i_isolate, "WebAssembly.Memory.grow()");
764 Local<Context> context = isolate->GetCurrentContext(); 731 Local<Context> context = isolate->GetCurrentContext();
765 i::Handle<i::Context> i_context = Utils::OpenHandle(*context); 732 EXTRACT_THIS(receiver, WasmMemoryObject);
766 if (!BrandCheck(Utils::OpenHandle(*args.This()), 733
767 i::Handle<i::Symbol>(i_context->wasm_memory_sym()), &thrower,
768 "Receiver is not a WebAssembly.Memory")) {
769 return;
770 }
771 int64_t delta_size = 0; 734 int64_t delta_size = 0;
772 if (args.Length() < 1 || !args[0]->IntegerValue(context).To(&delta_size)) { 735 if (args.Length() < 1 || !args[0]->IntegerValue(context).To(&delta_size)) {
773 thrower.TypeError("Argument 0 required, must be numeric value of pages"); 736 thrower.TypeError("Argument 0 required, must be numeric value of pages");
774 return; 737 return;
775 } 738 }
776 i::Handle<i::WasmMemoryObject> receiver =
777 i::Handle<i::WasmMemoryObject>::cast(Utils::OpenHandle(*args.This()));
778 int64_t max_size64 = receiver->maximum_pages(); 739 int64_t max_size64 = receiver->maximum_pages();
779 if (max_size64 < 0 || 740 if (max_size64 < 0 ||
780 max_size64 > static_cast<int64_t>(i::FLAG_wasm_max_mem_pages)) { 741 max_size64 > static_cast<int64_t>(i::FLAG_wasm_max_mem_pages)) {
781 max_size64 = i::FLAG_wasm_max_mem_pages; 742 max_size64 = i::FLAG_wasm_max_mem_pages;
782 } 743 }
783 i::Handle<i::JSArrayBuffer> old_buffer(receiver->array_buffer()); 744 i::Handle<i::JSArrayBuffer> old_buffer(receiver->array_buffer());
784 uint32_t old_size = 745 uint32_t old_size =
785 old_buffer->byte_length()->Number() / i::wasm::kSpecMaxWasmMemoryPages; 746 old_buffer->byte_length()->Number() / i::wasm::kSpecMaxWasmMemoryPages;
786 int64_t new_size64 = old_size + delta_size; 747 int64_t new_size64 = old_size + delta_size;
787 if (delta_size < 0 || max_size64 < new_size64 || new_size64 < old_size) { 748 if (delta_size < 0 || max_size64 < new_size64 || new_size64 < old_size) {
(...skipping 13 matching lines...) Expand all
801 return_value.Set(ret); 762 return_value.Set(ret);
802 } 763 }
803 764
804 // WebAssembly.Memory.buffer -> ArrayBuffer 765 // WebAssembly.Memory.buffer -> ArrayBuffer
805 void WebAssemblyMemoryGetBuffer( 766 void WebAssemblyMemoryGetBuffer(
806 const v8::FunctionCallbackInfo<v8::Value>& args) { 767 const v8::FunctionCallbackInfo<v8::Value>& args) {
807 v8::Isolate* isolate = args.GetIsolate(); 768 v8::Isolate* isolate = args.GetIsolate();
808 i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate); 769 i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate);
809 HandleScope scope(isolate); 770 HandleScope scope(isolate);
810 ScheduledErrorThrower thrower(i_isolate, "WebAssembly.Memory.buffer"); 771 ScheduledErrorThrower thrower(i_isolate, "WebAssembly.Memory.buffer");
811 Local<Context> context = isolate->GetCurrentContext(); 772 EXTRACT_THIS(receiver, WasmMemoryObject);
812 i::Handle<i::Context> i_context = Utils::OpenHandle(*context); 773
813 if (!BrandCheck(Utils::OpenHandle(*args.This()),
814 i::Handle<i::Symbol>(i_context->wasm_memory_sym()), &thrower,
815 "Receiver is not a WebAssembly.Memory")) {
816 return;
817 }
818 i::Handle<i::WasmMemoryObject> receiver =
819 i::Handle<i::WasmMemoryObject>::cast(Utils::OpenHandle(*args.This()));
820 i::Handle<i::Object> buffer(receiver->array_buffer(), i_isolate); 774 i::Handle<i::Object> buffer(receiver->array_buffer(), i_isolate);
821 DCHECK(buffer->IsJSArrayBuffer()); 775 DCHECK(buffer->IsJSArrayBuffer());
822 v8::ReturnValue<v8::Value> return_value = args.GetReturnValue(); 776 v8::ReturnValue<v8::Value> return_value = args.GetReturnValue();
823 return_value.Set(Utils::ToLocal(buffer)); 777 return_value.Set(Utils::ToLocal(buffer));
824 } 778 }
825 } // namespace 779 } // namespace
826 780
827 // TODO(titzer): we use the API to create the function template because the 781 // TODO(titzer): we use the API to create the function template because the
828 // internal guts are too ugly to replicate here. 782 // internal guts are too ugly to replicate here.
829 static i::Handle<i::FunctionTemplateInfo> NewTemplate(i::Isolate* i_isolate, 783 static i::Handle<i::FunctionTemplateInfo> NewTemplate(i::Isolate* i_isolate,
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
883 JSFunction::CalculateInstanceSizeHelper(instance_type, embedder_fields, 837 JSFunction::CalculateInstanceSizeHelper(instance_type, embedder_fields,
884 in_object_properties, &instance_size, 838 in_object_properties, &instance_size,
885 &in_object_properties); 839 &in_object_properties);
886 840
887 int unused_property_fields = in_object_properties - pre_allocated; 841 int unused_property_fields = in_object_properties - pre_allocated;
888 Handle<Map> map = Map::CopyInitialMap( 842 Handle<Map> map = Map::CopyInitialMap(
889 prev_map, instance_size, in_object_properties, unused_property_fields); 843 prev_map, instance_size, in_object_properties, unused_property_fields);
890 844
891 context->set_wasm_function_map(*map); 845 context->set_wasm_function_map(*map);
892 846
893 // Install symbols.
894
895 Factory* factory = isolate->factory(); 847 Factory* factory = isolate->factory();
896 // Create private symbols.
897 Handle<Symbol> module_sym = factory->NewPrivateSymbol();
898 context->set_wasm_module_sym(*module_sym);
899
900 Handle<Symbol> instance_sym = factory->NewPrivateSymbol();
901 context->set_wasm_instance_sym(*instance_sym);
902
903 Handle<Symbol> table_sym = factory->NewPrivateSymbol();
904 context->set_wasm_table_sym(*table_sym);
905
906 Handle<Symbol> memory_sym = factory->NewPrivateSymbol();
907 context->set_wasm_memory_sym(*memory_sym);
908 848
909 // Install the JS API. 849 // Install the JS API.
910 850
911 // Setup WebAssembly 851 // Setup WebAssembly
912 Handle<String> name = v8_str(isolate, "WebAssembly"); 852 Handle<String> name = v8_str(isolate, "WebAssembly");
913 Handle<JSFunction> cons = factory->NewFunction(isolate->strict_function_map(), 853 Handle<JSFunction> cons = factory->NewFunction(isolate->strict_function_map(),
914 name, MaybeHandle<Code>()); 854 name, MaybeHandle<Code>());
915 JSFunction::SetPrototype(cons, isolate->initial_object_prototype()); 855 JSFunction::SetPrototype(cons, isolate->initial_object_prototype());
916 cons->shared()->set_instance_class_name(*name); 856 cons->shared()->set_instance_class_name(*name);
917 Handle<JSObject> webassembly = factory->NewJSObject(cons, TENURED); 857 Handle<JSObject> webassembly = factory->NewJSObject(cons, TENURED);
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
1010 compile_error, attributes); 950 compile_error, attributes);
1011 Handle<JSFunction> link_error( 951 Handle<JSFunction> link_error(
1012 isolate->native_context()->wasm_link_error_function()); 952 isolate->native_context()->wasm_link_error_function());
1013 JSObject::AddProperty(webassembly, isolate->factory()->LinkError_string(), 953 JSObject::AddProperty(webassembly, isolate->factory()->LinkError_string(),
1014 link_error, attributes); 954 link_error, attributes);
1015 Handle<JSFunction> runtime_error( 955 Handle<JSFunction> runtime_error(
1016 isolate->native_context()->wasm_runtime_error_function()); 956 isolate->native_context()->wasm_runtime_error_function());
1017 JSObject::AddProperty(webassembly, isolate->factory()->RuntimeError_string(), 957 JSObject::AddProperty(webassembly, isolate->factory()->RuntimeError_string(),
1018 runtime_error, attributes); 958 runtime_error, attributes);
1019 } 959 }
1020
1021 bool WasmJs::IsWasmMemoryObject(Isolate* isolate, Handle<Object> value) {
1022 i::Handle<i::Symbol> symbol(isolate->context()->wasm_memory_sym(), isolate);
1023 return HasBrand(value, symbol);
1024 }
1025
1026 bool WasmJs::IsWasmTableObject(Isolate* isolate, Handle<Object> value) {
1027 i::Handle<i::Symbol> symbol(isolate->context()->wasm_table_sym(), isolate);
1028 return HasBrand(value, symbol);
1029 }
1030 } // namespace internal 960 } // namespace internal
1031 } // namespace v8 961 } // namespace v8
OLDNEW
« no previous file with comments | « src/wasm/module-compiler.cc ('k') | src/wasm/wasm-objects.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698