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

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

Issue 2410763002: [wasm] GrowMemory should use maximum size declared in WebAssembly.Memory (Closed)
Patch Set: Separate refactoring, add test Created 4 years, 2 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 | « no previous file | src/wasm/wasm-module.cc » ('j') | src/wasm/wasm-module.cc » ('J')
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 478 matching lines...) Expand 10 before | Expand all | Expand 10 after
489 void WebAssemblyTableGrow(const v8::FunctionCallbackInfo<v8::Value>& args) { 489 void WebAssemblyTableGrow(const v8::FunctionCallbackInfo<v8::Value>& args) {
490 // TODO(rossberg) 490 // TODO(rossberg)
491 } 491 }
492 void WebAssemblyTableGet(const v8::FunctionCallbackInfo<v8::Value>& args) { 492 void WebAssemblyTableGet(const v8::FunctionCallbackInfo<v8::Value>& args) {
493 // TODO(rossberg) 493 // TODO(rossberg)
494 } 494 }
495 void WebAssemblyTableSet(const v8::FunctionCallbackInfo<v8::Value>& args) { 495 void WebAssemblyTableSet(const v8::FunctionCallbackInfo<v8::Value>& args) {
496 // TODO(rossberg) 496 // TODO(rossberg)
497 } 497 }
498 void WebAssemblyMemoryGrow(const v8::FunctionCallbackInfo<v8::Value>& args) { 498 void WebAssemblyMemoryGrow(const v8::FunctionCallbackInfo<v8::Value>& args) {
499 // TODO(rossberg) 499 v8::Isolate* isolate = args.GetIsolate();
500 HandleScope scope(isolate);
501 ErrorThrower thrower(reinterpret_cast<i::Isolate*>(isolate),
502 "WebAssembly.Memory()");
503 if (args.Length() < 1 || !args[0]->IsUint32()) {
504 thrower.RangeError("Argument 0 must be numeric value of pages");
505 return;
506 }
507
508 Local<Context> context = isolate->GetCurrentContext();
509 uint32_t delta = args[0]->Uint32Value(context).FromJust();
510 i::Handle<i::Context> i_context = Utils::OpenHandle(*context);
511 if (!BrandCheck(isolate, Utils::OpenHandle(*args.This()),
512 i::Handle<i::Symbol>(i_context->wasm_memory_sym()),
513 "Receiver is not WebAssembly.Memory")) {
514 return;
515 }
516 i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate);
517 i::Handle<i::JSObject> receiver =
518 i::Handle<i::JSObject>::cast(Utils::OpenHandle(*args.This()));
519 i::Handle<i::Object> instance_object(receiver->GetInternalField(2),
520 i_isolate);
521
522 // TODO(gdeepti) Implement growing memory when shared by different
523 // instances.
524 uint32_t ret = internal::wasm::GrowInstanceMemory(
525 i_isolate, i::Handle<i::JSObject>::cast(instance_object), delta);
526 if (ret == -1) {
527 thrower.Error("Error while growing memory");
528 }
529
530 v8::ReturnValue<v8::Value> return_value = args.GetReturnValue();
531 return_value.Set(ret);
500 } 532 }
501 void WebAssemblyMemoryGetBuffer( 533 void WebAssemblyMemoryGetBuffer(
502 const v8::FunctionCallbackInfo<v8::Value>& args) { 534 const v8::FunctionCallbackInfo<v8::Value>& args) {
503 v8::Isolate* isolate = args.GetIsolate(); 535 v8::Isolate* isolate = args.GetIsolate();
504 Local<Context> context = isolate->GetCurrentContext(); 536 Local<Context> context = isolate->GetCurrentContext();
505 i::Handle<i::Context> i_context = Utils::OpenHandle(*context); 537 i::Handle<i::Context> i_context = Utils::OpenHandle(*context);
506 if (!BrandCheck(isolate, Utils::OpenHandle(*args.This()), 538 if (!BrandCheck(isolate, Utils::OpenHandle(*args.This()),
507 i::Handle<i::Symbol>(i_context->wasm_memory_sym()), 539 i::Handle<i::Symbol>(i_context->wasm_memory_sym()),
508 "Receiver is not a WebAssembly.Memory")) { 540 "Receiver is not a WebAssembly.Memory")) {
509 return; 541 return;
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after
651 InstallFunc(isolate, table_proto, "get", WebAssemblyTableGet); 683 InstallFunc(isolate, table_proto, "get", WebAssemblyTableGet);
652 InstallFunc(isolate, table_proto, "set", WebAssemblyTableSet); 684 InstallFunc(isolate, table_proto, "set", WebAssemblyTableSet);
653 685
654 // Setup Memory 686 // Setup Memory
655 Handle<JSFunction> memory_constructor = 687 Handle<JSFunction> memory_constructor =
656 InstallFunc(isolate, wasm_object, "Memory", WebAssemblyMemory); 688 InstallFunc(isolate, wasm_object, "Memory", WebAssemblyMemory);
657 context->set_wasm_memory_constructor(*memory_constructor); 689 context->set_wasm_memory_constructor(*memory_constructor);
658 Handle<JSObject> memory_proto = 690 Handle<JSObject> memory_proto =
659 factory->NewJSObject(memory_constructor, TENURED); 691 factory->NewJSObject(memory_constructor, TENURED);
660 map = isolate->factory()->NewMap( 692 map = isolate->factory()->NewMap(
661 i::JS_OBJECT_TYPE, i::JSObject::kHeaderSize + 2 * i::kPointerSize); 693 i::JS_OBJECT_TYPE, i::JSObject::kHeaderSize + 3 * i::kPointerSize);
662 JSFunction::SetInitialMap(memory_constructor, map, memory_proto); 694 JSFunction::SetInitialMap(memory_constructor, map, memory_proto);
663 JSObject::AddProperty(memory_proto, isolate->factory()->constructor_string(), 695 JSObject::AddProperty(memory_proto, isolate->factory()->constructor_string(),
664 memory_constructor, DONT_ENUM); 696 memory_constructor, DONT_ENUM);
665 InstallFunc(isolate, memory_proto, "grow", WebAssemblyMemoryGrow); 697 InstallFunc(isolate, memory_proto, "grow", WebAssemblyMemoryGrow);
666 InstallGetter(isolate, memory_proto, "buffer", WebAssemblyMemoryGetBuffer); 698 InstallGetter(isolate, memory_proto, "buffer", WebAssemblyMemoryGetBuffer);
667 } 699 }
668 700
669 void WasmJs::Install(Isolate* isolate, Handle<JSGlobalObject> global) { 701 void WasmJs::Install(Isolate* isolate, Handle<JSGlobalObject> global) {
670 if (!FLAG_expose_wasm && !FLAG_validate_asm) { 702 if (!FLAG_expose_wasm && !FLAG_validate_asm) {
671 return; 703 return;
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
754 Handle<JSArrayBuffer> WasmJs::GetWasmMemoryArrayBuffer(Isolate* isolate, 786 Handle<JSArrayBuffer> WasmJs::GetWasmMemoryArrayBuffer(Isolate* isolate,
755 Handle<Object> value) { 787 Handle<Object> value) {
756 DCHECK(IsWasmMemoryObject(isolate, value)); 788 DCHECK(IsWasmMemoryObject(isolate, value));
757 Handle<Object> buf( 789 Handle<Object> buf(
758 JSObject::cast(*value)->GetInternalField(kWasmMemoryBufferFieldIndex), 790 JSObject::cast(*value)->GetInternalField(kWasmMemoryBufferFieldIndex),
759 isolate); 791 isolate);
760 return Handle<JSArrayBuffer>::cast(buf); 792 return Handle<JSArrayBuffer>::cast(buf);
761 } 793 }
762 } // namespace internal 794 } // namespace internal
763 } // namespace v8 795 } // namespace v8
OLDNEW
« no previous file with comments | « no previous file | src/wasm/wasm-module.cc » ('j') | src/wasm/wasm-module.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698