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

Side by Side Diff: src/factory.cc

Issue 2498413002: Initialize internal fields in Factory::NewJSTypedArray and NewJSDataView. (Closed)
Patch Set: unit tests 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/cctest/test-api.cc » ('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 2014 the V8 project authors. All rights reserved. 1 // Copyright 2014 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/factory.h" 5 #include "src/factory.h"
6 6
7 #include "src/accessors.h" 7 #include "src/accessors.h"
8 #include "src/allocation-site-scopes.h" 8 #include "src/allocation-site-scopes.h"
9 #include "src/base/bits.h" 9 #include "src/base/bits.h"
10 #include "src/bootstrapper.h" 10 #include "src/bootstrapper.h"
(...skipping 1983 matching lines...) Expand 10 before | Expand all | Expand 10 after
1994 1994
1995 1995
1996 void SetupArrayBufferView(i::Isolate* isolate, 1996 void SetupArrayBufferView(i::Isolate* isolate,
1997 i::Handle<i::JSArrayBufferView> obj, 1997 i::Handle<i::JSArrayBufferView> obj,
1998 i::Handle<i::JSArrayBuffer> buffer, 1998 i::Handle<i::JSArrayBuffer> buffer,
1999 size_t byte_offset, size_t byte_length, 1999 size_t byte_offset, size_t byte_length,
2000 PretenureFlag pretenure = NOT_TENURED) { 2000 PretenureFlag pretenure = NOT_TENURED) {
2001 DCHECK(byte_offset + byte_length <= 2001 DCHECK(byte_offset + byte_length <=
2002 static_cast<size_t>(buffer->byte_length()->Number())); 2002 static_cast<size_t>(buffer->byte_length()->Number()));
2003 2003
2004 DCHECK_EQ(obj->GetInternalFieldCount(),
2005 v8::ArrayBufferView::kInternalFieldCount);
2006 for (int i = 0; i < v8::ArrayBufferView::kInternalFieldCount; i++) {
2007 obj->SetInternalField(i, Smi::kZero);
2008 }
2009
2004 obj->set_buffer(*buffer); 2010 obj->set_buffer(*buffer);
2005 2011
2006 i::Handle<i::Object> byte_offset_object = 2012 i::Handle<i::Object> byte_offset_object =
2007 isolate->factory()->NewNumberFromSize(byte_offset, pretenure); 2013 isolate->factory()->NewNumberFromSize(byte_offset, pretenure);
2008 obj->set_byte_offset(*byte_offset_object); 2014 obj->set_byte_offset(*byte_offset_object);
2009 2015
2010 i::Handle<i::Object> byte_length_object = 2016 i::Handle<i::Object> byte_length_object =
2011 isolate->factory()->NewNumberFromSize(byte_length, pretenure); 2017 isolate->factory()->NewNumberFromSize(byte_length, pretenure);
2012 obj->set_byte_length(*byte_length_object); 2018 obj->set_byte_length(*byte_length_object);
2013 } 2019 }
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
2063 Handle<Map> map = JSObject::GetElementsTransitionMap(obj, elements_kind); 2069 Handle<Map> map = JSObject::GetElementsTransitionMap(obj, elements_kind);
2064 JSObject::SetMapAndElements(obj, map, elements); 2070 JSObject::SetMapAndElements(obj, map, elements);
2065 return obj; 2071 return obj;
2066 } 2072 }
2067 2073
2068 2074
2069 Handle<JSTypedArray> Factory::NewJSTypedArray(ElementsKind elements_kind, 2075 Handle<JSTypedArray> Factory::NewJSTypedArray(ElementsKind elements_kind,
2070 size_t number_of_elements, 2076 size_t number_of_elements,
2071 PretenureFlag pretenure) { 2077 PretenureFlag pretenure) {
2072 Handle<JSTypedArray> obj = NewJSTypedArray(elements_kind, pretenure); 2078 Handle<JSTypedArray> obj = NewJSTypedArray(elements_kind, pretenure);
2079 DCHECK_EQ(obj->GetInternalFieldCount(),
2080 v8::ArrayBufferView::kInternalFieldCount);
2081 for (int i = 0; i < v8::ArrayBufferView::kInternalFieldCount; i++) {
2082 obj->SetInternalField(i, Smi::kZero);
2083 }
2073 2084
2074 size_t element_size = GetFixedTypedArraysElementSize(elements_kind); 2085 size_t element_size = GetFixedTypedArraysElementSize(elements_kind);
2075 ExternalArrayType array_type = GetArrayTypeFromElementsKind(elements_kind); 2086 ExternalArrayType array_type = GetArrayTypeFromElementsKind(elements_kind);
2076 2087
2077 CHECK(number_of_elements <= 2088 CHECK(number_of_elements <=
2078 (std::numeric_limits<size_t>::max() / element_size)); 2089 (std::numeric_limits<size_t>::max() / element_size));
2079 CHECK(number_of_elements <= static_cast<size_t>(Smi::kMaxValue)); 2090 CHECK(number_of_elements <= static_cast<size_t>(Smi::kMaxValue));
2080 size_t byte_length = number_of_elements * element_size; 2091 size_t byte_length = number_of_elements * element_size;
2081 2092
2082 obj->set_byte_offset(Smi::kZero); 2093 obj->set_byte_offset(Smi::kZero);
(...skipping 624 matching lines...) Expand 10 before | Expand all | Expand 10 after
2707 Handle<JSFixedArrayIterator>::cast(NewJSObjectFromMap(map)); 2718 Handle<JSFixedArrayIterator>::cast(NewJSObjectFromMap(map));
2708 iterator->set_initial_next(*next); 2719 iterator->set_initial_next(*next);
2709 iterator->set_array(*array); 2720 iterator->set_array(*array);
2710 iterator->set_index(0); 2721 iterator->set_index(0);
2711 iterator->InObjectPropertyAtPut(JSFixedArrayIterator::kNextIndex, *next); 2722 iterator->InObjectPropertyAtPut(JSFixedArrayIterator::kNextIndex, *next);
2712 return iterator; 2723 return iterator;
2713 } 2724 }
2714 2725
2715 } // namespace internal 2726 } // namespace internal
2716 } // namespace v8 2727 } // namespace v8
OLDNEW
« no previous file with comments | « no previous file | test/cctest/test-api.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698