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

Side by Side 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 unified diff | Download patch
« no previous file with comments | « no previous file | test/mjsunit/wasm/table.js » ('j') | no next file with comments »
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 464 matching lines...) Expand 10 before | Expand all | Expand 10 after
475 i_isolate->factory()->NewJSArrayBuffer(i::SharedFlag::kNotShared); 475 i_isolate->factory()->NewJSArrayBuffer(i::SharedFlag::kNotShared);
476 size_t size = static_cast<size_t>(i::wasm::WasmModule::kPageSize) * 476 size_t size = static_cast<size_t>(i::wasm::WasmModule::kPageSize) *
477 static_cast<size_t>(initial); 477 static_cast<size_t>(initial);
478 i::JSArrayBuffer::SetupAllocatingData(buffer, i_isolate, size); 478 i::JSArrayBuffer::SetupAllocatingData(buffer, i_isolate, size);
479 479
480 i::Handle<i::JSObject> memory_obj = i::WasmJs::CreateWasmMemoryObject( 480 i::Handle<i::JSObject> memory_obj = i::WasmJs::CreateWasmMemoryObject(
481 i_isolate, buffer, has_maximum.FromJust(), maximum); 481 i_isolate, buffer, has_maximum.FromJust(), maximum);
482 v8::ReturnValue<v8::Value> return_value = args.GetReturnValue(); 482 v8::ReturnValue<v8::Value> return_value = args.GetReturnValue();
483 return_value.Set(Utils::ToLocal(memory_obj)); 483 return_value.Set(Utils::ToLocal(memory_obj));
484 } 484 }
485
485 void WebAssemblyTableGetLength( 486 void WebAssemblyTableGetLength(
486 const v8::FunctionCallbackInfo<v8::Value>& args) { 487 const v8::FunctionCallbackInfo<v8::Value>& args) {
487 // TODO(rossberg) 488 v8::Isolate* isolate = args.GetIsolate();
489 Local<Context> context = isolate->GetCurrentContext();
490 i::Handle<i::Context> i_context = Utils::OpenHandle(*context);
491 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.
492 i::Handle<i::Symbol>(i_context->wasm_table_sym()),
493 "Receiver is not a WebAssembly.Table")) {
494 return;
495 }
496 i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate);
497 i::Handle<i::JSObject> receiver =
498 i::Handle<i::JSObject>::cast(Utils::OpenHandle(*args.This()));
499 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).
500 int length = i::Handle<i::FixedArray>::cast(array)->length();
501 v8::ReturnValue<v8::Value> return_value = args.GetReturnValue();
502 return_value.Set(v8::Number::New(isolate, length));
488 } 503 }
504
489 void WebAssemblyTableGrow(const v8::FunctionCallbackInfo<v8::Value>& args) { 505 void WebAssemblyTableGrow(const v8::FunctionCallbackInfo<v8::Value>& args) {
490 // TODO(rossberg) 506 v8::Isolate* isolate = args.GetIsolate();
507 Local<Context> context = isolate->GetCurrentContext();
508 i::Handle<i::Context> i_context = Utils::OpenHandle(*context);
509 if (!BrandCheck(isolate, Utils::OpenHandle(*args.This()),
510 i::Handle<i::Symbol>(i_context->wasm_table_sym()),
511 "Receiver is not a WebAssembly.Table")) {
512 return;
513 }
514 // TODO(rossberg): grow table and update relevant instances.
515 v8::Local<v8::Value> e =
516 v8::Exception::TypeError(v8_str(isolate, "Table#grow unimplemented"));
517 isolate->ThrowException(e);
491 } 518 }
519
492 void WebAssemblyTableGet(const v8::FunctionCallbackInfo<v8::Value>& args) { 520 void WebAssemblyTableGet(const v8::FunctionCallbackInfo<v8::Value>& args) {
493 // TODO(rossberg) 521 v8::Isolate* isolate = args.GetIsolate();
522 Local<Context> context = isolate->GetCurrentContext();
523 i::Handle<i::Context> i_context = Utils::OpenHandle(*context);
524 if (!BrandCheck(isolate, Utils::OpenHandle(*args.This()),
525 i::Handle<i::Symbol>(i_context->wasm_table_sym()),
526 "Receiver is not a WebAssembly.Table")) {
527 return;
528 }
529 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.
530 v8::Local<v8::Value> e = v8::Exception::TypeError(
531 v8_str(isolate, "Argument 0 must be an index"));
532 isolate->ThrowException(e);
533 return;
534 }
535
536 i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate);
537 i::Handle<i::JSObject> receiver =
538 i::Handle<i::JSObject>::cast(Utils::OpenHandle(*args.This()));
539 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.
540 int i;
541 if (!args[0]->Int32Value(context).To(&i)) return;
542 v8::ReturnValue<v8::Value> return_value = args.GetReturnValue();
543 if (i >= 0 && i < i::Handle<i::FixedArray>::cast(array)->length()) {
544 i::Handle<i::Object> value(
545 i::Handle<i::FixedArray>::cast(array)->get(i), i_isolate);
546 return_value.Set(Utils::ToLocal(value));
547 }
494 } 548 }
549
495 void WebAssemblyTableSet(const v8::FunctionCallbackInfo<v8::Value>& args) { 550 void WebAssemblyTableSet(const v8::FunctionCallbackInfo<v8::Value>& args) {
496 // TODO(rossberg) 551 v8::Isolate* isolate = args.GetIsolate();
552 Local<Context> context = isolate->GetCurrentContext();
553 i::Handle<i::Context> i_context = Utils::OpenHandle(*context);
554 if (!BrandCheck(isolate, Utils::OpenHandle(*args.This()),
555 i::Handle<i::Symbol>(i_context->wasm_table_sym()),
556 "Receiver is not a WebAssembly.Table")) {
557 return;
558 }
559 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.
560 v8::Local<v8::Value> e = v8::Exception::TypeError(
561 v8_str(isolate, "Argument 0 must be an index"));
562 isolate->ThrowException(e);
563 return;
564 }
565 if (args.Length() < 2 ||
566 !(args[1]->IsNull() ||
567 (args[1]->IsObject() && v8::Object::Cast(*args[1])->IsCallable()))) {
568 v8::Local<v8::Value> e = v8::Exception::TypeError(
569 v8_str(isolate, "Argument 1 must be a null or a function"));
570 isolate->ThrowException(e);
571 return;
572 }
573
574 // TODO(rossberg): set table element and update relevent instances.
575 v8::Local<v8::Value> e =
576 v8::Exception::TypeError(v8_str(isolate, "Table#set unimplemented"));
577 isolate->ThrowException(e);
497 } 578 }
579
498 void WebAssemblyMemoryGrow(const v8::FunctionCallbackInfo<v8::Value>& args) { 580 void WebAssemblyMemoryGrow(const v8::FunctionCallbackInfo<v8::Value>& args) {
499 // TODO(rossberg) 581 v8::Isolate* isolate = args.GetIsolate();
582 Local<Context> context = isolate->GetCurrentContext();
583 i::Handle<i::Context> i_context = Utils::OpenHandle(*context);
584 if (!BrandCheck(isolate, Utils::OpenHandle(*args.This()),
585 i::Handle<i::Symbol>(i_context->wasm_memory_sym()),
586 "Receiver is not a WebAssembly.Memory")) {
587 return;
588 }
589
590 // TODO(rossberg): grow memory.
591 v8::Local<v8::Value> e =
592 v8::Exception::TypeError(v8_str(isolate, "Memory#grow unimplemented"));
593 isolate->ThrowException(e);
500 } 594 }
595
501 void WebAssemblyMemoryGetBuffer( 596 void WebAssemblyMemoryGetBuffer(
502 const v8::FunctionCallbackInfo<v8::Value>& args) { 597 const v8::FunctionCallbackInfo<v8::Value>& args) {
503 v8::Isolate* isolate = args.GetIsolate(); 598 v8::Isolate* isolate = args.GetIsolate();
504 Local<Context> context = isolate->GetCurrentContext(); 599 Local<Context> context = isolate->GetCurrentContext();
505 i::Handle<i::Context> i_context = Utils::OpenHandle(*context); 600 i::Handle<i::Context> i_context = Utils::OpenHandle(*context);
506 if (!BrandCheck(isolate, Utils::OpenHandle(*args.This()), 601 if (!BrandCheck(isolate, Utils::OpenHandle(*args.This()),
507 i::Handle<i::Symbol>(i_context->wasm_memory_sym()), 602 i::Handle<i::Symbol>(i_context->wasm_memory_sym()),
508 "Receiver is not a WebAssembly.Memory")) { 603 "Receiver is not a WebAssembly.Memory")) {
509 return; 604 return;
510 } 605 }
(...skipping 243 matching lines...) Expand 10 before | Expand all | Expand 10 after
754 Handle<JSArrayBuffer> WasmJs::GetWasmMemoryArrayBuffer(Isolate* isolate, 849 Handle<JSArrayBuffer> WasmJs::GetWasmMemoryArrayBuffer(Isolate* isolate,
755 Handle<Object> value) { 850 Handle<Object> value) {
756 DCHECK(IsWasmMemoryObject(isolate, value)); 851 DCHECK(IsWasmMemoryObject(isolate, value));
757 Handle<Object> buf( 852 Handle<Object> buf(
758 JSObject::cast(*value)->GetInternalField(kWasmMemoryBufferFieldIndex), 853 JSObject::cast(*value)->GetInternalField(kWasmMemoryBufferFieldIndex),
759 isolate); 854 isolate);
760 return Handle<JSArrayBuffer>::cast(buf); 855 return Handle<JSArrayBuffer>::cast(buf);
761 } 856 }
762 } // namespace internal 857 } // namespace internal
763 } // namespace v8 858 } // namespace v8
OLDNEW
« 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