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

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

Issue 2512323004: Revert of [wasm] WebAssembly.Memory object can be referenced by multiple Instance objects. (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
« no previous file with comments | « src/runtime/runtime-wasm.cc ('k') | src/wasm/wasm-module.h » ('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/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 10 matching lines...) Expand all
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-objects.h"
23 #include "src/wasm/wasm-result.h" 23 #include "src/wasm/wasm-result.h"
24 24
25 typedef uint8_t byte; 25 typedef uint8_t byte;
26 26
27 using v8::internal::wasm::ErrorThrower; 27 using v8::internal::wasm::ErrorThrower;
28 28
29 namespace v8 { 29 namespace v8 {
30 30
31 enum WasmMemoryObjectData {
32 kWasmMemoryBuffer,
33 kWasmMemoryMaximum,
34 kWasmMemoryInstanceObject
35 };
36
31 namespace { 37 namespace {
32 i::Handle<i::String> v8_str(i::Isolate* isolate, const char* str) { 38 i::Handle<i::String> v8_str(i::Isolate* isolate, const char* str) {
33 return isolate->factory()->NewStringFromAsciiChecked(str); 39 return isolate->factory()->NewStringFromAsciiChecked(str);
34 } 40 }
35 Local<String> v8_str(Isolate* isolate, const char* str) { 41 Local<String> v8_str(Isolate* isolate, const char* str) {
36 return Utils::ToLocal(v8_str(reinterpret_cast<i::Isolate*>(isolate), str)); 42 return Utils::ToLocal(v8_str(reinterpret_cast<i::Isolate*>(isolate), str));
37 } 43 }
38 44
39 struct RawBuffer { 45 struct RawBuffer {
40 const byte* start; 46 const byte* start;
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after
217 i::Handle<i::JSArrayBuffer> memory = i::Handle<i::JSArrayBuffer>::null(); 223 i::Handle<i::JSArrayBuffer> memory = i::Handle<i::JSArrayBuffer>::null();
218 if (args.Length() > 2 && args[2]->IsObject()) { 224 if (args.Length() > 2 && args[2]->IsObject()) {
219 Local<Object> obj = Local<Object>::Cast(args[2]); 225 Local<Object> obj = Local<Object>::Cast(args[2]);
220 i::Handle<i::Object> mem_obj = v8::Utils::OpenHandle(*obj); 226 i::Handle<i::Object> mem_obj = v8::Utils::OpenHandle(*obj);
221 if (i::WasmJs::IsWasmMemoryObject(i_isolate, mem_obj)) { 227 if (i::WasmJs::IsWasmMemoryObject(i_isolate, mem_obj)) {
222 memory = i::Handle<i::JSArrayBuffer>( 228 memory = i::Handle<i::JSArrayBuffer>(
223 i::Handle<i::WasmMemoryObject>::cast(mem_obj)->get_buffer(), 229 i::Handle<i::WasmMemoryObject>::cast(mem_obj)->get_buffer(),
224 i_isolate); 230 i_isolate);
225 } else { 231 } else {
226 thrower.TypeError("Argument 2 must be a WebAssembly.Memory"); 232 thrower.TypeError("Argument 2 must be a WebAssembly.Memory");
227 return;
228 } 233 }
229 } 234 }
230 i::MaybeHandle<i::JSObject> instance = 235 i::MaybeHandle<i::JSObject> instance =
231 i::wasm::WasmModule::Instantiate(i_isolate, &thrower, i_obj, ffi, memory); 236 i::wasm::WasmModule::Instantiate(i_isolate, &thrower, i_obj, ffi, memory);
232 if (instance.is_null()) { 237 if (instance.is_null()) {
233 if (!thrower.error()) thrower.RuntimeError("Could not instantiate module"); 238 if (!thrower.error()) thrower.RuntimeError("Could not instantiate module");
234 return; 239 return;
235 } 240 }
236 DCHECK(!i_isolate->has_pending_exception()); 241 DCHECK(!i_isolate->has_pending_exception());
237 v8::ReturnValue<v8::Value> return_value = args.GetReturnValue(); 242 v8::ReturnValue<v8::Value> return_value = args.GetReturnValue();
(...skipping 280 matching lines...) Expand 10 before | Expand all | Expand 10 after
518 } 523 }
519 if (args.Length() < 1) { 524 if (args.Length() < 1) {
520 v8::Local<v8::Value> e = v8::Exception::TypeError( 525 v8::Local<v8::Value> e = v8::Exception::TypeError(
521 v8_str(isolate, "Argument 0 required, must be numeric value of pages")); 526 v8_str(isolate, "Argument 0 required, must be numeric value of pages"));
522 isolate->ThrowException(e); 527 isolate->ThrowException(e);
523 return; 528 return;
524 } 529 }
525 530
526 uint32_t delta = args[0]->Uint32Value(context).FromJust(); 531 uint32_t delta = args[0]->Uint32Value(context).FromJust();
527 i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate); 532 i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate);
528 i::Handle<i::Object> receiver = 533 i::Handle<i::JSObject> receiver =
529 i::Handle<i::Object>::cast(Utils::OpenHandle(*args.This())); 534 i::Handle<i::JSObject>::cast(Utils::OpenHandle(*args.This()));
530 int32_t ret = i::wasm::GrowWebAssemblyMemory(i_isolate, receiver, delta); 535 i::Handle<i::Object> instance_object(
536 receiver->GetInternalField(kWasmMemoryInstanceObject), i_isolate);
537 i::Handle<i::WasmInstanceObject> instance(
538 i::Handle<i::WasmInstanceObject>::cast(instance_object));
539
540 // TODO(gdeepti) Implement growing memory when shared by different
541 // instances.
542 int32_t ret = internal::wasm::GrowInstanceMemory(i_isolate, instance, delta);
531 if (ret == -1) { 543 if (ret == -1) {
532 v8::Local<v8::Value> e = v8::Exception::Error( 544 v8::Local<v8::Value> e = v8::Exception::Error(
533 v8_str(isolate, "Unable to grow instance memory.")); 545 v8_str(isolate, "Unable to grow instance memory."));
534 isolate->ThrowException(e); 546 isolate->ThrowException(e);
535 return; 547 return;
536 } 548 }
549 i::MaybeHandle<i::JSArrayBuffer> buffer =
550 internal::wasm::GetInstanceMemory(i_isolate, instance);
551 if (buffer.is_null()) {
552 v8::Local<v8::Value> e = v8::Exception::Error(
553 v8_str(isolate, "WebAssembly.Memory buffer object not set."));
554 isolate->ThrowException(e);
555 return;
556 }
557 receiver->SetInternalField(kWasmMemoryBuffer, *buffer.ToHandleChecked());
537 v8::ReturnValue<v8::Value> return_value = args.GetReturnValue(); 558 v8::ReturnValue<v8::Value> return_value = args.GetReturnValue();
538 return_value.Set(ret); 559 return_value.Set(ret);
539 } 560 }
540 561
541 void WebAssemblyMemoryGetBuffer( 562 void WebAssemblyMemoryGetBuffer(
542 const v8::FunctionCallbackInfo<v8::Value>& args) { 563 const v8::FunctionCallbackInfo<v8::Value>& args) {
543 v8::Isolate* isolate = args.GetIsolate(); 564 v8::Isolate* isolate = args.GetIsolate();
544 Local<Context> context = isolate->GetCurrentContext(); 565 Local<Context> context = isolate->GetCurrentContext();
545 i::Handle<i::Context> i_context = Utils::OpenHandle(*context); 566 i::Handle<i::Context> i_context = Utils::OpenHandle(*context);
546 if (!BrandCheck(isolate, Utils::OpenHandle(*args.This()), 567 if (!BrandCheck(isolate, Utils::OpenHandle(*args.This()),
547 i::Handle<i::Symbol>(i_context->wasm_memory_sym()), 568 i::Handle<i::Symbol>(i_context->wasm_memory_sym()),
548 "Receiver is not a WebAssembly.Memory")) { 569 "Receiver is not a WebAssembly.Memory")) {
549 return; 570 return;
550 } 571 }
551 i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate); 572 i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate);
552 i::Handle<i::WasmMemoryObject> receiver = 573 i::Handle<i::JSObject> receiver =
553 i::Handle<i::WasmMemoryObject>::cast(Utils::OpenHandle(*args.This())); 574 i::Handle<i::JSObject>::cast(Utils::OpenHandle(*args.This()));
554 i::Handle<i::Object> buffer(receiver->get_buffer(), i_isolate); 575 i::Handle<i::Object> buffer(receiver->GetInternalField(kWasmMemoryBuffer),
576 i_isolate);
555 DCHECK(buffer->IsJSArrayBuffer()); 577 DCHECK(buffer->IsJSArrayBuffer());
556 v8::ReturnValue<v8::Value> return_value = args.GetReturnValue(); 578 v8::ReturnValue<v8::Value> return_value = args.GetReturnValue();
557 return_value.Set(Utils::ToLocal(buffer)); 579 return_value.Set(Utils::ToLocal(buffer));
558 } 580 }
559 } // namespace 581 } // namespace
560 582
561 // TODO(titzer): we use the API to create the function template because the 583 // TODO(titzer): we use the API to create the function template because the
562 // internal guts are too ugly to replicate here. 584 // internal guts are too ugly to replicate here.
563 static i::Handle<i::FunctionTemplateInfo> NewTemplate(i::Isolate* i_isolate, 585 static i::Handle<i::FunctionTemplateInfo> NewTemplate(i::Isolate* i_isolate,
564 FunctionCallback func) { 586 FunctionCallback func) {
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after
758 i::Handle<i::Symbol> symbol(isolate->context()->wasm_memory_sym(), isolate); 780 i::Handle<i::Symbol> symbol(isolate->context()->wasm_memory_sym(), isolate);
759 return HasBrand(value, symbol); 781 return HasBrand(value, symbol);
760 } 782 }
761 783
762 bool WasmJs::IsWasmTableObject(Isolate* isolate, Handle<Object> value) { 784 bool WasmJs::IsWasmTableObject(Isolate* isolate, Handle<Object> value) {
763 i::Handle<i::Symbol> symbol(isolate->context()->wasm_table_sym(), isolate); 785 i::Handle<i::Symbol> symbol(isolate->context()->wasm_table_sym(), isolate);
764 return HasBrand(value, symbol); 786 return HasBrand(value, symbol);
765 } 787 }
766 } // namespace internal 788 } // namespace internal
767 } // namespace v8 789 } // namespace v8
OLDNEW
« no previous file with comments | « src/runtime/runtime-wasm.cc ('k') | src/wasm/wasm-module.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698