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

Side by Side Diff: src/runtime/runtime-typedarray.cc

Issue 2396353002: Revert "Add Smi::Zero and replace all Smi::FromInt(0) calls" (Closed)
Patch Set: Created 4 years, 2 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/runtime/runtime-strings.cc ('k') | src/s390/code-stubs-s390.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/runtime/runtime-utils.h" 5 #include "src/runtime/runtime-utils.h"
6 6
7 #include "src/arguments.h" 7 #include "src/arguments.h"
8 #include "src/factory.h" 8 #include "src/factory.h"
9 #include "src/messages.h" 9 #include "src/messages.h"
10 #include "src/objects-inl.h" 10 #include "src/objects-inl.h"
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
52 CopyBytes(target_data, source_data + start, target_length); 52 CopyBytes(target_data, source_data + start, target_length);
53 return isolate->heap()->undefined_value(); 53 return isolate->heap()->undefined_value();
54 } 54 }
55 55
56 56
57 RUNTIME_FUNCTION(Runtime_ArrayBufferNeuter) { 57 RUNTIME_FUNCTION(Runtime_ArrayBufferNeuter) {
58 HandleScope scope(isolate); 58 HandleScope scope(isolate);
59 DCHECK(args.length() == 1); 59 DCHECK(args.length() == 1);
60 CONVERT_ARG_HANDLE_CHECKED(JSArrayBuffer, array_buffer, 0); 60 CONVERT_ARG_HANDLE_CHECKED(JSArrayBuffer, array_buffer, 0);
61 if (array_buffer->backing_store() == NULL) { 61 if (array_buffer->backing_store() == NULL) {
62 CHECK(Smi::kZero == array_buffer->byte_length()); 62 CHECK(Smi::FromInt(0) == array_buffer->byte_length());
63 return isolate->heap()->undefined_value(); 63 return isolate->heap()->undefined_value();
64 } 64 }
65 // Shared array buffers should never be neutered. 65 // Shared array buffers should never be neutered.
66 CHECK(!array_buffer->is_shared()); 66 CHECK(!array_buffer->is_shared());
67 DCHECK(!array_buffer->is_external()); 67 DCHECK(!array_buffer->is_external());
68 void* backing_store = array_buffer->backing_store(); 68 void* backing_store = array_buffer->backing_store();
69 size_t byte_length = NumberToSize(array_buffer->byte_length()); 69 size_t byte_length = NumberToSize(array_buffer->byte_length());
70 array_buffer->set_is_external(true); 70 array_buffer->set_is_external(true);
71 isolate->heap()->UnregisterArrayBuffer(*array_buffer); 71 isolate->heap()->UnregisterArrayBuffer(*array_buffer);
72 array_buffer->Neuter(); 72 array_buffer->Neuter();
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
135 if (length > static_cast<unsigned>(Smi::kMaxValue)) { 135 if (length > static_cast<unsigned>(Smi::kMaxValue)) {
136 THROW_NEW_ERROR_RETURN_FAILURE( 136 THROW_NEW_ERROR_RETURN_FAILURE(
137 isolate, NewRangeError(MessageTemplate::kInvalidTypedArrayLength)); 137 isolate, NewRangeError(MessageTemplate::kInvalidTypedArrayLength));
138 } 138 }
139 139
140 // All checks are done, now we can modify objects. 140 // All checks are done, now we can modify objects.
141 141
142 DCHECK_EQ(v8::ArrayBufferView::kInternalFieldCount, 142 DCHECK_EQ(v8::ArrayBufferView::kInternalFieldCount,
143 holder->GetInternalFieldCount()); 143 holder->GetInternalFieldCount());
144 for (int i = 0; i < v8::ArrayBufferView::kInternalFieldCount; i++) { 144 for (int i = 0; i < v8::ArrayBufferView::kInternalFieldCount; i++) {
145 holder->SetInternalField(i, Smi::kZero); 145 holder->SetInternalField(i, Smi::FromInt(0));
146 } 146 }
147 Handle<Object> length_obj = isolate->factory()->NewNumberFromSize(length); 147 Handle<Object> length_obj = isolate->factory()->NewNumberFromSize(length);
148 holder->set_length(*length_obj); 148 holder->set_length(*length_obj);
149 holder->set_byte_offset(*byte_offset_object); 149 holder->set_byte_offset(*byte_offset_object);
150 holder->set_byte_length(*byte_length_object); 150 holder->set_byte_length(*byte_length_object);
151 151
152 if (!maybe_buffer->IsNull(isolate)) { 152 if (!maybe_buffer->IsNull(isolate)) {
153 Handle<JSArrayBuffer> buffer = Handle<JSArrayBuffer>::cast(maybe_buffer); 153 Handle<JSArrayBuffer> buffer = Handle<JSArrayBuffer>::cast(maybe_buffer);
154 holder->set_buffer(*buffer); 154 holder->set_buffer(*buffer);
155 155
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
208 if ((length > static_cast<unsigned>(Smi::kMaxValue)) || 208 if ((length > static_cast<unsigned>(Smi::kMaxValue)) ||
209 (length > (kMaxInt / element_size))) { 209 (length > (kMaxInt / element_size))) {
210 THROW_NEW_ERROR_RETURN_FAILURE( 210 THROW_NEW_ERROR_RETURN_FAILURE(
211 isolate, NewRangeError(MessageTemplate::kInvalidTypedArrayLength)); 211 isolate, NewRangeError(MessageTemplate::kInvalidTypedArrayLength));
212 } 212 }
213 size_t byte_length = length * element_size; 213 size_t byte_length = length * element_size;
214 214
215 DCHECK_EQ(v8::ArrayBufferView::kInternalFieldCount, 215 DCHECK_EQ(v8::ArrayBufferView::kInternalFieldCount,
216 holder->GetInternalFieldCount()); 216 holder->GetInternalFieldCount());
217 for (int i = 0; i < v8::ArrayBufferView::kInternalFieldCount; i++) { 217 for (int i = 0; i < v8::ArrayBufferView::kInternalFieldCount; i++) {
218 holder->SetInternalField(i, Smi::kZero); 218 holder->SetInternalField(i, Smi::FromInt(0));
219 } 219 }
220 220
221 // NOTE: not initializing backing store. 221 // NOTE: not initializing backing store.
222 // We assume that the caller of this function will initialize holder 222 // We assume that the caller of this function will initialize holder
223 // with the loop 223 // with the loop
224 // for(i = 0; i < length; i++) { holder[i] = source[i]; } 224 // for(i = 0; i < length; i++) { holder[i] = source[i]; }
225 // We assume that the caller of this function is always a typed array 225 // We assume that the caller of this function is always a typed array
226 // constructor. 226 // constructor.
227 // If source is a typed array, this loop will always run to completion, 227 // If source is a typed array, this loop will always run to completion,
228 // so we are sure that the backing store will be initialized. 228 // so we are sure that the backing store will be initialized.
229 // Otherwise, the indexing operation might throw, so the loop will not 229 // Otherwise, the indexing operation might throw, so the loop will not
230 // run to completion and the typed array might remain partly initialized. 230 // run to completion and the typed array might remain partly initialized.
231 // However we further assume that the caller of this function is a typed array 231 // However we further assume that the caller of this function is a typed array
232 // constructor, and the exception will propagate out of the constructor, 232 // constructor, and the exception will propagate out of the constructor,
233 // therefore uninitialized memory will not be accessible by a user program. 233 // therefore uninitialized memory will not be accessible by a user program.
234 // 234 //
235 // TODO(dslomov): revise this once we support subclassing. 235 // TODO(dslomov): revise this once we support subclassing.
236 236
237 if (!JSArrayBuffer::SetupAllocatingData(buffer, isolate, byte_length, 237 if (!JSArrayBuffer::SetupAllocatingData(buffer, isolate, byte_length,
238 false)) { 238 false)) {
239 THROW_NEW_ERROR_RETURN_FAILURE( 239 THROW_NEW_ERROR_RETURN_FAILURE(
240 isolate, NewRangeError(MessageTemplate::kInvalidArrayBufferLength)); 240 isolate, NewRangeError(MessageTemplate::kInvalidArrayBufferLength));
241 } 241 }
242 242
243 holder->set_buffer(*buffer); 243 holder->set_buffer(*buffer);
244 holder->set_byte_offset(Smi::kZero); 244 holder->set_byte_offset(Smi::FromInt(0));
245 Handle<Object> byte_length_obj( 245 Handle<Object> byte_length_obj(
246 isolate->factory()->NewNumberFromSize(byte_length)); 246 isolate->factory()->NewNumberFromSize(byte_length));
247 holder->set_byte_length(*byte_length_obj); 247 holder->set_byte_length(*byte_length_obj);
248 length_obj = isolate->factory()->NewNumberFromSize(length); 248 length_obj = isolate->factory()->NewNumberFromSize(length);
249 holder->set_length(*length_obj); 249 holder->set_length(*length_obj);
250 250
251 Handle<FixedTypedArrayBase> elements = 251 Handle<FixedTypedArrayBase> elements =
252 isolate->factory()->NewFixedTypedArrayWithExternalPointer( 252 isolate->factory()->NewFixedTypedArrayWithExternalPointer(
253 static_cast<int>(length), array_type, 253 static_cast<int>(length), array_type,
254 static_cast<uint8_t*>(buffer->backing_store())); 254 static_cast<uint8_t*>(buffer->backing_store()));
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after
414 return isolate->heap()->false_value(); 414 return isolate->heap()->false_value();
415 } 415 }
416 416
417 Handle<JSTypedArray> obj(JSTypedArray::cast(args[0])); 417 Handle<JSTypedArray> obj(JSTypedArray::cast(args[0]));
418 return isolate->heap()->ToBoolean(obj->GetBuffer()->is_shared() && 418 return isolate->heap()->ToBoolean(obj->GetBuffer()->is_shared() &&
419 obj->type() == kExternalInt32Array); 419 obj->type() == kExternalInt32Array);
420 } 420 }
421 421
422 } // namespace internal 422 } // namespace internal
423 } // namespace v8 423 } // namespace v8
OLDNEW
« no previous file with comments | « src/runtime/runtime-strings.cc ('k') | src/s390/code-stubs-s390.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698