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

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

Issue 2820223002: [wasm] Handle no initial memory case correctly when memory is exported (Closed)
Patch Set: Fix bot failure Created 3 years, 8 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/wasm-objects.h ('k') | test/mjsunit/regress/wasm/regression-699485.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/wasm/wasm-objects.h" 5 #include "src/wasm/wasm-objects.h"
6 #include "src/utils.h" 6 #include "src/utils.h"
7 7
8 #include "src/assembler-inl.h" 8 #include "src/assembler-inl.h"
9 #include "src/base/iterator.h" 9 #include "src/base/iterator.h"
10 #include "src/compiler/wasm-compiler.h" 10 #include "src/compiler/wasm-compiler.h"
(...skipping 364 matching lines...) Expand 10 before | Expand all | Expand 10 after
375 } // namespace 375 } // namespace
376 376
377 Handle<WasmMemoryObject> WasmMemoryObject::New(Isolate* isolate, 377 Handle<WasmMemoryObject> WasmMemoryObject::New(Isolate* isolate,
378 Handle<JSArrayBuffer> buffer, 378 Handle<JSArrayBuffer> buffer,
379 int32_t maximum) { 379 int32_t maximum) {
380 Handle<JSFunction> memory_ctor( 380 Handle<JSFunction> memory_ctor(
381 isolate->native_context()->wasm_memory_constructor()); 381 isolate->native_context()->wasm_memory_constructor());
382 Handle<JSObject> memory_obj = 382 Handle<JSObject> memory_obj =
383 isolate->factory()->NewJSObject(memory_ctor, TENURED); 383 isolate->factory()->NewJSObject(memory_ctor, TENURED);
384 memory_obj->SetEmbedderField(kWrapperTracerHeader, Smi::kZero); 384 memory_obj->SetEmbedderField(kWrapperTracerHeader, Smi::kZero);
385 385 buffer.is_null() ? memory_obj->SetEmbedderField(
386 memory_obj->SetEmbedderField(kArrayBuffer, *buffer); 386 kArrayBuffer, isolate->heap()->undefined_value())
387 : memory_obj->SetEmbedderField(kArrayBuffer, *buffer);
387 Handle<Object> max = isolate->factory()->NewNumber(maximum); 388 Handle<Object> max = isolate->factory()->NewNumber(maximum);
388 memory_obj->SetEmbedderField(kMaximum, *max); 389 memory_obj->SetEmbedderField(kMaximum, *max);
389 Handle<Symbol> memory_sym(isolate->native_context()->wasm_memory_sym()); 390 Handle<Symbol> memory_sym(isolate->native_context()->wasm_memory_sym());
390 Object::SetProperty(memory_obj, memory_sym, memory_obj, STRICT).Check(); 391 Object::SetProperty(memory_obj, memory_sym, memory_obj, STRICT).Check();
391 return Handle<WasmMemoryObject>::cast(memory_obj); 392 return Handle<WasmMemoryObject>::cast(memory_obj);
392 } 393 }
393 394
394 DEFINE_OBJ_ACCESSORS(WasmMemoryObject, buffer, kArrayBuffer, JSArrayBuffer) 395 DEFINE_OPTIONAL_OBJ_ACCESSORS(WasmMemoryObject, buffer, kArrayBuffer,
396 JSArrayBuffer)
395 DEFINE_OPTIONAL_OBJ_ACCESSORS(WasmMemoryObject, instances_link, kInstancesLink, 397 DEFINE_OPTIONAL_OBJ_ACCESSORS(WasmMemoryObject, instances_link, kInstancesLink,
396 WasmInstanceWrapper) 398 WasmInstanceWrapper)
397 399
398 uint32_t WasmMemoryObject::current_pages() { 400 uint32_t WasmMemoryObject::current_pages() {
399 uint32_t byte_length; 401 uint32_t byte_length;
400 CHECK(buffer()->byte_length()->ToUint32(&byte_length)); 402 CHECK(buffer()->byte_length()->ToUint32(&byte_length));
401 return byte_length / wasm::WasmModule::kPageSize; 403 return byte_length / wasm::WasmModule::kPageSize;
402 } 404 }
403 405
404 bool WasmMemoryObject::has_maximum_pages() { 406 bool WasmMemoryObject::has_maximum_pages() {
(...skipping 26 matching lines...) Expand all
431 433
432 void WasmMemoryObject::ResetInstancesLink(Isolate* isolate) { 434 void WasmMemoryObject::ResetInstancesLink(Isolate* isolate) {
433 Handle<Object> undefined = isolate->factory()->undefined_value(); 435 Handle<Object> undefined = isolate->factory()->undefined_value();
434 SetEmbedderField(kInstancesLink, *undefined); 436 SetEmbedderField(kInstancesLink, *undefined);
435 } 437 }
436 438
437 // static 439 // static
438 int32_t WasmMemoryObject::Grow(Isolate* isolate, 440 int32_t WasmMemoryObject::Grow(Isolate* isolate,
439 Handle<WasmMemoryObject> memory_object, 441 Handle<WasmMemoryObject> memory_object,
440 uint32_t pages) { 442 uint32_t pages) {
441 Handle<JSArrayBuffer> old_buffer(memory_object->buffer(), isolate); 443 Handle<JSArrayBuffer> old_buffer;
442 uint32_t old_size = 0; 444 uint32_t old_size = 0;
443 Address old_mem_start = nullptr; 445 Address old_mem_start = nullptr;
444 // Force byte_length to 0, if byte_length fails IsNumber() check. 446 if (memory_object->has_buffer()) {
445 if (!old_buffer.is_null()) { 447 old_buffer = handle(memory_object->buffer());
446 old_size = old_buffer->byte_length()->Number(); 448 old_size = old_buffer->byte_length()->Number();
447 old_mem_start = static_cast<Address>(old_buffer->backing_store()); 449 old_mem_start = static_cast<Address>(old_buffer->backing_store());
448 } 450 }
449 Handle<JSArrayBuffer> new_buffer; 451 Handle<JSArrayBuffer> new_buffer;
450 // Return current size if grow by 0. 452 // Return current size if grow by 0.
451 if (pages == 0) { 453 if (pages == 0) {
452 // Even for pages == 0, we need to attach a new JSArrayBuffer and neuter the 454 // Even for pages == 0, we need to attach a new JSArrayBuffer and neuter the
453 // old one to be spec compliant. 455 // old one to be spec compliant.
454 if (!old_buffer.is_null() && old_buffer->backing_store() != nullptr) { 456 if (!old_buffer.is_null() && old_buffer->backing_store() != nullptr) {
455 new_buffer = SetupArrayBuffer(isolate, old_buffer->backing_store(), 457 new_buffer = SetupArrayBuffer(isolate, old_buffer->backing_store(),
(...skipping 1101 matching lines...) Expand 10 before | Expand all | Expand 10 after
1557 if (!array->get(kWrapperInstanceObject)->IsWeakCell()) return false; 1559 if (!array->get(kWrapperInstanceObject)->IsWeakCell()) return false;
1558 Isolate* isolate = array->GetIsolate(); 1560 Isolate* isolate = array->GetIsolate();
1559 if (!array->get(kNextInstanceWrapper)->IsUndefined(isolate) && 1561 if (!array->get(kNextInstanceWrapper)->IsUndefined(isolate) &&
1560 !array->get(kNextInstanceWrapper)->IsFixedArray()) 1562 !array->get(kNextInstanceWrapper)->IsFixedArray())
1561 return false; 1563 return false;
1562 if (!array->get(kPreviousInstanceWrapper)->IsUndefined(isolate) && 1564 if (!array->get(kPreviousInstanceWrapper)->IsUndefined(isolate) &&
1563 !array->get(kPreviousInstanceWrapper)->IsFixedArray()) 1565 !array->get(kPreviousInstanceWrapper)->IsFixedArray())
1564 return false; 1566 return false;
1565 return true; 1567 return true;
1566 } 1568 }
OLDNEW
« no previous file with comments | « src/wasm/wasm-objects.h ('k') | test/mjsunit/regress/wasm/regression-699485.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698