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

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

Issue 2045193002: [runtime] Deprecate RUNTIME_ASSERT from object ops. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Rebased. Created 4 years, 6 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-scopes.cc ('k') | test/mjsunit/regress/regress-403292.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 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 18 matching lines...) Expand all
29 CONVERT_NUMBER_ARG_HANDLE_CHECKED(first, 2); 29 CONVERT_NUMBER_ARG_HANDLE_CHECKED(first, 2);
30 CONVERT_NUMBER_ARG_HANDLE_CHECKED(new_length, 3); 30 CONVERT_NUMBER_ARG_HANDLE_CHECKED(new_length, 3);
31 31
32 if (source->was_neutered() || target->was_neutered()) { 32 if (source->was_neutered() || target->was_neutered()) {
33 THROW_NEW_ERROR_RETURN_FAILURE( 33 THROW_NEW_ERROR_RETURN_FAILURE(
34 isolate, NewTypeError(MessageTemplate::kDetachedOperation, 34 isolate, NewTypeError(MessageTemplate::kDetachedOperation,
35 isolate->factory()->NewStringFromAsciiChecked( 35 isolate->factory()->NewStringFromAsciiChecked(
36 "ArrayBuffer.prototype.slice"))); 36 "ArrayBuffer.prototype.slice")));
37 } 37 }
38 38
39 RUNTIME_ASSERT(!source.is_identical_to(target)); 39 CHECK(!source.is_identical_to(target));
40 size_t start = 0, target_length = 0; 40 size_t start = 0, target_length = 0;
41 RUNTIME_ASSERT(TryNumberToSize(isolate, *first, &start)); 41 CHECK(TryNumberToSize(isolate, *first, &start));
42 RUNTIME_ASSERT(TryNumberToSize(isolate, *new_length, &target_length)); 42 CHECK(TryNumberToSize(isolate, *new_length, &target_length));
43 RUNTIME_ASSERT(NumberToSize(isolate, target->byte_length()) >= target_length); 43 CHECK(NumberToSize(isolate, target->byte_length()) >= target_length);
44 44
45 if (target_length == 0) return isolate->heap()->undefined_value(); 45 if (target_length == 0) return isolate->heap()->undefined_value();
46 46
47 size_t source_byte_length = NumberToSize(isolate, source->byte_length()); 47 size_t source_byte_length = NumberToSize(isolate, source->byte_length());
48 RUNTIME_ASSERT(start <= source_byte_length); 48 CHECK(start <= source_byte_length);
49 RUNTIME_ASSERT(source_byte_length - start >= target_length); 49 CHECK(source_byte_length - start >= target_length);
50 uint8_t* source_data = reinterpret_cast<uint8_t*>(source->backing_store()); 50 uint8_t* source_data = reinterpret_cast<uint8_t*>(source->backing_store());
51 uint8_t* target_data = reinterpret_cast<uint8_t*>(target->backing_store()); 51 uint8_t* target_data = reinterpret_cast<uint8_t*>(target->backing_store());
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::FromInt(0) == 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 RUNTIME_ASSERT(!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(isolate, array_buffer->byte_length()); 69 size_t byte_length = NumberToSize(isolate, 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();
73 isolate->array_buffer_allocator()->Free(backing_store, byte_length); 73 isolate->array_buffer_allocator()->Free(backing_store, byte_length);
74 return isolate->heap()->undefined_value(); 74 return isolate->heap()->undefined_value();
75 } 75 }
76 76
(...skipping 21 matching lines...) Expand all
98 RUNTIME_FUNCTION(Runtime_TypedArrayInitialize) { 98 RUNTIME_FUNCTION(Runtime_TypedArrayInitialize) {
99 HandleScope scope(isolate); 99 HandleScope scope(isolate);
100 DCHECK(args.length() == 6); 100 DCHECK(args.length() == 6);
101 CONVERT_ARG_HANDLE_CHECKED(JSTypedArray, holder, 0); 101 CONVERT_ARG_HANDLE_CHECKED(JSTypedArray, holder, 0);
102 CONVERT_SMI_ARG_CHECKED(arrayId, 1); 102 CONVERT_SMI_ARG_CHECKED(arrayId, 1);
103 CONVERT_ARG_HANDLE_CHECKED(Object, maybe_buffer, 2); 103 CONVERT_ARG_HANDLE_CHECKED(Object, maybe_buffer, 2);
104 CONVERT_NUMBER_ARG_HANDLE_CHECKED(byte_offset_object, 3); 104 CONVERT_NUMBER_ARG_HANDLE_CHECKED(byte_offset_object, 3);
105 CONVERT_NUMBER_ARG_HANDLE_CHECKED(byte_length_object, 4); 105 CONVERT_NUMBER_ARG_HANDLE_CHECKED(byte_length_object, 4);
106 CONVERT_BOOLEAN_ARG_CHECKED(initialize, 5); 106 CONVERT_BOOLEAN_ARG_CHECKED(initialize, 5);
107 107
108 RUNTIME_ASSERT(arrayId >= Runtime::ARRAY_ID_FIRST && 108 CHECK(arrayId >= Runtime::ARRAY_ID_FIRST &&
109 arrayId <= Runtime::ARRAY_ID_LAST); 109 arrayId <= Runtime::ARRAY_ID_LAST);
110 110
111 ExternalArrayType array_type = kExternalInt8Array; // Bogus initialization. 111 ExternalArrayType array_type = kExternalInt8Array; // Bogus initialization.
112 size_t element_size = 1; // Bogus initialization. 112 size_t element_size = 1; // Bogus initialization.
113 ElementsKind fixed_elements_kind = INT8_ELEMENTS; // Bogus initialization. 113 ElementsKind fixed_elements_kind = INT8_ELEMENTS; // Bogus initialization.
114 Runtime::ArrayIdToTypeAndSize(arrayId, &array_type, &fixed_elements_kind, 114 Runtime::ArrayIdToTypeAndSize(arrayId, &array_type, &fixed_elements_kind,
115 &element_size); 115 &element_size);
116 RUNTIME_ASSERT(holder->map()->elements_kind() == fixed_elements_kind); 116 CHECK(holder->map()->elements_kind() == fixed_elements_kind);
117 117
118 size_t byte_offset = 0; 118 size_t byte_offset = 0;
119 size_t byte_length = 0; 119 size_t byte_length = 0;
120 RUNTIME_ASSERT(TryNumberToSize(isolate, *byte_offset_object, &byte_offset)); 120 CHECK(TryNumberToSize(isolate, *byte_offset_object, &byte_offset));
121 RUNTIME_ASSERT(TryNumberToSize(isolate, *byte_length_object, &byte_length)); 121 CHECK(TryNumberToSize(isolate, *byte_length_object, &byte_length));
122 122
123 if (maybe_buffer->IsJSArrayBuffer()) { 123 if (maybe_buffer->IsJSArrayBuffer()) {
124 Handle<JSArrayBuffer> buffer = Handle<JSArrayBuffer>::cast(maybe_buffer); 124 Handle<JSArrayBuffer> buffer = Handle<JSArrayBuffer>::cast(maybe_buffer);
125 size_t array_buffer_byte_length = 125 size_t array_buffer_byte_length =
126 NumberToSize(isolate, buffer->byte_length()); 126 NumberToSize(isolate, buffer->byte_length());
127 RUNTIME_ASSERT(byte_offset <= array_buffer_byte_length); 127 CHECK(byte_offset <= array_buffer_byte_length);
128 RUNTIME_ASSERT(array_buffer_byte_length - byte_offset >= byte_length); 128 CHECK(array_buffer_byte_length - byte_offset >= byte_length);
129 } else { 129 } else {
130 RUNTIME_ASSERT(maybe_buffer->IsNull()); 130 CHECK(maybe_buffer->IsNull());
131 } 131 }
132 132
133 RUNTIME_ASSERT(byte_length % element_size == 0); 133 CHECK(byte_length % element_size == 0);
134 size_t length = byte_length / element_size; 134 size_t length = byte_length / element_size;
135 135
136 if (length > static_cast<unsigned>(Smi::kMaxValue)) { 136 if (length > static_cast<unsigned>(Smi::kMaxValue)) {
137 THROW_NEW_ERROR_RETURN_FAILURE( 137 THROW_NEW_ERROR_RETURN_FAILURE(
138 isolate, NewRangeError(MessageTemplate::kInvalidTypedArrayLength)); 138 isolate, NewRangeError(MessageTemplate::kInvalidTypedArrayLength));
139 } 139 }
140 140
141 // All checks are done, now we can modify objects. 141 // All checks are done, now we can modify objects.
142 142
143 DCHECK_EQ(v8::ArrayBufferView::kInternalFieldCount, 143 DCHECK_EQ(v8::ArrayBufferView::kInternalFieldCount,
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
179 // 179 //
180 // Returns true if backing store was initialized or false otherwise. 180 // Returns true if backing store was initialized or false otherwise.
181 RUNTIME_FUNCTION(Runtime_TypedArrayInitializeFromArrayLike) { 181 RUNTIME_FUNCTION(Runtime_TypedArrayInitializeFromArrayLike) {
182 HandleScope scope(isolate); 182 HandleScope scope(isolate);
183 DCHECK(args.length() == 4); 183 DCHECK(args.length() == 4);
184 CONVERT_ARG_HANDLE_CHECKED(JSTypedArray, holder, 0); 184 CONVERT_ARG_HANDLE_CHECKED(JSTypedArray, holder, 0);
185 CONVERT_SMI_ARG_CHECKED(arrayId, 1); 185 CONVERT_SMI_ARG_CHECKED(arrayId, 1);
186 CONVERT_ARG_HANDLE_CHECKED(Object, source, 2); 186 CONVERT_ARG_HANDLE_CHECKED(Object, source, 2);
187 CONVERT_NUMBER_ARG_HANDLE_CHECKED(length_obj, 3); 187 CONVERT_NUMBER_ARG_HANDLE_CHECKED(length_obj, 3);
188 188
189 RUNTIME_ASSERT(arrayId >= Runtime::ARRAY_ID_FIRST && 189 CHECK(arrayId >= Runtime::ARRAY_ID_FIRST &&
190 arrayId <= Runtime::ARRAY_ID_LAST); 190 arrayId <= Runtime::ARRAY_ID_LAST);
191 191
192 ExternalArrayType array_type = kExternalInt8Array; // Bogus initialization. 192 ExternalArrayType array_type = kExternalInt8Array; // Bogus initialization.
193 size_t element_size = 1; // Bogus initialization. 193 size_t element_size = 1; // Bogus initialization.
194 ElementsKind fixed_elements_kind = INT8_ELEMENTS; // Bogus initialization. 194 ElementsKind fixed_elements_kind = INT8_ELEMENTS; // Bogus initialization.
195 Runtime::ArrayIdToTypeAndSize(arrayId, &array_type, &fixed_elements_kind, 195 Runtime::ArrayIdToTypeAndSize(arrayId, &array_type, &fixed_elements_kind,
196 &element_size); 196 &element_size);
197 197
198 RUNTIME_ASSERT(holder->map()->elements_kind() == fixed_elements_kind); 198 CHECK(holder->map()->elements_kind() == fixed_elements_kind);
199 199
200 Handle<JSArrayBuffer> buffer = isolate->factory()->NewJSArrayBuffer(); 200 Handle<JSArrayBuffer> buffer = isolate->factory()->NewJSArrayBuffer();
201 size_t length = 0; 201 size_t length = 0;
202 if (source->IsJSTypedArray() && 202 if (source->IsJSTypedArray() &&
203 JSTypedArray::cast(*source)->type() == array_type) { 203 JSTypedArray::cast(*source)->type() == array_type) {
204 length_obj = handle(JSTypedArray::cast(*source)->length(), isolate); 204 length_obj = handle(JSTypedArray::cast(*source)->length(), isolate);
205 length = JSTypedArray::cast(*source)->length_value(); 205 length = JSTypedArray::cast(*source)->length_value();
206 } else { 206 } else {
207 RUNTIME_ASSERT(TryNumberToSize(isolate, *length_obj, &length)); 207 CHECK(TryNumberToSize(isolate, *length_obj, &length));
208 } 208 }
209 209
210 if ((length > static_cast<unsigned>(Smi::kMaxValue)) || 210 if ((length > static_cast<unsigned>(Smi::kMaxValue)) ||
211 (length > (kMaxInt / element_size))) { 211 (length > (kMaxInt / element_size))) {
212 THROW_NEW_ERROR_RETURN_FAILURE( 212 THROW_NEW_ERROR_RETURN_FAILURE(
213 isolate, NewRangeError(MessageTemplate::kInvalidTypedArrayLength)); 213 isolate, NewRangeError(MessageTemplate::kInvalidTypedArrayLength));
214 } 214 }
215 size_t byte_length = length * element_size; 215 size_t byte_length = length * element_size;
216 216
217 DCHECK_EQ(v8::ArrayBufferView::kInternalFieldCount, 217 DCHECK_EQ(v8::ArrayBufferView::kInternalFieldCount,
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
321 if (!args[1]->IsJSTypedArray()) 321 if (!args[1]->IsJSTypedArray())
322 return Smi::FromInt(TYPED_ARRAY_SET_NON_TYPED_ARRAY); 322 return Smi::FromInt(TYPED_ARRAY_SET_NON_TYPED_ARRAY);
323 323
324 CONVERT_ARG_HANDLE_CHECKED(JSTypedArray, target_obj, 0); 324 CONVERT_ARG_HANDLE_CHECKED(JSTypedArray, target_obj, 0);
325 CONVERT_ARG_HANDLE_CHECKED(JSTypedArray, source_obj, 1); 325 CONVERT_ARG_HANDLE_CHECKED(JSTypedArray, source_obj, 1);
326 CONVERT_NUMBER_ARG_HANDLE_CHECKED(offset_obj, 2); 326 CONVERT_NUMBER_ARG_HANDLE_CHECKED(offset_obj, 2);
327 327
328 Handle<JSTypedArray> target(JSTypedArray::cast(*target_obj)); 328 Handle<JSTypedArray> target(JSTypedArray::cast(*target_obj));
329 Handle<JSTypedArray> source(JSTypedArray::cast(*source_obj)); 329 Handle<JSTypedArray> source(JSTypedArray::cast(*source_obj));
330 size_t offset = 0; 330 size_t offset = 0;
331 RUNTIME_ASSERT(TryNumberToSize(isolate, *offset_obj, &offset)); 331 CHECK(TryNumberToSize(isolate, *offset_obj, &offset));
332 size_t target_length = target->length_value(); 332 size_t target_length = target->length_value();
333 size_t source_length = source->length_value(); 333 size_t source_length = source->length_value();
334 size_t target_byte_length = NumberToSize(isolate, target->byte_length()); 334 size_t target_byte_length = NumberToSize(isolate, target->byte_length());
335 size_t source_byte_length = NumberToSize(isolate, source->byte_length()); 335 size_t source_byte_length = NumberToSize(isolate, source->byte_length());
336 if (offset > target_length || offset + source_length > target_length || 336 if (offset > target_length || offset + source_length > target_length ||
337 offset + source_length < offset) { // overflow 337 offset + source_length < offset) { // overflow
338 THROW_NEW_ERROR_RETURN_FAILURE( 338 THROW_NEW_ERROR_RETURN_FAILURE(
339 isolate, NewRangeError(MessageTemplate::kTypedArraySetSourceTooLarge)); 339 isolate, NewRangeError(MessageTemplate::kTypedArraySetSourceTooLarge));
340 } 340 }
341 341
(...skipping 292 matching lines...) Expand 10 before | Expand all | Expand 10 after
634 DATA_VIEW_SETTER(Uint16, uint16_t) 634 DATA_VIEW_SETTER(Uint16, uint16_t)
635 DATA_VIEW_SETTER(Int16, int16_t) 635 DATA_VIEW_SETTER(Int16, int16_t)
636 DATA_VIEW_SETTER(Uint32, uint32_t) 636 DATA_VIEW_SETTER(Uint32, uint32_t)
637 DATA_VIEW_SETTER(Int32, int32_t) 637 DATA_VIEW_SETTER(Int32, int32_t)
638 DATA_VIEW_SETTER(Float32, float) 638 DATA_VIEW_SETTER(Float32, float)
639 DATA_VIEW_SETTER(Float64, double) 639 DATA_VIEW_SETTER(Float64, double)
640 640
641 #undef DATA_VIEW_SETTER 641 #undef DATA_VIEW_SETTER
642 } // namespace internal 642 } // namespace internal
643 } // namespace v8 643 } // namespace v8
OLDNEW
« no previous file with comments | « src/runtime/runtime-scopes.cc ('k') | test/mjsunit/regress/regress-403292.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698