@@ -354,22 +354,22 @@ void WebAssemblyInstantiate(const v8::FunctionCallbackInfo<v8::Value>& args) {
354354
355355bool GetIntegerProperty (v8::Isolate* isolate, ErrorThrower* thrower,
356356 Local<Context> context, Local<v8::Object> object,
357- Local<String> property, int * result, int lower_bound,
358- int upper_bound) {
357+ Local<String> property, int * result,
358+ int64_t lower_bound, uint64_t upper_bound) {
359359 v8::MaybeLocal<v8::Value> maybe = object->Get (context, property);
360360 v8::Local<v8::Value> value;
361361 if (maybe.ToLocal (&value)) {
362362 int64_t number;
363363 if (!value->IntegerValue (context).To (&number)) return false ;
364- if (number < static_cast < int64_t >( lower_bound) ) {
364+ if (number < lower_bound) {
365365 thrower->RangeError (" Property value %" PRId64
366- " is below the lower bound %d " ,
366+ " is below the lower bound %" PRIx64 ,
367367 number, lower_bound);
368368 return false ;
369369 }
370370 if (number > static_cast <int64_t >(upper_bound)) {
371371 thrower->RangeError (" Property value %" PRId64
372- " is above the upper bound %d " ,
372+ " is above the upper bound %" PRIu64 ,
373373 number, upper_bound);
374374 return false ;
375375 }
@@ -379,8 +379,6 @@ bool GetIntegerProperty(v8::Isolate* isolate, ErrorThrower* thrower,
379379 return false ;
380380}
381381
382- const int max_table_size = 1 << 26 ;
383-
384382void WebAssemblyTable (const v8::FunctionCallbackInfo<v8::Value>& args) {
385383 v8::Isolate* isolate = args.GetIsolate ();
386384 HandleScope scope (isolate);
@@ -408,28 +406,23 @@ void WebAssemblyTable(const v8::FunctionCallbackInfo<v8::Value>& args) {
408406 }
409407 }
410408 // The descriptor's 'initial'.
411- int initial;
409+ int initial = 0 ;
412410 if (!GetIntegerProperty (isolate, &thrower, context, descriptor,
413411 v8_str (isolate, " initial" ), &initial, 0 ,
414- max_table_size )) {
412+ i::wasm:: kV8MaxWasmTableSize )) {
415413 return ;
416414 }
417415 // The descriptor's 'maximum'.
418- int maximum = 0 ;
416+ int maximum = - 1 ;
419417 Local<String> maximum_key = v8_str (isolate, " maximum" );
420418 Maybe<bool > has_maximum = descriptor->Has (context, maximum_key);
421419
422- if (has_maximum.IsNothing ()) {
423- // There has been an exception, just return.
424- return ;
425- }
426- if (has_maximum.FromJust ()) {
420+ if (!has_maximum.IsNothing () && has_maximum.FromJust ()) {
427421 if (!GetIntegerProperty (isolate, &thrower, context, descriptor, maximum_key,
428- &maximum, initial, max_table_size)) {
422+ &maximum, initial,
423+ i::wasm::kSpecMaxWasmTableSize )) {
429424 return ;
430425 }
431- } else {
432- maximum = static_cast <int >(i::wasm::kV8MaxWasmTableSize );
433426 }
434427
435428 i::Isolate* i_isolate = reinterpret_cast <i::Isolate*>(isolate);
@@ -452,23 +445,21 @@ void WebAssemblyMemory(const v8::FunctionCallbackInfo<v8::Value>& args) {
452445 Local<Context> context = isolate->GetCurrentContext ();
453446 Local<v8::Object> descriptor = args[0 ]->ToObject (context).ToLocalChecked ();
454447 // The descriptor's 'initial'.
455- int initial;
448+ int initial = 0 ;
456449 if (!GetIntegerProperty (isolate, &thrower, context, descriptor,
457- v8_str (isolate, " initial" ), &initial, 0 , 65536 )) {
450+ v8_str (isolate, " initial" ), &initial, 0 ,
451+ i::wasm::kV8MaxWasmMemoryPages )) {
458452 return ;
459453 }
460454 // The descriptor's 'maximum'.
461- int maximum = 0 ;
455+ int maximum = - 1 ;
462456 Local<String> maximum_key = v8_str (isolate, " maximum" );
463457 Maybe<bool > has_maximum = descriptor->Has (context, maximum_key);
464458
465- if (has_maximum.IsNothing ()) {
466- // There has been an exception, just return.
467- return ;
468- }
469- if (has_maximum.FromJust ()) {
459+ if (!has_maximum.IsNothing () && has_maximum.FromJust ()) {
470460 if (!GetIntegerProperty (isolate, &thrower, context, descriptor, maximum_key,
471- &maximum, initial, 65536 )) {
461+ &maximum, initial,
462+ i::wasm::kSpecMaxWasmMemoryPages )) {
472463 return ;
473464 }
474465 }
@@ -481,8 +472,8 @@ void WebAssemblyMemory(const v8::FunctionCallbackInfo<v8::Value>& args) {
481472 thrower.RangeError (" could not allocate memory" );
482473 return ;
483474 }
484- i::Handle<i::JSObject> memory_obj = i::WasmMemoryObject::New (
485- i_isolate, buffer, has_maximum. FromJust () ? maximum : - 1 );
475+ i::Handle<i::JSObject> memory_obj =
476+ i::WasmMemoryObject::New ( i_isolate, buffer, maximum);
486477 args.GetReturnValue ().Set (Utils::ToLocal (memory_obj));
487478}
488479
@@ -523,7 +514,13 @@ void WebAssemblyTableGrow(const v8::FunctionCallbackInfo<v8::Value>& args) {
523514 }
524515 new_size64 += old_size;
525516
526- if (new_size64 < old_size || new_size64 > receiver->maximum_length ()) {
517+ int64_t max_size64 = receiver->maximum_length ();
518+ if (max_size64 < 0 ||
519+ max_size64 > static_cast <int64_t >(i::wasm::kV8MaxWasmTableSize )) {
520+ max_size64 = i::wasm::kV8MaxWasmTableSize ;
521+ }
522+
523+ if (new_size64 < old_size || new_size64 > max_size64) {
527524 v8::Local<v8::Value> e = v8::Exception::RangeError (
528525 v8_str (isolate, new_size64 < old_size ? " trying to shrink table"
529526 : " maximum table size exceeded" ));
0 commit comments