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

Unified 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | src/wasm/wasm-module.cc » ('j') | src/wasm/wasm-module.cc » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/wasm/wasm-js.cc
diff --git a/src/wasm/wasm-js.cc b/src/wasm/wasm-js.cc
index 57ee2654f9981e96d4b9a513d09689f5c60f590d..bd71f619fa8fc058c5a411817eaedab51c387234 100644
--- a/src/wasm/wasm-js.cc
+++ b/src/wasm/wasm-js.cc
@@ -496,7 +496,39 @@ void WebAssemblyTableSet(const v8::FunctionCallbackInfo<v8::Value>& args) {
// TODO(rossberg)
}
void WebAssemblyMemoryGrow(const v8::FunctionCallbackInfo<v8::Value>& args) {
- // TODO(rossberg)
+ v8::Isolate* isolate = args.GetIsolate();
+ HandleScope scope(isolate);
+ ErrorThrower thrower(reinterpret_cast<i::Isolate*>(isolate),
+ "WebAssembly.Memory()");
+ if (args.Length() < 1 || !args[0]->IsUint32()) {
+ thrower.RangeError("Argument 0 must be numeric value of pages");
+ return;
+ }
+
+ Local<Context> context = isolate->GetCurrentContext();
+ uint32_t delta = args[0]->Uint32Value(context).FromJust();
+ i::Handle<i::Context> i_context = Utils::OpenHandle(*context);
+ if (!BrandCheck(isolate, Utils::OpenHandle(*args.This()),
+ i::Handle<i::Symbol>(i_context->wasm_memory_sym()),
+ "Receiver is not WebAssembly.Memory")) {
+ return;
+ }
+ i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate);
+ i::Handle<i::JSObject> receiver =
+ i::Handle<i::JSObject>::cast(Utils::OpenHandle(*args.This()));
+ i::Handle<i::Object> instance_object(receiver->GetInternalField(2),
+ i_isolate);
+
+ // TODO(gdeepti) Implement growing memory when shared by different
+ // instances.
+ uint32_t ret = internal::wasm::GrowInstanceMemory(
+ i_isolate, i::Handle<i::JSObject>::cast(instance_object), delta);
+ if (ret == -1) {
+ thrower.Error("Error while growing memory");
+ }
+
+ v8::ReturnValue<v8::Value> return_value = args.GetReturnValue();
+ return_value.Set(ret);
}
void WebAssemblyMemoryGetBuffer(
const v8::FunctionCallbackInfo<v8::Value>& args) {
@@ -658,7 +690,7 @@ void WasmJs::InstallWasmConstructors(Isolate* isolate,
Handle<JSObject> memory_proto =
factory->NewJSObject(memory_constructor, TENURED);
map = isolate->factory()->NewMap(
- i::JS_OBJECT_TYPE, i::JSObject::kHeaderSize + 2 * i::kPointerSize);
+ i::JS_OBJECT_TYPE, i::JSObject::kHeaderSize + 3 * i::kPointerSize);
JSFunction::SetInitialMap(memory_constructor, map, memory_proto);
JSObject::AddProperty(memory_proto, isolate->factory()->constructor_string(),
memory_constructor, DONT_ENUM);
« 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