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

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

Issue 2638243002: [wasm] WebAssembly.Memory.grow() should handle the no instance case (Closed)
Patch Set: Created 3 years, 11 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.h » ('j') | test/mjsunit/wasm/js-api.js » ('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 617 matching lines...) Expand 10 before | Expand all | Expand 10 after
628 628
629 void WebAssemblyMemoryGrow(const v8::FunctionCallbackInfo<v8::Value>& args) { 629 void WebAssemblyMemoryGrow(const v8::FunctionCallbackInfo<v8::Value>& args) {
630 v8::Isolate* isolate = args.GetIsolate(); 630 v8::Isolate* isolate = args.GetIsolate();
631 Local<Context> context = isolate->GetCurrentContext(); 631 Local<Context> context = isolate->GetCurrentContext();
632 i::Handle<i::Context> i_context = Utils::OpenHandle(*context); 632 i::Handle<i::Context> i_context = Utils::OpenHandle(*context);
633 if (!BrandCheck(isolate, Utils::OpenHandle(*args.This()), 633 if (!BrandCheck(isolate, Utils::OpenHandle(*args.This()),
634 i::Handle<i::Symbol>(i_context->wasm_memory_sym()), 634 i::Handle<i::Symbol>(i_context->wasm_memory_sym()),
635 "Receiver is not a WebAssembly.Memory")) { 635 "Receiver is not a WebAssembly.Memory")) {
636 return; 636 return;
637 } 637 }
638 if (args.Length() < 1) { 638 int64_t delta_size = 0;
639 if (args.Length() < 1 || !args[0]->IntegerValue(context).To(&delta_size)) {
639 v8::Local<v8::Value> e = v8::Exception::TypeError( 640 v8::Local<v8::Value> e = v8::Exception::TypeError(
640 v8_str(isolate, "Argument 0 required, must be numeric value of pages")); 641 v8_str(isolate, "Argument 0 required, must be numeric value of pages"));
641 isolate->ThrowException(e); 642 isolate->ThrowException(e);
642 return; 643 return;
643 } 644 }
644 645 i::Handle<i::WasmMemoryObject> receiver =
645 uint32_t delta = args[0]->Uint32Value(context).FromJust(); 646 i::Handle<i::WasmMemoryObject>::cast(Utils::OpenHandle(*args.This()));
647 int64_t max_size64 = receiver->maximum_pages();
648 if (max_size64 < 0 ||
649 max_size64 > static_cast<int64_t>(i::wasm::kV8MaxWasmTableSize)) {
650 max_size64 = i::wasm::kV8MaxWasmMemoryPages;
651 }
652 i::Handle<i::JSArrayBuffer> old_buffer(receiver->buffer());
653 uint32_t old_size =
654 old_buffer->byte_length()->Number() / i::wasm::kSpecMaxWasmMemoryPages;
655 int64_t new_size64 = old_size + delta_size;
656 if (delta_size < 0 || max_size64 < new_size64 || new_size64 < old_size) {
657 v8::Local<v8::Value> e = v8::Exception::RangeError(v8_str(
658 isolate, new_size64 < old_size ? "trying to shrink memory"
659 : "maximum memory size exceeded"));
660 isolate->ThrowException(e);
661 return;
662 }
646 i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate); 663 i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate);
647 i::Handle<i::Object> receiver = 664 int32_t ret = i::wasm::GrowWebAssemblyMemory(
648 i::Handle<i::Object>::cast(Utils::OpenHandle(*args.This())); 665 i_isolate, receiver, static_cast<uint32_t>(delta_size));
649 int32_t ret = i::wasm::GrowWebAssemblyMemory(i_isolate, receiver, delta);
650 if (ret == -1) { 666 if (ret == -1) {
651 v8::Local<v8::Value> e = v8::Exception::Error( 667 v8::Local<v8::Value> e = v8::Exception::RangeError(
652 v8_str(isolate, "Unable to grow instance memory.")); 668 v8_str(isolate, "Unable to grow instance memory."));
653 isolate->ThrowException(e); 669 isolate->ThrowException(e);
654 return; 670 return;
655 } 671 }
656 v8::ReturnValue<v8::Value> return_value = args.GetReturnValue(); 672 v8::ReturnValue<v8::Value> return_value = args.GetReturnValue();
657 return_value.Set(ret); 673 return_value.Set(ret);
658 } 674 }
659 675
660 void WebAssemblyMemoryGetBuffer( 676 void WebAssemblyMemoryGetBuffer(
661 const v8::FunctionCallbackInfo<v8::Value>& args) { 677 const v8::FunctionCallbackInfo<v8::Value>& args) {
(...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after
884 i::Handle<i::Symbol> symbol(isolate->context()->wasm_memory_sym(), isolate); 900 i::Handle<i::Symbol> symbol(isolate->context()->wasm_memory_sym(), isolate);
885 return HasBrand(value, symbol); 901 return HasBrand(value, symbol);
886 } 902 }
887 903
888 bool WasmJs::IsWasmTableObject(Isolate* isolate, Handle<Object> value) { 904 bool WasmJs::IsWasmTableObject(Isolate* isolate, Handle<Object> value) {
889 i::Handle<i::Symbol> symbol(isolate->context()->wasm_table_sym(), isolate); 905 i::Handle<i::Symbol> symbol(isolate->context()->wasm_table_sym(), isolate);
890 return HasBrand(value, symbol); 906 return HasBrand(value, symbol);
891 } 907 }
892 } // namespace internal 908 } // namespace internal
893 } // namespace v8 909 } // namespace v8
OLDNEW
« no previous file with comments | « no previous file | src/wasm/wasm-module.h » ('j') | test/mjsunit/wasm/js-api.js » ('J')

Powered by Google App Engine
This is Rietveld 408576698