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

Unified Diff: src/wasm/wasm-js.cc

Issue 2392943006: [wasm] Implement importing of WebAssembly.Memory. (Closed)
Patch Set: 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
Index: src/wasm/wasm-js.cc
diff --git a/src/wasm/wasm-js.cc b/src/wasm/wasm-js.cc
index 254fd7061abf9363a390deec8a8b00d560d5f330..d971e8bebc0456da9d582d34fdd8ca3f4f1e312d 100644
--- a/src/wasm/wasm-js.cc
+++ b/src/wasm/wasm-js.cc
@@ -737,5 +737,22 @@ void WasmJs::InstallWasmMapsIfNeeded(Isolate* isolate,
}
}
+bool WasmJs::IsWasmMemoryObject(Isolate* isolate, Handle<Object> value) {
+ if (value->IsJSObject()) {
+ i::Handle<i::JSObject> object = i::Handle<i::JSObject>::cast(value);
+ i::Handle<i::Symbol> sym(isolate->context()->wasm_memory_sym(), isolate);
+ Maybe<bool> has_brand = i::JSObject::HasOwnProperty(object, sym);
ahaas 2016/10/07 08:23:36 Can sym also be further up the prototype chain? If
titzer 2016/10/07 08:50:52 Definitely don't want to go up the prototype chain
+ if (has_brand.IsNothing()) return false;
+ if (has_brand.ToChecked()) return true;
+ }
+ return false;
+}
+
+Handle<JSArrayBuffer> WasmJs::GetWasmMemoryArrayBuffer(Isolate* isolate,
+ Handle<Object> value) {
+ DCHECK(IsWasmMemoryObject(isolate, value));
+ Handle<Object> buf(JSObject::cast(*value)->GetInternalField(0), isolate);
ahaas 2016/10/07 08:23:36 Could we use a constant for index 0?
titzer 2016/10/07 08:50:52 Done.
+ return Handle<JSArrayBuffer>::cast(buf);
+}
} // namespace internal
} // namespace v8
« no previous file with comments | « src/wasm/wasm-js.h ('k') | src/wasm/wasm-module.cc » ('j') | src/wasm/wasm-module.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698