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

Side by Side Diff: src/wasm/wasm-js.cc

Issue 2977543002: [wasm] Allow full u32 range for table maximum in WebAssembly.Table constructor. (Closed)
Patch Set: [wasm] Allow full u32 range for table maximum in WebAssembly.Table constructor. Created 3 years, 5 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 | « src/wasm/module-compiler.cc ('k') | src/wasm/wasm-objects.h » ('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/assert-scope.h" 7 #include "src/assert-scope.h"
8 #include "src/ast/ast.h" 8 #include "src/ast/ast.h"
9 #include "src/execution.h" 9 #include "src/execution.h"
10 #include "src/factory.h" 10 #include "src/factory.h"
(...skipping 454 matching lines...) Expand 10 before | Expand all | Expand 10 after
465 // We'll check for that in WebAssemblyInstantiateImpl. 465 // We'll check for that in WebAssemblyInstantiateImpl.
466 Local<Value> data = args[1]; 466 Local<Value> data = args[1];
467 ASSIGN(Function, instantiate_impl, 467 ASSIGN(Function, instantiate_impl,
468 Function::New(context, instantiator, data)); 468 Function::New(context, instantiator, data));
469 ASSIGN(Promise, result, module_promise->Then(context, instantiate_impl)); 469 ASSIGN(Promise, result, module_promise->Then(context, instantiate_impl));
470 args.GetReturnValue().Set(result); 470 args.GetReturnValue().Set(result);
471 } 471 }
472 472
473 bool GetIntegerProperty(v8::Isolate* isolate, ErrorThrower* thrower, 473 bool GetIntegerProperty(v8::Isolate* isolate, ErrorThrower* thrower,
474 Local<Context> context, Local<v8::Object> object, 474 Local<Context> context, Local<v8::Object> object,
475 Local<String> property, int* result, 475 Local<String> property, int64_t* result,
476 int64_t lower_bound, uint64_t upper_bound) { 476 int64_t lower_bound, uint64_t upper_bound) {
477 v8::MaybeLocal<v8::Value> maybe = object->Get(context, property); 477 v8::MaybeLocal<v8::Value> maybe = object->Get(context, property);
478 v8::Local<v8::Value> value; 478 v8::Local<v8::Value> value;
479 if (maybe.ToLocal(&value)) { 479 if (maybe.ToLocal(&value)) {
480 int64_t number; 480 int64_t number;
481 if (!value->IntegerValue(context).To(&number)) return false; 481 if (!value->IntegerValue(context).To(&number)) return false;
482 if (number < lower_bound) { 482 if (number < lower_bound) {
483 thrower->RangeError("Property value %" PRId64 483 thrower->RangeError("Property value %" PRId64
484 " is below the lower bound %" PRIx64, 484 " is below the lower bound %" PRIx64,
485 number, lower_bound); 485 number, lower_bound);
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
518 v8::Local<v8::String> string; 518 v8::Local<v8::String> string;
519 if (!value->ToString(context).ToLocal(&string)) return; 519 if (!value->ToString(context).ToLocal(&string)) return;
520 bool equal; 520 bool equal;
521 if (!string->Equals(context, v8_str(isolate, "anyfunc")).To(&equal)) return; 521 if (!string->Equals(context, v8_str(isolate, "anyfunc")).To(&equal)) return;
522 if (!equal) { 522 if (!equal) {
523 thrower.TypeError("Descriptor property 'element' must be 'anyfunc'"); 523 thrower.TypeError("Descriptor property 'element' must be 'anyfunc'");
524 return; 524 return;
525 } 525 }
526 } 526 }
527 // The descriptor's 'initial'. 527 // The descriptor's 'initial'.
528 int initial = 0; 528 int64_t initial = 0;
529 if (!GetIntegerProperty(isolate, &thrower, context, descriptor, 529 if (!GetIntegerProperty(isolate, &thrower, context, descriptor,
530 v8_str(isolate, "initial"), &initial, 0, 530 v8_str(isolate, "initial"), &initial, 0,
531 i::FLAG_wasm_max_table_size)) { 531 i::FLAG_wasm_max_table_size)) {
532 return; 532 return;
533 } 533 }
534 // The descriptor's 'maximum'. 534 // The descriptor's 'maximum'.
535 int maximum = -1; 535 int64_t maximum = -1;
536 Local<String> maximum_key = v8_str(isolate, "maximum"); 536 Local<String> maximum_key = v8_str(isolate, "maximum");
537 Maybe<bool> has_maximum = descriptor->Has(context, maximum_key); 537 Maybe<bool> has_maximum = descriptor->Has(context, maximum_key);
538 538
539 if (!has_maximum.IsNothing() && has_maximum.FromJust()) { 539 if (!has_maximum.IsNothing() && has_maximum.FromJust()) {
540 if (!GetIntegerProperty(isolate, &thrower, context, descriptor, maximum_key, 540 if (!GetIntegerProperty(isolate, &thrower, context, descriptor, maximum_key,
541 &maximum, initial, 541 &maximum, initial,
542 i::wasm::kSpecMaxWasmTableSize)) { 542 i::wasm::kSpecMaxWasmTableSize)) {
543 return; 543 return;
544 } 544 }
545 } 545 }
546 546
547 i::Handle<i::FixedArray> fixed_array; 547 i::Handle<i::FixedArray> fixed_array;
548 i::Handle<i::JSObject> table_obj = 548 i::Handle<i::JSObject> table_obj = i::WasmTableObject::New(
549 i::WasmTableObject::New(i_isolate, initial, maximum, &fixed_array); 549 i_isolate, static_cast<uint32_t>(initial), maximum, &fixed_array);
550 v8::ReturnValue<v8::Value> return_value = args.GetReturnValue(); 550 v8::ReturnValue<v8::Value> return_value = args.GetReturnValue();
551 return_value.Set(Utils::ToLocal(table_obj)); 551 return_value.Set(Utils::ToLocal(table_obj));
552 } 552 }
553 553
554 void WebAssemblyMemory(const v8::FunctionCallbackInfo<v8::Value>& args) { 554 void WebAssemblyMemory(const v8::FunctionCallbackInfo<v8::Value>& args) {
555 v8::Isolate* isolate = args.GetIsolate(); 555 v8::Isolate* isolate = args.GetIsolate();
556 i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate); 556 i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate);
557 HandleScope scope(isolate); 557 HandleScope scope(isolate);
558 ScheduledErrorThrower thrower(i_isolate, "WebAssembly.Memory()"); 558 ScheduledErrorThrower thrower(i_isolate, "WebAssembly.Memory()");
559 if (args.Length() < 1 || !args[0]->IsObject()) { 559 if (args.Length() < 1 || !args[0]->IsObject()) {
560 thrower.TypeError("Argument 0 must be a memory descriptor"); 560 thrower.TypeError("Argument 0 must be a memory descriptor");
561 return; 561 return;
562 } 562 }
563 Local<Context> context = isolate->GetCurrentContext(); 563 Local<Context> context = isolate->GetCurrentContext();
564 Local<v8::Object> descriptor = args[0]->ToObject(context).ToLocalChecked(); 564 Local<v8::Object> descriptor = args[0]->ToObject(context).ToLocalChecked();
565 // The descriptor's 'initial'. 565 // The descriptor's 'initial'.
566 int initial = 0; 566 int64_t initial = 0;
567 if (!GetIntegerProperty(isolate, &thrower, context, descriptor, 567 if (!GetIntegerProperty(isolate, &thrower, context, descriptor,
568 v8_str(isolate, "initial"), &initial, 0, 568 v8_str(isolate, "initial"), &initial, 0,
569 i::FLAG_wasm_max_mem_pages)) { 569 i::FLAG_wasm_max_mem_pages)) {
570 return; 570 return;
571 } 571 }
572 // The descriptor's 'maximum'. 572 // The descriptor's 'maximum'.
573 int maximum = -1; 573 int64_t maximum = -1;
574 Local<String> maximum_key = v8_str(isolate, "maximum"); 574 Local<String> maximum_key = v8_str(isolate, "maximum");
575 Maybe<bool> has_maximum = descriptor->Has(context, maximum_key); 575 Maybe<bool> has_maximum = descriptor->Has(context, maximum_key);
576 576
577 if (!has_maximum.IsNothing() && has_maximum.FromJust()) { 577 if (!has_maximum.IsNothing() && has_maximum.FromJust()) {
578 if (!GetIntegerProperty(isolate, &thrower, context, descriptor, maximum_key, 578 if (!GetIntegerProperty(isolate, &thrower, context, descriptor, maximum_key,
579 &maximum, initial, 579 &maximum, initial,
580 i::wasm::kSpecMaxWasmMemoryPages)) { 580 i::wasm::kSpecMaxWasmMemoryPages)) {
581 return; 581 return;
582 } 582 }
583 } 583 }
584 size_t size = static_cast<size_t>(i::wasm::WasmModule::kPageSize) * 584 size_t size = static_cast<size_t>(i::wasm::WasmModule::kPageSize) *
585 static_cast<size_t>(initial); 585 static_cast<size_t>(initial);
586 i::Handle<i::JSArrayBuffer> buffer = 586 i::Handle<i::JSArrayBuffer> buffer =
587 i::wasm::NewArrayBuffer(i_isolate, size, i::FLAG_wasm_guard_pages); 587 i::wasm::NewArrayBuffer(i_isolate, size, i::FLAG_wasm_guard_pages);
588 if (buffer.is_null()) { 588 if (buffer.is_null()) {
589 thrower.RangeError("could not allocate memory"); 589 thrower.RangeError("could not allocate memory");
590 return; 590 return;
591 } 591 }
592 i::Handle<i::JSObject> memory_obj = 592 i::Handle<i::JSObject> memory_obj = i::WasmMemoryObject::New(
593 i::WasmMemoryObject::New(i_isolate, buffer, maximum); 593 i_isolate, buffer, static_cast<int32_t>(maximum));
594 args.GetReturnValue().Set(Utils::ToLocal(memory_obj)); 594 args.GetReturnValue().Set(Utils::ToLocal(memory_obj));
595 } 595 }
596 596
597 #define NAME_OF_WasmMemoryObject "WebAssembly.Memory" 597 #define NAME_OF_WasmMemoryObject "WebAssembly.Memory"
598 #define NAME_OF_WasmModuleObject "WebAssembly.Module" 598 #define NAME_OF_WasmModuleObject "WebAssembly.Module"
599 #define NAME_OF_WasmInstanceObject "WebAssembly.Instance" 599 #define NAME_OF_WasmInstanceObject "WebAssembly.Instance"
600 #define NAME_OF_WasmTableObject "WebAssembly.Table" 600 #define NAME_OF_WasmTableObject "WebAssembly.Table"
601 601
602 #define EXTRACT_THIS(var, WasmType) \ 602 #define EXTRACT_THIS(var, WasmType) \
603 i::Handle<i::WasmType> var; \ 603 i::Handle<i::WasmType> var; \
(...skipping 27 matching lines...) Expand all
631 EXTRACT_THIS(receiver, WasmTableObject); 631 EXTRACT_THIS(receiver, WasmTableObject);
632 632
633 i::Handle<i::FixedArray> old_array(receiver->functions(), i_isolate); 633 i::Handle<i::FixedArray> old_array(receiver->functions(), i_isolate);
634 int old_size = old_array->length(); 634 int old_size = old_array->length();
635 int64_t new_size64 = 0; 635 int64_t new_size64 = 0;
636 if (args.Length() > 0 && !args[0]->IntegerValue(context).To(&new_size64)) { 636 if (args.Length() > 0 && !args[0]->IntegerValue(context).To(&new_size64)) {
637 return; 637 return;
638 } 638 }
639 new_size64 += old_size; 639 new_size64 += old_size;
640 640
641 int64_t max_size64 = receiver->maximum_length(); 641 int64_t max_size64 = receiver->maximum_length()->Number();
642 if (max_size64 < 0 || 642 if (max_size64 < 0 || max_size64 > i::FLAG_wasm_max_table_size) {
643 max_size64 > static_cast<int64_t>(i::FLAG_wasm_max_table_size)) {
644 max_size64 = i::FLAG_wasm_max_table_size; 643 max_size64 = i::FLAG_wasm_max_table_size;
645 } 644 }
646 645
647 if (new_size64 < old_size || new_size64 > max_size64) { 646 if (new_size64 < old_size || new_size64 > max_size64) {
648 thrower.RangeError(new_size64 < old_size ? "trying to shrink table" 647 thrower.RangeError(new_size64 < old_size ? "trying to shrink table"
649 : "maximum table size exceeded"); 648 : "maximum table size exceeded");
650 return; 649 return;
651 } 650 }
652 651
653 int new_size = static_cast<int>(new_size64); 652 int new_size = static_cast<int>(new_size64);
(...skipping 298 matching lines...) Expand 10 before | Expand all | Expand 10 after
952 isolate->native_context()->wasm_link_error_function()); 951 isolate->native_context()->wasm_link_error_function());
953 JSObject::AddProperty(webassembly, isolate->factory()->LinkError_string(), 952 JSObject::AddProperty(webassembly, isolate->factory()->LinkError_string(),
954 link_error, attributes); 953 link_error, attributes);
955 Handle<JSFunction> runtime_error( 954 Handle<JSFunction> runtime_error(
956 isolate->native_context()->wasm_runtime_error_function()); 955 isolate->native_context()->wasm_runtime_error_function());
957 JSObject::AddProperty(webassembly, isolate->factory()->RuntimeError_string(), 956 JSObject::AddProperty(webassembly, isolate->factory()->RuntimeError_string(),
958 runtime_error, attributes); 957 runtime_error, attributes);
959 } 958 }
960 } // namespace internal 959 } // namespace internal
961 } // namespace v8 960 } // namespace v8
OLDNEW
« no previous file with comments | « src/wasm/module-compiler.cc ('k') | src/wasm/wasm-objects.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698