| 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);
|
|
|