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

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

Issue 2514983002: [wasm] Throw a RangeError if Wasm memory could not be allocated. (Closed)
Patch Set: Fixing nits Created 4 years, 1 month 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/regress/wasm/regression-666741.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 317 matching lines...) Expand 10 before | Expand all | Expand 10 after
328 i::Handle<i::JSObject> table_obj = 328 i::Handle<i::JSObject> table_obj =
329 i::WasmTableObject::New(i_isolate, initial, maximum, &fixed_array); 329 i::WasmTableObject::New(i_isolate, initial, maximum, &fixed_array);
330 v8::ReturnValue<v8::Value> return_value = args.GetReturnValue(); 330 v8::ReturnValue<v8::Value> return_value = args.GetReturnValue();
331 return_value.Set(Utils::ToLocal(table_obj)); 331 return_value.Set(Utils::ToLocal(table_obj));
332 } 332 }
333 333
334 void WebAssemblyMemory(const v8::FunctionCallbackInfo<v8::Value>& args) { 334 void WebAssemblyMemory(const v8::FunctionCallbackInfo<v8::Value>& args) {
335 v8::Isolate* isolate = args.GetIsolate(); 335 v8::Isolate* isolate = args.GetIsolate();
336 HandleScope scope(isolate); 336 HandleScope scope(isolate);
337 ErrorThrower thrower(reinterpret_cast<i::Isolate*>(isolate), 337 ErrorThrower thrower(reinterpret_cast<i::Isolate*>(isolate),
338 "WebAssembly.Module()"); 338 "WebAssembly.Memory()");
339 if (args.Length() < 1 || !args[0]->IsObject()) { 339 if (args.Length() < 1 || !args[0]->IsObject()) {
340 thrower.TypeError("Argument 0 must be a memory descriptor"); 340 thrower.TypeError("Argument 0 must be a memory descriptor");
341 return; 341 return;
342 } 342 }
343 Local<Context> context = isolate->GetCurrentContext(); 343 Local<Context> context = isolate->GetCurrentContext();
344 Local<v8::Object> descriptor = args[0]->ToObject(context).ToLocalChecked(); 344 Local<v8::Object> descriptor = args[0]->ToObject(context).ToLocalChecked();
345 // The descriptor's 'initial'. 345 // The descriptor's 'initial'.
346 int initial; 346 int initial;
347 if (!GetIntegerProperty(isolate, &thrower, context, descriptor, 347 if (!GetIntegerProperty(isolate, &thrower, context, descriptor,
348 v8_str(isolate, "initial"), &initial, 0, 65536)) { 348 v8_str(isolate, "initial"), &initial, 0, 65536)) {
(...skipping 12 matching lines...) Expand all
361 if (!GetIntegerProperty(isolate, &thrower, context, descriptor, maximum_key, 361 if (!GetIntegerProperty(isolate, &thrower, context, descriptor, maximum_key,
362 &maximum, initial, 65536)) { 362 &maximum, initial, 65536)) {
363 return; 363 return;
364 } 364 }
365 } 365 }
366 i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate); 366 i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate);
367 size_t size = static_cast<size_t>(i::wasm::WasmModule::kPageSize) * 367 size_t size = static_cast<size_t>(i::wasm::WasmModule::kPageSize) *
368 static_cast<size_t>(initial); 368 static_cast<size_t>(initial);
369 i::Handle<i::JSArrayBuffer> buffer = 369 i::Handle<i::JSArrayBuffer> buffer =
370 i::wasm::NewArrayBuffer(i_isolate, size, i::FLAG_wasm_guard_pages); 370 i::wasm::NewArrayBuffer(i_isolate, size, i::FLAG_wasm_guard_pages);
371 371 if (buffer.is_null()) {
372 thrower.RangeError("could not allocate memory");
373 return;
374 }
372 i::Handle<i::JSObject> memory_obj = i::WasmMemoryObject::New( 375 i::Handle<i::JSObject> memory_obj = i::WasmMemoryObject::New(
373 i_isolate, buffer, has_maximum.FromJust() ? maximum : -1); 376 i_isolate, buffer, has_maximum.FromJust() ? maximum : -1);
374 args.GetReturnValue().Set(Utils::ToLocal(memory_obj)); 377 args.GetReturnValue().Set(Utils::ToLocal(memory_obj));
375 } 378 }
376 379
377 void WebAssemblyTableGetLength( 380 void WebAssemblyTableGetLength(
378 const v8::FunctionCallbackInfo<v8::Value>& args) { 381 const v8::FunctionCallbackInfo<v8::Value>& args) {
379 v8::Isolate* isolate = args.GetIsolate(); 382 v8::Isolate* isolate = args.GetIsolate();
380 Local<Context> context = isolate->GetCurrentContext(); 383 Local<Context> context = isolate->GetCurrentContext();
381 i::Handle<i::Context> i_context = Utils::OpenHandle(*context); 384 i::Handle<i::Context> i_context = Utils::OpenHandle(*context);
(...skipping 398 matching lines...) Expand 10 before | Expand all | Expand 10 after
780 i::Handle<i::Symbol> symbol(isolate->context()->wasm_memory_sym(), isolate); 783 i::Handle<i::Symbol> symbol(isolate->context()->wasm_memory_sym(), isolate);
781 return HasBrand(value, symbol); 784 return HasBrand(value, symbol);
782 } 785 }
783 786
784 bool WasmJs::IsWasmTableObject(Isolate* isolate, Handle<Object> value) { 787 bool WasmJs::IsWasmTableObject(Isolate* isolate, Handle<Object> value) {
785 i::Handle<i::Symbol> symbol(isolate->context()->wasm_table_sym(), isolate); 788 i::Handle<i::Symbol> symbol(isolate->context()->wasm_table_sym(), isolate);
786 return HasBrand(value, symbol); 789 return HasBrand(value, symbol);
787 } 790 }
788 } // namespace internal 791 } // namespace internal
789 } // namespace v8 792 } // namespace v8
OLDNEW
« no previous file with comments | « no previous file | test/mjsunit/regress/wasm/regression-666741.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698