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

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

Issue 2411963003: Implement Table#length and Table#get (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
« no previous file with comments | « no previous file | test/mjsunit/wasm/table.js » ('j') | no next file with comments »
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 36f286f73cffcd58a940d74e7d06442ed8fe1f92..8c21ac5e45962a77f78f76ae6bcb5a33a6d03ec4 100644
--- a/src/wasm/wasm-js.cc
+++ b/src/wasm/wasm-js.cc
@@ -482,22 +482,117 @@ void WebAssemblyMemory(const v8::FunctionCallbackInfo<v8::Value>& args) {
v8::ReturnValue<v8::Value> return_value = args.GetReturnValue();
return_value.Set(Utils::ToLocal(memory_obj));
}
+
void WebAssemblyTableGetLength(
const v8::FunctionCallbackInfo<v8::Value>& args) {
- // TODO(rossberg)
+ v8::Isolate* isolate = args.GetIsolate();
+ Local<Context> context = isolate->GetCurrentContext();
+ i::Handle<i::Context> i_context = Utils::OpenHandle(*context);
+ if (!BrandCheck(isolate, Utils::OpenHandle(*args.This()),
ahaas 2016/10/13 09:12:58 you call Utils::OpenHandle(*args.This()) twice her
rossberg 2016/10/13 12:02:07 It's just an accessor, so should be fast enough.
+ i::Handle<i::Symbol>(i_context->wasm_table_sym()),
+ "Receiver is not a WebAssembly.Table")) {
+ 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> array(receiver->GetInternalField(0), i_isolate);
ahaas 2016/10/13 09:12:59 Can you use a constant here instead of '0'?
rossberg 2016/10/13 12:02:07 Done (also for some other field indices).
+ int length = i::Handle<i::FixedArray>::cast(array)->length();
+ v8::ReturnValue<v8::Value> return_value = args.GetReturnValue();
+ return_value.Set(v8::Number::New(isolate, length));
}
+
void WebAssemblyTableGrow(const v8::FunctionCallbackInfo<v8::Value>& args) {
- // TODO(rossberg)
+ v8::Isolate* isolate = args.GetIsolate();
+ Local<Context> context = isolate->GetCurrentContext();
+ i::Handle<i::Context> i_context = Utils::OpenHandle(*context);
+ if (!BrandCheck(isolate, Utils::OpenHandle(*args.This()),
+ i::Handle<i::Symbol>(i_context->wasm_table_sym()),
+ "Receiver is not a WebAssembly.Table")) {
+ return;
+ }
+ // TODO(rossberg): grow table and update relevant instances.
+ v8::Local<v8::Value> e =
+ v8::Exception::TypeError(v8_str(isolate, "Table#grow unimplemented"));
+ isolate->ThrowException(e);
}
+
void WebAssemblyTableGet(const v8::FunctionCallbackInfo<v8::Value>& args) {
- // TODO(rossberg)
+ v8::Isolate* isolate = args.GetIsolate();
+ Local<Context> context = isolate->GetCurrentContext();
+ i::Handle<i::Context> i_context = Utils::OpenHandle(*context);
+ if (!BrandCheck(isolate, Utils::OpenHandle(*args.This()),
+ i::Handle<i::Symbol>(i_context->wasm_table_sym()),
+ "Receiver is not a WebAssembly.Table")) {
+ return;
+ }
+ if (args.Length() < 1) {
ahaas 2016/10/13 09:12:58 Does the spec actually say that a TypeError should
rossberg 2016/10/13 12:02:07 Changed.
+ v8::Local<v8::Value> e = v8::Exception::TypeError(
+ v8_str(isolate, "Argument 0 must be an index"));
+ isolate->ThrowException(e);
+ 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> array(receiver->GetInternalField(0), i_isolate);
ahaas 2016/10/13 09:12:58 same here
rossberg 2016/10/13 12:02:07 Done.
+ int i;
+ if (!args[0]->Int32Value(context).To(&i)) return;
+ v8::ReturnValue<v8::Value> return_value = args.GetReturnValue();
+ if (i >= 0 && i < i::Handle<i::FixedArray>::cast(array)->length()) {
+ i::Handle<i::Object> value(
+ i::Handle<i::FixedArray>::cast(array)->get(i), i_isolate);
+ return_value.Set(Utils::ToLocal(value));
+ }
}
+
void WebAssemblyTableSet(const v8::FunctionCallbackInfo<v8::Value>& args) {
- // TODO(rossberg)
+ v8::Isolate* isolate = args.GetIsolate();
+ Local<Context> context = isolate->GetCurrentContext();
+ i::Handle<i::Context> i_context = Utils::OpenHandle(*context);
+ if (!BrandCheck(isolate, Utils::OpenHandle(*args.This()),
+ i::Handle<i::Symbol>(i_context->wasm_table_sym()),
+ "Receiver is not a WebAssembly.Table")) {
+ return;
+ }
+ if (args.Length() < 1) {
ahaas 2016/10/13 09:12:59 This if is not needed, the next if also takes care
rossberg 2016/10/13 12:02:07 Obsolete.
+ v8::Local<v8::Value> e = v8::Exception::TypeError(
+ v8_str(isolate, "Argument 0 must be an index"));
+ isolate->ThrowException(e);
+ return;
+ }
+ if (args.Length() < 2 ||
+ !(args[1]->IsNull() ||
+ (args[1]->IsObject() && v8::Object::Cast(*args[1])->IsCallable()))) {
+ v8::Local<v8::Value> e = v8::Exception::TypeError(
+ v8_str(isolate, "Argument 1 must be a null or a function"));
+ isolate->ThrowException(e);
+ return;
+ }
+
+ // TODO(rossberg): set table element and update relevent instances.
+ v8::Local<v8::Value> e =
+ v8::Exception::TypeError(v8_str(isolate, "Table#set unimplemented"));
+ isolate->ThrowException(e);
}
+
void WebAssemblyMemoryGrow(const v8::FunctionCallbackInfo<v8::Value>& args) {
- // TODO(rossberg)
+ v8::Isolate* isolate = args.GetIsolate();
+ Local<Context> context = isolate->GetCurrentContext();
+ 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 a WebAssembly.Memory")) {
+ return;
+ }
+
+ // TODO(rossberg): grow memory.
+ v8::Local<v8::Value> e =
+ v8::Exception::TypeError(v8_str(isolate, "Memory#grow unimplemented"));
+ isolate->ThrowException(e);
}
+
void WebAssemblyMemoryGetBuffer(
const v8::FunctionCallbackInfo<v8::Value>& args) {
v8::Isolate* isolate = args.GetIsolate();
« no previous file with comments | « no previous file | test/mjsunit/wasm/table.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698