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

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

Issue 2490663002: [wasm] Move all heap-allocated WASM structures into wasm-objects.h. (Closed)
Patch Set: Created 4 years, 1 month 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
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/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"
11 #include "src/ast/ast.h" 11 #include "src/ast/ast.h"
12 #include "src/execution.h" 12 #include "src/execution.h"
13 #include "src/factory.h" 13 #include "src/factory.h"
14 #include "src/handles.h" 14 #include "src/handles.h"
15 #include "src/isolate.h" 15 #include "src/isolate.h"
16 #include "src/objects.h" 16 #include "src/objects.h"
17 #include "src/parsing/parse-info.h" 17 #include "src/parsing/parse-info.h"
18 18
19 #include "src/wasm/module-decoder.h" 19 #include "src/wasm/module-decoder.h"
20 #include "src/wasm/wasm-js.h" 20 #include "src/wasm/wasm-js.h"
21 #include "src/wasm/wasm-module.h" 21 #include "src/wasm/wasm-module.h"
22 #include "src/wasm/wasm-objects.h"
22 #include "src/wasm/wasm-result.h" 23 #include "src/wasm/wasm-result.h"
23 24
24 typedef uint8_t byte; 25 typedef uint8_t byte;
25 26
26 using v8::internal::wasm::ErrorThrower; 27 using v8::internal::wasm::ErrorThrower;
27 28
28 namespace v8 { 29 namespace v8 {
29 30
30 static const int kWasmTableArrayFieldIndex = 0; 31 static const int kWasmTableArrayFieldIndex = 0;
31 static const int kWasmTableMaximumFieldIndex = 1; 32 static const int kWasmTableMaximumFieldIndex = 1;
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
86 if (start == nullptr || end == start) { 87 if (start == nullptr || end == start) {
87 thrower->TypeError("ArrayBuffer argument is empty"); 88 thrower->TypeError("ArrayBuffer argument is empty");
88 } 89 }
89 } else { 90 } else {
90 thrower->TypeError("Argument 0 must be an ArrayBuffer or Uint8Array"); 91 thrower->TypeError("Argument 0 must be an ArrayBuffer or Uint8Array");
91 } 92 }
92 93
93 return {start, end}; 94 return {start, end};
94 } 95 }
95 96
96 static i::MaybeHandle<i::JSObject> CreateModuleObject( 97 static i::MaybeHandle<i::WasmModuleObject> CreateModuleObject(
97 v8::Isolate* isolate, const v8::Local<v8::Value> source, 98 v8::Isolate* isolate, const v8::Local<v8::Value> source,
98 ErrorThrower* thrower) { 99 ErrorThrower* thrower) {
99 i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate); 100 i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate);
100 i::MaybeHandle<i::JSObject> nothing; 101 i::MaybeHandle<i::JSObject> nothing;
101 102
102 RawBuffer buffer = GetRawBufferSource(source, thrower); 103 RawBuffer buffer = GetRawBufferSource(source, thrower);
103 if (buffer.start == nullptr) return i::MaybeHandle<i::JSObject>(); 104 if (buffer.start == nullptr) return i::MaybeHandle<i::WasmModuleObject>();
104 105
105 DCHECK(source->IsArrayBuffer() || source->IsTypedArray()); 106 DCHECK(source->IsArrayBuffer() || source->IsTypedArray());
106 return i::wasm::CreateModuleObjectFromBytes( 107 return i::wasm::CreateModuleObjectFromBytes(
107 i_isolate, buffer.start, buffer.end, thrower, i::wasm::kWasmOrigin, 108 i_isolate, buffer.start, buffer.end, thrower, i::wasm::kWasmOrigin,
108 i::Handle<i::Script>::null(), nullptr, nullptr); 109 i::Handle<i::Script>::null(), nullptr, nullptr);
109 } 110 }
110 111
111 static bool ValidateModule(v8::Isolate* isolate, 112 static bool ValidateModule(v8::Isolate* isolate,
112 const v8::Local<v8::Value> source, 113 const v8::Local<v8::Value> source,
113 ErrorThrower* thrower) { 114 ErrorThrower* thrower) {
114 i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate); 115 i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate);
115 i::MaybeHandle<i::JSObject> nothing; 116 i::MaybeHandle<i::JSObject> nothing;
116 117
117 RawBuffer buffer = GetRawBufferSource(source, thrower); 118 RawBuffer buffer = GetRawBufferSource(source, thrower);
118 if (buffer.start == nullptr) return false; 119 if (buffer.start == nullptr) return false;
119 120
120 DCHECK(source->IsArrayBuffer() || source->IsTypedArray()); 121 DCHECK(source->IsArrayBuffer() || source->IsTypedArray());
121 return i::wasm::ValidateModuleBytes(i_isolate, buffer.start, buffer.end, 122 return i::wasm::ValidateModuleBytes(i_isolate, buffer.start, buffer.end,
122 thrower, 123 thrower,
123 i::wasm::ModuleOrigin::kWasmOrigin); 124 i::wasm::ModuleOrigin::kWasmOrigin);
124 } 125 }
125 126
126 bool BrandCheck(Isolate* isolate, i::Handle<i::Object> value, 127 static bool BrandCheck(Isolate* isolate, i::Handle<i::Object> value,
127 i::Handle<i::Symbol> sym, const char* msg) { 128 i::Handle<i::Symbol> sym, const char* msg) {
128 if (value->IsJSObject()) { 129 if (value->IsJSObject()) {
129 i::Handle<i::JSObject> object = i::Handle<i::JSObject>::cast(value); 130 i::Handle<i::JSObject> object = i::Handle<i::JSObject>::cast(value);
130 Maybe<bool> has_brand = i::JSObject::HasOwnProperty(object, sym); 131 Maybe<bool> has_brand = i::JSObject::HasOwnProperty(object, sym);
131 if (has_brand.IsNothing()) return false; 132 if (has_brand.IsNothing()) return false;
132 if (has_brand.ToChecked()) return true; 133 if (has_brand.ToChecked()) return true;
133 } 134 }
134 v8::Local<v8::Value> e = v8::Exception::TypeError(v8_str(isolate, msg)); 135 v8::Local<v8::Value> e = v8::Exception::TypeError(v8_str(isolate, msg));
135 isolate->ThrowException(e); 136 isolate->ThrowException(e);
136 return false; 137 return false;
137 } 138 }
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
226 if (args.Length() > 1 && args[1]->IsObject()) { 227 if (args.Length() > 1 && args[1]->IsObject()) {
227 Local<Object> obj = Local<Object>::Cast(args[1]); 228 Local<Object> obj = Local<Object>::Cast(args[1]);
228 ffi = i::Handle<i::JSReceiver>::cast(v8::Utils::OpenHandle(*obj)); 229 ffi = i::Handle<i::JSReceiver>::cast(v8::Utils::OpenHandle(*obj));
229 } 230 }
230 231
231 i::Handle<i::JSArrayBuffer> memory = i::Handle<i::JSArrayBuffer>::null(); 232 i::Handle<i::JSArrayBuffer> memory = i::Handle<i::JSArrayBuffer>::null();
232 if (args.Length() > 2 && args[2]->IsObject()) { 233 if (args.Length() > 2 && args[2]->IsObject()) {
233 Local<Object> obj = Local<Object>::Cast(args[2]); 234 Local<Object> obj = Local<Object>::Cast(args[2]);
234 i::Handle<i::Object> mem_obj = v8::Utils::OpenHandle(*obj); 235 i::Handle<i::Object> mem_obj = v8::Utils::OpenHandle(*obj);
235 if (i::WasmJs::IsWasmMemoryObject(i_isolate, mem_obj)) { 236 if (i::WasmJs::IsWasmMemoryObject(i_isolate, mem_obj)) {
236 memory = i::WasmJs::GetWasmMemoryArrayBuffer(i_isolate, mem_obj); 237 memory = i::Handle<i::JSArrayBuffer>(
238 i::Handle<i::WasmMemoryObject>::cast(mem_obj)->get_buffer(),
239 i_isolate);
237 } else { 240 } else {
238 thrower.TypeError("Argument 2 must be a WebAssembly.Memory"); 241 thrower.TypeError("Argument 2 must be a WebAssembly.Memory");
239 } 242 }
240 } 243 }
241 i::MaybeHandle<i::JSObject> instance = 244 i::MaybeHandle<i::JSObject> instance =
242 i::wasm::WasmModule::Instantiate(i_isolate, &thrower, i_obj, ffi, memory); 245 i::wasm::WasmModule::Instantiate(i_isolate, &thrower, i_obj, ffi, memory);
243 if (instance.is_null()) { 246 if (instance.is_null()) {
244 if (!thrower.error()) thrower.RuntimeError("Could not instantiate module"); 247 if (!thrower.error()) thrower.RuntimeError("Could not instantiate module");
245 return; 248 return;
246 } 249 }
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
322 } 325 }
323 if (has_maximum.FromJust()) { 326 if (has_maximum.FromJust()) {
324 if (!GetIntegerProperty(isolate, &thrower, context, descriptor, maximum_key, 327 if (!GetIntegerProperty(isolate, &thrower, context, descriptor, maximum_key,
325 &maximum, initial, max_table_size)) { 328 &maximum, initial, max_table_size)) {
326 return; 329 return;
327 } 330 }
328 } 331 }
329 332
330 i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate); 333 i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate);
331 i::Handle<i::FixedArray> fixed_array; 334 i::Handle<i::FixedArray> fixed_array;
332 i::Handle<i::JSObject> table_obj = i::WasmJs::CreateWasmTableObject( 335 i::Handle<i::JSObject> table_obj = i::WasmTableObject::New(
333 i_isolate, initial, has_maximum.FromJust(), maximum, &fixed_array); 336 i_isolate, initial, has_maximum.FromJust(), maximum, &fixed_array);
334 v8::ReturnValue<v8::Value> return_value = args.GetReturnValue(); 337 v8::ReturnValue<v8::Value> return_value = args.GetReturnValue();
335 return_value.Set(Utils::ToLocal(table_obj)); 338 return_value.Set(Utils::ToLocal(table_obj));
336 } 339 }
337 340
338 void WebAssemblyMemory(const v8::FunctionCallbackInfo<v8::Value>& args) { 341 void WebAssemblyMemory(const v8::FunctionCallbackInfo<v8::Value>& args) {
339 v8::Isolate* isolate = args.GetIsolate(); 342 v8::Isolate* isolate = args.GetIsolate();
340 HandleScope scope(isolate); 343 HandleScope scope(isolate);
341 ErrorThrower thrower(reinterpret_cast<i::Isolate*>(isolate), 344 ErrorThrower thrower(reinterpret_cast<i::Isolate*>(isolate),
342 "WebAssembly.Module()"); 345 "WebAssembly.Module()");
(...skipping 24 matching lines...) Expand all
367 return; 370 return;
368 } 371 }
369 } 372 }
370 i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate); 373 i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate);
371 i::Handle<i::JSArrayBuffer> buffer = 374 i::Handle<i::JSArrayBuffer> buffer =
372 i_isolate->factory()->NewJSArrayBuffer(i::SharedFlag::kNotShared); 375 i_isolate->factory()->NewJSArrayBuffer(i::SharedFlag::kNotShared);
373 size_t size = static_cast<size_t>(i::wasm::WasmModule::kPageSize) * 376 size_t size = static_cast<size_t>(i::wasm::WasmModule::kPageSize) *
374 static_cast<size_t>(initial); 377 static_cast<size_t>(initial);
375 i::JSArrayBuffer::SetupAllocatingData(buffer, i_isolate, size); 378 i::JSArrayBuffer::SetupAllocatingData(buffer, i_isolate, size);
376 379
377 i::Handle<i::JSObject> memory_obj = i::WasmJs::CreateWasmMemoryObject( 380 i::Handle<i::JSObject> memory_obj = i::WasmMemoryObject::New(
378 i_isolate, buffer, has_maximum.FromJust(), maximum); 381 i_isolate, buffer, has_maximum.FromJust() ? maximum : -1);
379 v8::ReturnValue<v8::Value> return_value = args.GetReturnValue(); 382 v8::ReturnValue<v8::Value> return_value = args.GetReturnValue();
380 return_value.Set(Utils::ToLocal(memory_obj)); 383 return_value.Set(Utils::ToLocal(memory_obj));
381 } 384 }
382 385
383 void WebAssemblyTableGetLength( 386 void WebAssemblyTableGetLength(
384 const v8::FunctionCallbackInfo<v8::Value>& args) { 387 const v8::FunctionCallbackInfo<v8::Value>& args) {
385 v8::Isolate* isolate = args.GetIsolate(); 388 v8::Isolate* isolate = args.GetIsolate();
386 Local<Context> context = isolate->GetCurrentContext(); 389 Local<Context> context = isolate->GetCurrentContext();
387 i::Handle<i::Context> i_context = Utils::OpenHandle(*context); 390 i::Handle<i::Context> i_context = Utils::OpenHandle(*context);
388 if (!BrandCheck(isolate, Utils::OpenHandle(*args.This()), 391 if (!BrandCheck(isolate, Utils::OpenHandle(*args.This()),
(...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after
595 i::Handle<i::JSObject> receiver = 598 i::Handle<i::JSObject> receiver =
596 i::Handle<i::JSObject>::cast(Utils::OpenHandle(*args.This())); 599 i::Handle<i::JSObject>::cast(Utils::OpenHandle(*args.This()));
597 i::Handle<i::Object> buffer(receiver->GetInternalField(kWasmMemoryBuffer), 600 i::Handle<i::Object> buffer(receiver->GetInternalField(kWasmMemoryBuffer),
598 i_isolate); 601 i_isolate);
599 DCHECK(buffer->IsJSArrayBuffer()); 602 DCHECK(buffer->IsJSArrayBuffer());
600 v8::ReturnValue<v8::Value> return_value = args.GetReturnValue(); 603 v8::ReturnValue<v8::Value> return_value = args.GetReturnValue();
601 return_value.Set(Utils::ToLocal(buffer)); 604 return_value.Set(Utils::ToLocal(buffer));
602 } 605 }
603 } // namespace 606 } // namespace
604 607
605 i::Handle<i::JSObject> i::WasmJs::CreateWasmMemoryObject(
606 i::Isolate* i_isolate, i::Handle<i::JSArrayBuffer> buffer, bool has_maximum,
607 int maximum) {
608 i::Handle<i::JSFunction> memory_ctor(
609 i_isolate->native_context()->wasm_memory_constructor());
610 i::Handle<i::JSObject> memory_obj =
611 i_isolate->factory()->NewJSObject(memory_ctor);
612 memory_obj->SetInternalField(kWasmMemoryBuffer, *buffer);
613 memory_obj->SetInternalField(
614 kWasmMemoryMaximum,
615 has_maximum
616 ? static_cast<i::Object*>(i::Smi::FromInt(maximum))
617 : static_cast<i::Object*>(i_isolate->heap()->undefined_value()));
618 i::Handle<i::Symbol> memory_sym(
619 i_isolate->native_context()->wasm_memory_sym());
620 i::Object::SetProperty(memory_obj, memory_sym, memory_obj, i::STRICT).Check();
621 return memory_obj;
622 }
623
624 i::Handle<i::JSObject> i::WasmJs::CreateWasmTableObject(
625 i::Isolate* i_isolate, uint32_t initial, bool has_maximum, uint32_t maximum,
626 i::Handle<i::FixedArray>* js_functions) {
627 i::Handle<i::JSFunction> table_ctor(
628 i_isolate->native_context()->wasm_table_constructor());
629 i::Handle<i::JSObject> table_obj =
630 i_isolate->factory()->NewJSObject(table_ctor);
631 *js_functions = i_isolate->factory()->NewFixedArray(initial);
632 i::Object* null = i_isolate->heap()->null_value();
633 // TODO(titzer): consider moving FixedArray to size_t.
634 for (int i = 0; i < static_cast<int>(initial); ++i) {
635 (*js_functions)->set(i, null);
636 }
637 table_obj->SetInternalField(kWasmTableArrayFieldIndex, *(*js_functions));
638 table_obj->SetInternalField(
639 kWasmTableMaximumFieldIndex,
640 has_maximum
641 ? static_cast<i::Object*>(i::Smi::FromInt(maximum))
642 : static_cast<i::Object*>(i_isolate->heap()->undefined_value()));
643 Handle<FixedArray> dispatch_tables = i_isolate->factory()->NewFixedArray(0);
644 table_obj->SetInternalField(kWasmTableDispatchTablesFieldIndex,
645 *dispatch_tables);
646 i::Handle<i::Symbol> table_sym(i_isolate->native_context()->wasm_table_sym());
647 i::Object::SetProperty(table_obj, table_sym, table_obj, i::STRICT).Check();
648 return table_obj;
649 }
650
651 i::Handle<i::FixedArray> i::WasmJs::AddWasmTableDispatchTable(
652 i::Isolate* i_isolate, i::Handle<i::JSObject> table_obj,
653 i::Handle<i::JSObject> instance, int table_index,
654 i::Handle<i::FixedArray> dispatch_table) {
655 DCHECK(IsWasmTableObject(i_isolate, table_obj));
656 i::Handle<i::FixedArray> dispatch_tables(
657 i::FixedArray::cast(
658 table_obj->GetInternalField(kWasmTableDispatchTablesFieldIndex)),
659 i_isolate);
660 DCHECK_EQ(0, dispatch_tables->length() % 3);
661
662 if (instance.is_null()) return dispatch_tables;
663 // TODO(titzer): use weak cells here to avoid leaking instances.
664
665 // Grow the dispatch table and add a new pair at the end.
666 i::Handle<i::FixedArray> new_dispatch_tables =
667 i_isolate->factory()->CopyFixedArrayAndGrow(dispatch_tables, 3);
668
669 new_dispatch_tables->set(dispatch_tables->length() + 0, *instance);
670 new_dispatch_tables->set(dispatch_tables->length() + 1,
671 Smi::FromInt(table_index));
672 new_dispatch_tables->set(dispatch_tables->length() + 2, *dispatch_table);
673
674 table_obj->SetInternalField(kWasmTableDispatchTablesFieldIndex,
675 *new_dispatch_tables);
676
677 return new_dispatch_tables;
678 }
679
680 // TODO(titzer): we use the API to create the function template because the 608 // TODO(titzer): we use the API to create the function template because the
681 // internal guts are too ugly to replicate here. 609 // internal guts are too ugly to replicate here.
682 static i::Handle<i::FunctionTemplateInfo> NewTemplate(i::Isolate* i_isolate, 610 static i::Handle<i::FunctionTemplateInfo> NewTemplate(i::Isolate* i_isolate,
683 FunctionCallback func) { 611 FunctionCallback func) {
684 Isolate* isolate = reinterpret_cast<Isolate*>(i_isolate); 612 Isolate* isolate = reinterpret_cast<Isolate*>(i_isolate);
685 Local<FunctionTemplate> local = FunctionTemplate::New(isolate, func); 613 Local<FunctionTemplate> local = FunctionTemplate::New(isolate, func);
686 return v8::Utils::OpenHandle(*local); 614 return v8::Utils::OpenHandle(*local);
687 } 615 }
688 616
689 namespace internal { 617 namespace internal {
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
758 // Setup compile 686 // Setup compile
759 InstallFunc(isolate, webassembly, "validate", WebAssemblyValidate); 687 InstallFunc(isolate, webassembly, "validate", WebAssemblyValidate);
760 688
761 // Setup Module 689 // Setup Module
762 Handle<JSFunction> module_constructor = 690 Handle<JSFunction> module_constructor =
763 InstallFunc(isolate, webassembly, "Module", WebAssemblyModule); 691 InstallFunc(isolate, webassembly, "Module", WebAssemblyModule);
764 context->set_wasm_module_constructor(*module_constructor); 692 context->set_wasm_module_constructor(*module_constructor);
765 Handle<JSObject> module_proto = 693 Handle<JSObject> module_proto =
766 factory->NewJSObject(module_constructor, TENURED); 694 factory->NewJSObject(module_constructor, TENURED);
767 i::Handle<i::Map> map = isolate->factory()->NewMap( 695 i::Handle<i::Map> map = isolate->factory()->NewMap(
768 i::JS_OBJECT_TYPE, i::JSObject::kHeaderSize + i::kPointerSize); 696 i::JS_OBJECT_TYPE, i::JSObject::kHeaderSize +
697 WasmModuleObject::kFieldCount * i::kPointerSize);
769 JSFunction::SetInitialMap(module_constructor, map, module_proto); 698 JSFunction::SetInitialMap(module_constructor, map, module_proto);
770 JSObject::AddProperty(module_proto, isolate->factory()->constructor_string(), 699 JSObject::AddProperty(module_proto, isolate->factory()->constructor_string(),
771 module_constructor, DONT_ENUM); 700 module_constructor, DONT_ENUM);
772 701
773 // Setup Instance 702 // Setup Instance
774 Handle<JSFunction> instance_constructor = 703 Handle<JSFunction> instance_constructor =
775 InstallFunc(isolate, webassembly, "Instance", WebAssemblyInstance); 704 InstallFunc(isolate, webassembly, "Instance", WebAssemblyInstance);
776 context->set_wasm_instance_constructor(*instance_constructor); 705 context->set_wasm_instance_constructor(*instance_constructor);
777 706
778 // Setup Table 707 // Setup Table
779 Handle<JSFunction> table_constructor = 708 Handle<JSFunction> table_constructor =
780 InstallFunc(isolate, webassembly, "Table", WebAssemblyTable); 709 InstallFunc(isolate, webassembly, "Table", WebAssemblyTable);
781 context->set_wasm_table_constructor(*table_constructor); 710 context->set_wasm_table_constructor(*table_constructor);
782 Handle<JSObject> table_proto = 711 Handle<JSObject> table_proto =
783 factory->NewJSObject(table_constructor, TENURED); 712 factory->NewJSObject(table_constructor, TENURED);
784 map = isolate->factory()->NewMap( 713 map = isolate->factory()->NewMap(
785 i::JS_OBJECT_TYPE, i::JSObject::kHeaderSize + 714 i::JS_OBJECT_TYPE, i::JSObject::kHeaderSize +
786 kWasmTableInternalFieldCount * i::kPointerSize); 715 WasmTableObject::kFieldCount * i::kPointerSize);
787 JSFunction::SetInitialMap(table_constructor, map, table_proto); 716 JSFunction::SetInitialMap(table_constructor, map, table_proto);
788 JSObject::AddProperty(table_proto, isolate->factory()->constructor_string(), 717 JSObject::AddProperty(table_proto, isolate->factory()->constructor_string(),
789 table_constructor, DONT_ENUM); 718 table_constructor, DONT_ENUM);
790 InstallGetter(isolate, table_proto, "length", WebAssemblyTableGetLength); 719 InstallGetter(isolate, table_proto, "length", WebAssemblyTableGetLength);
791 InstallFunc(isolate, table_proto, "grow", WebAssemblyTableGrow); 720 InstallFunc(isolate, table_proto, "grow", WebAssemblyTableGrow);
792 InstallFunc(isolate, table_proto, "get", WebAssemblyTableGet); 721 InstallFunc(isolate, table_proto, "get", WebAssemblyTableGet);
793 InstallFunc(isolate, table_proto, "set", WebAssemblyTableSet); 722 InstallFunc(isolate, table_proto, "set", WebAssemblyTableSet);
794 723
795 // Setup Memory 724 // Setup Memory
796 Handle<JSFunction> memory_constructor = 725 Handle<JSFunction> memory_constructor =
797 InstallFunc(isolate, webassembly, "Memory", WebAssemblyMemory); 726 InstallFunc(isolate, webassembly, "Memory", WebAssemblyMemory);
798 context->set_wasm_memory_constructor(*memory_constructor); 727 context->set_wasm_memory_constructor(*memory_constructor);
799 Handle<JSObject> memory_proto = 728 Handle<JSObject> memory_proto =
800 factory->NewJSObject(memory_constructor, TENURED); 729 factory->NewJSObject(memory_constructor, TENURED);
801 map = isolate->factory()->NewMap( 730 map = isolate->factory()->NewMap(
802 i::JS_OBJECT_TYPE, i::JSObject::kHeaderSize + 731 i::JS_OBJECT_TYPE, i::JSObject::kHeaderSize +
803 kWasmMemoryInternalFieldCount * i::kPointerSize); 732 WasmMemoryObject::kFieldCount * i::kPointerSize);
804 JSFunction::SetInitialMap(memory_constructor, map, memory_proto); 733 JSFunction::SetInitialMap(memory_constructor, map, memory_proto);
805 JSObject::AddProperty(memory_proto, isolate->factory()->constructor_string(), 734 JSObject::AddProperty(memory_proto, isolate->factory()->constructor_string(),
806 memory_constructor, DONT_ENUM); 735 memory_constructor, DONT_ENUM);
807 InstallFunc(isolate, memory_proto, "grow", WebAssemblyMemoryGrow); 736 InstallFunc(isolate, memory_proto, "grow", WebAssemblyMemoryGrow);
808 InstallGetter(isolate, memory_proto, "buffer", WebAssemblyMemoryGetBuffer); 737 InstallGetter(isolate, memory_proto, "buffer", WebAssemblyMemoryGetBuffer);
809 738
810 // Setup errors 739 // Setup errors
811 attributes = static_cast<PropertyAttributes>(DONT_DELETE | READ_ONLY); 740 attributes = static_cast<PropertyAttributes>(DONT_DELETE | READ_ONLY);
812 Handle<JSFunction> compile_error( 741 Handle<JSFunction> compile_error(
813 isolate->native_context()->wasm_compile_error_function()); 742 isolate->native_context()->wasm_compile_error_function());
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
884 813
885 Handle<FixedArray> WasmJs::GetWasmTableFunctions(Isolate* isolate, 814 Handle<FixedArray> WasmJs::GetWasmTableFunctions(Isolate* isolate,
886 Handle<JSObject> value) { 815 Handle<JSObject> value) {
887 DCHECK(IsWasmTableObject(isolate, value)); 816 DCHECK(IsWasmTableObject(isolate, value));
888 Handle<Object> arr( 817 Handle<Object> arr(
889 JSObject::cast(*value)->GetInternalField(kWasmTableArrayFieldIndex), 818 JSObject::cast(*value)->GetInternalField(kWasmTableArrayFieldIndex),
890 isolate); 819 isolate);
891 return Handle<FixedArray>::cast(arr); 820 return Handle<FixedArray>::cast(arr);
892 } 821 }
893 822
894 Handle<JSArrayBuffer> WasmJs::GetWasmMemoryArrayBuffer(Isolate* isolate,
895 Handle<Object> value) {
896 DCHECK(IsWasmMemoryObject(isolate, value));
897 Handle<Object> buf(
898 JSObject::cast(*value)->GetInternalField(kWasmMemoryBuffer), isolate);
899 return Handle<JSArrayBuffer>::cast(buf);
900 }
901
902 void WasmJs::SetWasmMemoryArrayBuffer(Isolate* isolate, Handle<Object> value,
903 Handle<JSArrayBuffer> buffer) {
904 DCHECK(IsWasmMemoryObject(isolate, value));
905 JSObject::cast(*value)->SetInternalField(kWasmMemoryBuffer, *buffer);
906 }
907
908 uint32_t WasmJs::GetWasmMemoryMaximumSize(Isolate* isolate,
909 Handle<Object> value) {
910 DCHECK(IsWasmMemoryObject(isolate, value));
911 Object* max_mem =
912 JSObject::cast(*value)->GetInternalField(kWasmMemoryMaximum);
913 if (max_mem->IsUndefined(isolate)) return 0;
914 uint32_t max_pages = Smi::cast(max_mem)->value();
915 return max_pages;
916 }
917
918 void WasmJs::SetWasmMemoryInstance(Isolate* isolate, 823 void WasmJs::SetWasmMemoryInstance(Isolate* isolate,
919 Handle<Object> memory_object, 824 Handle<Object> memory_object,
920 Handle<JSObject> instance) { 825 Handle<JSObject> instance) {
921 if (!memory_object->IsUndefined(isolate)) { 826 if (!memory_object->IsUndefined(isolate)) {
922 DCHECK(IsWasmMemoryObject(isolate, memory_object)); 827 DCHECK(IsWasmMemoryObject(isolate, memory_object));
923 // TODO(gdeepti): This should be a weak list of instance objects 828 // TODO(gdeepti): This should be a weak list of instance objects
924 // for instances that share memory. 829 // for instances that share memory.
925 JSObject::cast(*memory_object) 830 JSObject::cast(*memory_object)
926 ->SetInternalField(kWasmMemoryInstanceObject, *instance); 831 ->SetInternalField(kWasmMemoryInstanceObject, *instance);
927 } 832 }
928 } 833 }
929 } // namespace internal 834 } // namespace internal
930 } // namespace v8 835 } // namespace v8
OLDNEW
« no previous file with comments | « src/wasm/wasm-js.h ('k') | src/wasm/wasm-module.h » ('j') | src/wasm/wasm-module.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698