OLD | NEW |
1 // Copyright 2013 the V8 project authors. All rights reserved. | 1 // Copyright 2013 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 <iomanip> | 5 #include <iomanip> |
6 #include <sstream> | 6 #include <sstream> |
7 | 7 |
8 #include "src/v8.h" | 8 #include "src/v8.h" |
9 | 9 |
10 #include "src/accessors.h" | 10 #include "src/accessors.h" |
(...skipping 1263 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1274 case BYTE_ARRAY_TYPE: | 1274 case BYTE_ARRAY_TYPE: |
1275 os << "<ByteArray[" << ByteArray::cast(this)->length() << "]>"; | 1275 os << "<ByteArray[" << ByteArray::cast(this)->length() << "]>"; |
1276 break; | 1276 break; |
1277 case BYTECODE_ARRAY_TYPE: | 1277 case BYTECODE_ARRAY_TYPE: |
1278 os << "<BytecodeArray[" << BytecodeArray::cast(this)->length() << "]>"; | 1278 os << "<BytecodeArray[" << BytecodeArray::cast(this)->length() << "]>"; |
1279 break; | 1279 break; |
1280 case FREE_SPACE_TYPE: | 1280 case FREE_SPACE_TYPE: |
1281 os << "<FreeSpace[" << FreeSpace::cast(this)->Size() << "]>"; | 1281 os << "<FreeSpace[" << FreeSpace::cast(this)->Size() << "]>"; |
1282 break; | 1282 break; |
1283 #define TYPED_ARRAY_SHORT_PRINT(Type, type, TYPE, ctype, size) \ | 1283 #define TYPED_ARRAY_SHORT_PRINT(Type, type, TYPE, ctype, size) \ |
1284 case EXTERNAL_##TYPE##_ARRAY_TYPE: \ | |
1285 os << "<External" #Type "Array[" \ | |
1286 << External##Type##Array::cast(this)->length() << "]>"; \ | |
1287 break; \ | |
1288 case FIXED_##TYPE##_ARRAY_TYPE: \ | 1284 case FIXED_##TYPE##_ARRAY_TYPE: \ |
1289 os << "<Fixed" #Type "Array[" << Fixed##Type##Array::cast(this)->length() \ | 1285 os << "<Fixed" #Type "Array[" << Fixed##Type##Array::cast(this)->length() \ |
1290 << "]>"; \ | 1286 << "]>"; \ |
1291 break; | 1287 break; |
1292 | 1288 |
1293 TYPED_ARRAYS(TYPED_ARRAY_SHORT_PRINT) | 1289 TYPED_ARRAYS(TYPED_ARRAY_SHORT_PRINT) |
1294 #undef TYPED_ARRAY_SHORT_PRINT | 1290 #undef TYPED_ARRAY_SHORT_PRINT |
1295 | 1291 |
1296 case SHARED_FUNCTION_INFO_TYPE: { | 1292 case SHARED_FUNCTION_INFO_TYPE: { |
1297 SharedFunctionInfo* shared = SharedFunctionInfo::cast(this); | 1293 SharedFunctionInfo* shared = SharedFunctionInfo::cast(this); |
(...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1501 case HEAP_NUMBER_TYPE: | 1497 case HEAP_NUMBER_TYPE: |
1502 case MUTABLE_HEAP_NUMBER_TYPE: | 1498 case MUTABLE_HEAP_NUMBER_TYPE: |
1503 case FLOAT32X4_TYPE: | 1499 case FLOAT32X4_TYPE: |
1504 case FILLER_TYPE: | 1500 case FILLER_TYPE: |
1505 case BYTE_ARRAY_TYPE: | 1501 case BYTE_ARRAY_TYPE: |
1506 case BYTECODE_ARRAY_TYPE: | 1502 case BYTECODE_ARRAY_TYPE: |
1507 case FREE_SPACE_TYPE: | 1503 case FREE_SPACE_TYPE: |
1508 break; | 1504 break; |
1509 | 1505 |
1510 #define TYPED_ARRAY_CASE(Type, type, TYPE, ctype, size) \ | 1506 #define TYPED_ARRAY_CASE(Type, type, TYPE, ctype, size) \ |
1511 case EXTERNAL_##TYPE##_ARRAY_TYPE: \ | |
1512 break; \ | |
1513 \ | |
1514 case FIXED_##TYPE##_ARRAY_TYPE: \ | 1507 case FIXED_##TYPE##_ARRAY_TYPE: \ |
1515 reinterpret_cast<FixedTypedArrayBase*>(this) \ | 1508 reinterpret_cast<FixedTypedArrayBase*>(this) \ |
1516 ->FixedTypedArrayBaseIterateBody(v); \ | 1509 ->FixedTypedArrayBaseIterateBody(v); \ |
1517 break; | 1510 break; |
1518 | 1511 |
1519 | 1512 |
1520 TYPED_ARRAYS(TYPED_ARRAY_CASE) | 1513 TYPED_ARRAYS(TYPED_ARRAY_CASE) |
1521 #undef TYPED_ARRAY_CASE | 1514 #undef TYPED_ARRAY_CASE |
1522 | 1515 |
1523 case SHARED_FUNCTION_INFO_TYPE: { | 1516 case SHARED_FUNCTION_INFO_TYPE: { |
(...skipping 1787 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3311 // Fetch before transforming the object since the encoding may become | 3304 // Fetch before transforming the object since the encoding may become |
3312 // incompatible with what's cached in |it|. | 3305 // incompatible with what's cached in |it|. |
3313 bool is_observed = receiver->map()->is_observed() && | 3306 bool is_observed = receiver->map()->is_observed() && |
3314 (it->IsElement() || | 3307 (it->IsElement() || |
3315 !it->isolate()->IsInternallyUsedPropertyName(it->name())); | 3308 !it->isolate()->IsInternallyUsedPropertyName(it->name())); |
3316 MaybeHandle<Object> maybe_old; | 3309 MaybeHandle<Object> maybe_old; |
3317 if (is_observed) maybe_old = it->GetDataValue(); | 3310 if (is_observed) maybe_old = it->GetDataValue(); |
3318 | 3311 |
3319 Handle<Object> to_assign = value; | 3312 Handle<Object> to_assign = value; |
3320 // Convert the incoming value to a number for storing into typed arrays. | 3313 // Convert the incoming value to a number for storing into typed arrays. |
3321 if (it->IsElement() && (receiver->HasExternalArrayElements() || | 3314 if (it->IsElement() && receiver->HasFixedTypedArrayElements()) { |
3322 receiver->HasFixedTypedArrayElements())) { | |
3323 if (!value->IsNumber() && !value->IsUndefined()) { | 3315 if (!value->IsNumber() && !value->IsUndefined()) { |
3324 ASSIGN_RETURN_ON_EXCEPTION(it->isolate(), to_assign, | 3316 ASSIGN_RETURN_ON_EXCEPTION(it->isolate(), to_assign, |
3325 Execution::ToNumber(it->isolate(), value), | 3317 Execution::ToNumber(it->isolate(), value), |
3326 Object); | 3318 Object); |
3327 // ToNumber above might modify the receiver, causing the cached | 3319 // ToNumber above might modify the receiver, causing the cached |
3328 // holder_map to mismatch the actual holder->map() after this point. | 3320 // holder_map to mismatch the actual holder->map() after this point. |
3329 // Reload the map to be in consistent state. Other cached state cannot | 3321 // Reload the map to be in consistent state. Other cached state cannot |
3330 // have been invalidated since typed array elements cannot be reconfigured | 3322 // have been invalidated since typed array elements cannot be reconfigured |
3331 // in any way. | 3323 // in any way. |
3332 it->ReloadHolderMap(); | 3324 it->ReloadHolderMap(); |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3424 | 3416 |
3425 if (it->IsElement()) { | 3417 if (it->IsElement()) { |
3426 if (receiver->IsJSArray()) { | 3418 if (receiver->IsJSArray()) { |
3427 Handle<JSArray> array = Handle<JSArray>::cast(receiver); | 3419 Handle<JSArray> array = Handle<JSArray>::cast(receiver); |
3428 if (JSArray::WouldChangeReadOnlyLength(array, it->index())) { | 3420 if (JSArray::WouldChangeReadOnlyLength(array, it->index())) { |
3429 if (is_sloppy(language_mode)) return value; | 3421 if (is_sloppy(language_mode)) return value; |
3430 return JSArray::ReadOnlyLengthError(array); | 3422 return JSArray::ReadOnlyLengthError(array); |
3431 } | 3423 } |
3432 | 3424 |
3433 if (FLAG_trace_external_array_abuse && | 3425 if (FLAG_trace_external_array_abuse && |
3434 (array->HasExternalArrayElements() || | 3426 array->HasFixedTypedArrayElements()) { |
3435 array->HasFixedTypedArrayElements())) { | |
3436 CheckArrayAbuse(array, "typed elements write", it->index(), true); | 3427 CheckArrayAbuse(array, "typed elements write", it->index(), true); |
3437 } | 3428 } |
3438 | 3429 |
3439 if (FLAG_trace_js_array_abuse && !array->HasExternalArrayElements() && | 3430 if (FLAG_trace_js_array_abuse && !array->HasFixedTypedArrayElements()) { |
3440 !array->HasFixedTypedArrayElements()) { | |
3441 CheckArrayAbuse(array, "elements write", it->index(), false); | 3431 CheckArrayAbuse(array, "elements write", it->index(), false); |
3442 } | 3432 } |
3443 } | 3433 } |
3444 | 3434 |
3445 MaybeHandle<Object> result = | 3435 MaybeHandle<Object> result = |
3446 JSObject::AddDataElement(receiver, it->index(), value, attributes); | 3436 JSObject::AddDataElement(receiver, it->index(), value, attributes); |
3447 JSObject::ValidateElements(receiver); | 3437 JSObject::ValidateElements(receiver); |
3448 return result; | 3438 return result; |
3449 } else { | 3439 } else { |
3450 // Migrate to the most up-to-date map that will be able to store |value| | 3440 // Migrate to the most up-to-date map that will be able to store |value| |
(...skipping 808 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4259 case LookupIterator::DATA: { | 4249 case LookupIterator::DATA: { |
4260 PropertyDetails details = it->property_details(); | 4250 PropertyDetails details = it->property_details(); |
4261 Handle<Object> old_value = it->factory()->the_hole_value(); | 4251 Handle<Object> old_value = it->factory()->the_hole_value(); |
4262 // Regular property update if the attributes match. | 4252 // Regular property update if the attributes match. |
4263 if (details.attributes() == attributes) { | 4253 if (details.attributes() == attributes) { |
4264 return SetDataProperty(it, value); | 4254 return SetDataProperty(it, value); |
4265 } | 4255 } |
4266 | 4256 |
4267 // Special case: properties of typed arrays cannot be reconfigured to | 4257 // Special case: properties of typed arrays cannot be reconfigured to |
4268 // non-writable nor to non-enumerable. | 4258 // non-writable nor to non-enumerable. |
4269 if (it->IsElement() && (object->HasExternalArrayElements() || | 4259 if (it->IsElement() && object->HasFixedTypedArrayElements()) { |
4270 object->HasFixedTypedArrayElements())) { | |
4271 return RedefineNonconfigurableProperty(it->isolate(), it->GetName(), | 4260 return RedefineNonconfigurableProperty(it->isolate(), it->GetName(), |
4272 value, STRICT); | 4261 value, STRICT); |
4273 } | 4262 } |
4274 | 4263 |
4275 // Reconfigure the data property if the attributes mismatch. | 4264 // Reconfigure the data property if the attributes mismatch. |
4276 if (is_observed) old_value = it->GetDataValue(); | 4265 if (is_observed) old_value = it->GetDataValue(); |
4277 | 4266 |
4278 it->ReconfigureDataProperty(value, attributes); | 4267 it->ReconfigureDataProperty(value, attributes); |
4279 it->WriteDataValue(value); | 4268 it->WriteDataValue(value); |
4280 | 4269 |
(...skipping 562 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4843 : elements->length(); | 4832 : elements->length(); |
4844 int used = object->GetFastElementsUsage(); | 4833 int used = object->GetFastElementsUsage(); |
4845 Handle<SeededNumberDictionary> dictionary = | 4834 Handle<SeededNumberDictionary> dictionary = |
4846 SeededNumberDictionary::New(isolate, used); | 4835 SeededNumberDictionary::New(isolate, used); |
4847 return CopyFastElementsToDictionary(elements, length, dictionary); | 4836 return CopyFastElementsToDictionary(elements, length, dictionary); |
4848 } | 4837 } |
4849 | 4838 |
4850 | 4839 |
4851 Handle<SeededNumberDictionary> JSObject::NormalizeElements( | 4840 Handle<SeededNumberDictionary> JSObject::NormalizeElements( |
4852 Handle<JSObject> object) { | 4841 Handle<JSObject> object) { |
4853 DCHECK(!object->HasExternalArrayElements() && | 4842 DCHECK(!object->HasFixedTypedArrayElements()); |
4854 !object->HasFixedTypedArrayElements()); | |
4855 Isolate* isolate = object->GetIsolate(); | 4843 Isolate* isolate = object->GetIsolate(); |
4856 | 4844 |
4857 // Find the backing store. | 4845 // Find the backing store. |
4858 Handle<FixedArrayBase> elements(object->elements(), isolate); | 4846 Handle<FixedArrayBase> elements(object->elements(), isolate); |
4859 bool is_arguments = object->HasSloppyArgumentsElements(); | 4847 bool is_arguments = object->HasSloppyArgumentsElements(); |
4860 if (is_arguments) { | 4848 if (is_arguments) { |
4861 FixedArray* parameter_map = FixedArray::cast(*elements); | 4849 FixedArray* parameter_map = FixedArray::cast(*elements); |
4862 elements = handle(FixedArrayBase::cast(parameter_map->get(1)), isolate); | 4850 elements = handle(FixedArrayBase::cast(parameter_map->get(1)), isolate); |
4863 } | 4851 } |
4864 | 4852 |
(...skipping 484 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5349 if (!key->IsUndefined()) { | 5337 if (!key->IsUndefined()) { |
5350 return true; | 5338 return true; |
5351 } | 5339 } |
5352 | 5340 |
5353 // Check if the object is among the indexed properties. | 5341 // Check if the object is among the indexed properties. |
5354 ElementsKind kind = GetElementsKind(); | 5342 ElementsKind kind = GetElementsKind(); |
5355 switch (kind) { | 5343 switch (kind) { |
5356 // Raw pixels and external arrays do not reference other | 5344 // Raw pixels and external arrays do not reference other |
5357 // objects. | 5345 // objects. |
5358 #define TYPED_ARRAY_CASE(Type, type, TYPE, ctype, size) \ | 5346 #define TYPED_ARRAY_CASE(Type, type, TYPE, ctype, size) \ |
5359 case EXTERNAL_##TYPE##_ELEMENTS: \ | |
5360 case TYPE##_ELEMENTS: \ | 5347 case TYPE##_ELEMENTS: \ |
5361 break; | 5348 break; |
5362 | 5349 |
5363 TYPED_ARRAYS(TYPED_ARRAY_CASE) | 5350 TYPED_ARRAYS(TYPED_ARRAY_CASE) |
5364 #undef TYPED_ARRAY_CASE | 5351 #undef TYPED_ARRAY_CASE |
5365 | 5352 |
5366 case FAST_DOUBLE_ELEMENTS: | 5353 case FAST_DOUBLE_ELEMENTS: |
5367 case FAST_HOLEY_DOUBLE_ELEMENTS: | 5354 case FAST_HOLEY_DOUBLE_ELEMENTS: |
5368 break; | 5355 break; |
5369 case FAST_SMI_ELEMENTS: | 5356 case FAST_SMI_ELEMENTS: |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5459 | 5446 |
5460 if (object->IsJSGlobalProxy()) { | 5447 if (object->IsJSGlobalProxy()) { |
5461 PrototypeIterator iter(isolate, object); | 5448 PrototypeIterator iter(isolate, object); |
5462 if (iter.IsAtEnd()) return object; | 5449 if (iter.IsAtEnd()) return object; |
5463 DCHECK(PrototypeIterator::GetCurrent(iter)->IsJSGlobalObject()); | 5450 DCHECK(PrototypeIterator::GetCurrent(iter)->IsJSGlobalObject()); |
5464 return PreventExtensions( | 5451 return PreventExtensions( |
5465 Handle<JSObject>::cast(PrototypeIterator::GetCurrent(iter))); | 5452 Handle<JSObject>::cast(PrototypeIterator::GetCurrent(iter))); |
5466 } | 5453 } |
5467 | 5454 |
5468 // It's not possible to seal objects with external array elements | 5455 // It's not possible to seal objects with external array elements |
5469 if (object->HasExternalArrayElements() || | 5456 if (object->HasFixedTypedArrayElements()) { |
5470 object->HasFixedTypedArrayElements()) { | |
5471 THROW_NEW_ERROR( | 5457 THROW_NEW_ERROR( |
5472 isolate, NewTypeError(MessageTemplate::kCannotPreventExtExternalArray), | 5458 isolate, NewTypeError(MessageTemplate::kCannotPreventExtExternalArray), |
5473 Object); | 5459 Object); |
5474 } | 5460 } |
5475 | 5461 |
5476 // If there are fast elements we normalize. | 5462 // If there are fast elements we normalize. |
5477 Handle<SeededNumberDictionary> dictionary = NormalizeElements(object); | 5463 Handle<SeededNumberDictionary> dictionary = NormalizeElements(object); |
5478 DCHECK(object->HasDictionaryElements() || object->HasSlowArgumentsElements()); | 5464 DCHECK(object->HasDictionaryElements() || object->HasSlowArgumentsElements()); |
5479 | 5465 |
5480 // Make sure that we never go back to fast case. | 5466 // Make sure that we never go back to fast case. |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5553 | 5539 |
5554 if (object->IsJSGlobalProxy()) { | 5540 if (object->IsJSGlobalProxy()) { |
5555 PrototypeIterator iter(isolate, object); | 5541 PrototypeIterator iter(isolate, object); |
5556 if (iter.IsAtEnd()) return object; | 5542 if (iter.IsAtEnd()) return object; |
5557 DCHECK(PrototypeIterator::GetCurrent(iter)->IsJSGlobalObject()); | 5543 DCHECK(PrototypeIterator::GetCurrent(iter)->IsJSGlobalObject()); |
5558 return PreventExtensionsWithTransition<attrs>( | 5544 return PreventExtensionsWithTransition<attrs>( |
5559 Handle<JSObject>::cast(PrototypeIterator::GetCurrent(iter))); | 5545 Handle<JSObject>::cast(PrototypeIterator::GetCurrent(iter))); |
5560 } | 5546 } |
5561 | 5547 |
5562 // It's not possible to seal or freeze objects with external array elements | 5548 // It's not possible to seal or freeze objects with external array elements |
5563 if (object->HasExternalArrayElements() || | 5549 if (object->HasFixedTypedArrayElements()) { |
5564 object->HasFixedTypedArrayElements()) { | |
5565 THROW_NEW_ERROR( | 5550 THROW_NEW_ERROR( |
5566 isolate, NewTypeError(MessageTemplate::kCannotPreventExtExternalArray), | 5551 isolate, NewTypeError(MessageTemplate::kCannotPreventExtExternalArray), |
5567 Object); | 5552 Object); |
5568 } | 5553 } |
5569 | 5554 |
5570 Handle<SeededNumberDictionary> new_element_dictionary; | 5555 Handle<SeededNumberDictionary> new_element_dictionary; |
5571 if (!object->HasDictionaryElements()) { | 5556 if (!object->HasDictionaryElements()) { |
5572 int length = | 5557 int length = |
5573 object->IsJSArray() | 5558 object->IsJSArray() |
5574 ? Smi::cast(Handle<JSArray>::cast(object)->length())->value() | 5559 ? Smi::cast(Handle<JSArray>::cast(object)->length())->value() |
(...skipping 248 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5823 if (copying) { | 5808 if (copying) { |
5824 // Creating object copy for literals. No strict mode needed. | 5809 // Creating object copy for literals. No strict mode needed. |
5825 JSObject::SetProperty(copy, key_string, result, SLOPPY).Assert(); | 5810 JSObject::SetProperty(copy, key_string, result, SLOPPY).Assert(); |
5826 } | 5811 } |
5827 } | 5812 } |
5828 } | 5813 } |
5829 } | 5814 } |
5830 | 5815 |
5831 // Deep copy own elements. | 5816 // Deep copy own elements. |
5832 // Pixel elements cannot be created using an object literal. | 5817 // Pixel elements cannot be created using an object literal. |
5833 DCHECK(!copy->HasExternalArrayElements()); | 5818 DCHECK(!copy->HasFixedTypedArrayElements()); |
5834 switch (kind) { | 5819 switch (kind) { |
5835 case FAST_SMI_ELEMENTS: | 5820 case FAST_SMI_ELEMENTS: |
5836 case FAST_ELEMENTS: | 5821 case FAST_ELEMENTS: |
5837 case FAST_HOLEY_SMI_ELEMENTS: | 5822 case FAST_HOLEY_SMI_ELEMENTS: |
5838 case FAST_HOLEY_ELEMENTS: { | 5823 case FAST_HOLEY_ELEMENTS: { |
5839 Handle<FixedArray> elements(FixedArray::cast(copy->elements())); | 5824 Handle<FixedArray> elements(FixedArray::cast(copy->elements())); |
5840 if (elements->map() == isolate->heap()->fixed_cow_array_map()) { | 5825 if (elements->map() == isolate->heap()->fixed_cow_array_map()) { |
5841 #ifdef DEBUG | 5826 #ifdef DEBUG |
5842 for (int i = 0; i < elements->length(); i++) { | 5827 for (int i = 0; i < elements->length(); i++) { |
5843 DCHECK(!elements->get(i)->IsJSObject()); | 5828 DCHECK(!elements->get(i)->IsJSObject()); |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5885 } | 5870 } |
5886 break; | 5871 break; |
5887 } | 5872 } |
5888 case FAST_SLOPPY_ARGUMENTS_ELEMENTS: | 5873 case FAST_SLOPPY_ARGUMENTS_ELEMENTS: |
5889 case SLOW_SLOPPY_ARGUMENTS_ELEMENTS: | 5874 case SLOW_SLOPPY_ARGUMENTS_ELEMENTS: |
5890 UNIMPLEMENTED(); | 5875 UNIMPLEMENTED(); |
5891 break; | 5876 break; |
5892 | 5877 |
5893 | 5878 |
5894 #define TYPED_ARRAY_CASE(Type, type, TYPE, ctype, size) \ | 5879 #define TYPED_ARRAY_CASE(Type, type, TYPE, ctype, size) \ |
5895 case EXTERNAL_##TYPE##_ELEMENTS: \ | |
5896 case TYPE##_ELEMENTS: \ | 5880 case TYPE##_ELEMENTS: \ |
5897 | 5881 |
5898 TYPED_ARRAYS(TYPED_ARRAY_CASE) | 5882 TYPED_ARRAYS(TYPED_ARRAY_CASE) |
5899 #undef TYPED_ARRAY_CASE | 5883 #undef TYPED_ARRAY_CASE |
5900 | 5884 |
5901 case FAST_DOUBLE_ELEMENTS: | 5885 case FAST_DOUBLE_ELEMENTS: |
5902 case FAST_HOLEY_DOUBLE_ELEMENTS: | 5886 case FAST_HOLEY_DOUBLE_ELEMENTS: |
5903 // No contained objects, nothing to do. | 5887 // No contained objects, nothing to do. |
5904 break; | 5888 break; |
5905 } | 5889 } |
(...skipping 382 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6288 if (it.state() == LookupIterator::ACCESS_CHECK) { | 6272 if (it.state() == LookupIterator::ACCESS_CHECK) { |
6289 if (!it.HasAccess()) { | 6273 if (!it.HasAccess()) { |
6290 isolate->ReportFailedAccessCheck(it.GetHolder<JSObject>()); | 6274 isolate->ReportFailedAccessCheck(it.GetHolder<JSObject>()); |
6291 RETURN_EXCEPTION_IF_SCHEDULED_EXCEPTION(isolate, Object); | 6275 RETURN_EXCEPTION_IF_SCHEDULED_EXCEPTION(isolate, Object); |
6292 return isolate->factory()->undefined_value(); | 6276 return isolate->factory()->undefined_value(); |
6293 } | 6277 } |
6294 it.Next(); | 6278 it.Next(); |
6295 } | 6279 } |
6296 | 6280 |
6297 // Ignore accessors on typed arrays. | 6281 // Ignore accessors on typed arrays. |
6298 if (it.IsElement() && (object->HasFixedTypedArrayElements() || | 6282 if (it.IsElement() && object->HasFixedTypedArrayElements()) { |
6299 object->HasExternalArrayElements())) { | |
6300 return it.factory()->undefined_value(); | 6283 return it.factory()->undefined_value(); |
6301 } | 6284 } |
6302 | 6285 |
6303 Handle<Object> old_value = isolate->factory()->the_hole_value(); | 6286 Handle<Object> old_value = isolate->factory()->the_hole_value(); |
6304 bool is_observed = object->map()->is_observed() && | 6287 bool is_observed = object->map()->is_observed() && |
6305 !isolate->IsInternallyUsedPropertyName(name); | 6288 !isolate->IsInternallyUsedPropertyName(name); |
6306 bool preexists = false; | 6289 bool preexists = false; |
6307 if (is_observed) { | 6290 if (is_observed) { |
6308 CHECK(GetPropertyAttributes(&it).IsJust()); | 6291 CHECK(GetPropertyAttributes(&it).IsJust()); |
6309 preexists = it.IsFound(); | 6292 preexists = it.IsFound(); |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6352 if (it.state() == LookupIterator::ACCESS_CHECK) { | 6335 if (it.state() == LookupIterator::ACCESS_CHECK) { |
6353 if (!it.HasAccess()) { | 6336 if (!it.HasAccess()) { |
6354 isolate->ReportFailedAccessCheck(object); | 6337 isolate->ReportFailedAccessCheck(object); |
6355 RETURN_EXCEPTION_IF_SCHEDULED_EXCEPTION(isolate, Object); | 6338 RETURN_EXCEPTION_IF_SCHEDULED_EXCEPTION(isolate, Object); |
6356 return it.factory()->undefined_value(); | 6339 return it.factory()->undefined_value(); |
6357 } | 6340 } |
6358 it.Next(); | 6341 it.Next(); |
6359 } | 6342 } |
6360 | 6343 |
6361 // Ignore accessors on typed arrays. | 6344 // Ignore accessors on typed arrays. |
6362 if (it.IsElement() && (object->HasFixedTypedArrayElements() || | 6345 if (it.IsElement() && object->HasFixedTypedArrayElements()) { |
6363 object->HasExternalArrayElements())) { | |
6364 return it.factory()->undefined_value(); | 6346 return it.factory()->undefined_value(); |
6365 } | 6347 } |
6366 | 6348 |
6367 CHECK(GetPropertyAttributes(&it).IsJust()); | 6349 CHECK(GetPropertyAttributes(&it).IsJust()); |
6368 | 6350 |
6369 // ES5 forbids turning a property into an accessor if it's not | 6351 // ES5 forbids turning a property into an accessor if it's not |
6370 // configurable. See 8.6.1 (Table 5). | 6352 // configurable. See 8.6.1 (Table 5). |
6371 if (it.IsFound() && !it.IsConfigurable()) { | 6353 if (it.IsFound() && !it.IsConfigurable()) { |
6372 return it.factory()->undefined_value(); | 6354 return it.factory()->undefined_value(); |
6373 } | 6355 } |
(...skipping 396 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6770 | 6752 |
6771 return result; | 6753 return result; |
6772 } | 6754 } |
6773 | 6755 |
6774 | 6756 |
6775 Handle<Map> Map::CopyAsElementsKind(Handle<Map> map, ElementsKind kind, | 6757 Handle<Map> Map::CopyAsElementsKind(Handle<Map> map, ElementsKind kind, |
6776 TransitionFlag flag) { | 6758 TransitionFlag flag) { |
6777 Map* maybe_elements_transition_map = NULL; | 6759 Map* maybe_elements_transition_map = NULL; |
6778 if (flag == INSERT_TRANSITION) { | 6760 if (flag == INSERT_TRANSITION) { |
6779 maybe_elements_transition_map = map->ElementsTransitionMap(); | 6761 maybe_elements_transition_map = map->ElementsTransitionMap(); |
6780 DCHECK( | 6762 DCHECK(maybe_elements_transition_map == NULL || |
6781 maybe_elements_transition_map == NULL || | 6763 (maybe_elements_transition_map->elements_kind() == |
6782 ((maybe_elements_transition_map->elements_kind() == | 6764 DICTIONARY_ELEMENTS && |
6783 DICTIONARY_ELEMENTS || | 6765 kind == DICTIONARY_ELEMENTS)); |
6784 IsExternalArrayElementsKind( | |
6785 maybe_elements_transition_map->elements_kind())) && | |
6786 (kind == DICTIONARY_ELEMENTS || IsExternalArrayElementsKind(kind)))); | |
6787 DCHECK(!IsFastElementsKind(kind) || | 6766 DCHECK(!IsFastElementsKind(kind) || |
6788 IsMoreGeneralElementsKindTransition(map->elements_kind(), kind)); | 6767 IsMoreGeneralElementsKindTransition(map->elements_kind(), kind)); |
6789 DCHECK(kind != map->elements_kind()); | 6768 DCHECK(kind != map->elements_kind()); |
6790 } | 6769 } |
6791 | 6770 |
6792 bool insert_transition = flag == INSERT_TRANSITION && | 6771 bool insert_transition = flag == INSERT_TRANSITION && |
6793 TransitionArray::CanHaveMoreTransitions(map) && | 6772 TransitionArray::CanHaveMoreTransitions(map) && |
6794 maybe_elements_transition_map == NULL; | 6773 maybe_elements_transition_map == NULL; |
6795 | 6774 |
6796 if (insert_transition) { | 6775 if (insert_transition) { |
(...skipping 5795 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
12592 case FAST_HOLEY_SMI_ELEMENTS: | 12571 case FAST_HOLEY_SMI_ELEMENTS: |
12593 case FAST_HOLEY_ELEMENTS: | 12572 case FAST_HOLEY_ELEMENTS: |
12594 return FastHoleyElementsUsage(this, FixedArray::cast(store)); | 12573 return FastHoleyElementsUsage(this, FixedArray::cast(store)); |
12595 case FAST_HOLEY_DOUBLE_ELEMENTS: | 12574 case FAST_HOLEY_DOUBLE_ELEMENTS: |
12596 if (elements()->length() == 0) return 0; | 12575 if (elements()->length() == 0) return 0; |
12597 return FastHoleyElementsUsage(this, FixedDoubleArray::cast(store)); | 12576 return FastHoleyElementsUsage(this, FixedDoubleArray::cast(store)); |
12598 | 12577 |
12599 case SLOW_SLOPPY_ARGUMENTS_ELEMENTS: | 12578 case SLOW_SLOPPY_ARGUMENTS_ELEMENTS: |
12600 case DICTIONARY_ELEMENTS: | 12579 case DICTIONARY_ELEMENTS: |
12601 #define TYPED_ARRAY_CASE(Type, type, TYPE, ctype, size) \ | 12580 #define TYPED_ARRAY_CASE(Type, type, TYPE, ctype, size) \ |
12602 case EXTERNAL_##TYPE##_ELEMENTS: \ | |
12603 case TYPE##_ELEMENTS: \ | 12581 case TYPE##_ELEMENTS: \ |
12604 | 12582 |
12605 TYPED_ARRAYS(TYPED_ARRAY_CASE) | 12583 TYPED_ARRAYS(TYPED_ARRAY_CASE) |
12606 #undef TYPED_ARRAY_CASE | 12584 #undef TYPED_ARRAY_CASE |
12607 UNREACHABLE(); | 12585 UNREACHABLE(); |
12608 } | 12586 } |
12609 return 0; | 12587 return 0; |
12610 } | 12588 } |
12611 | 12589 |
12612 | 12590 |
(...skipping 413 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
13026 storage->set(counter, Smi::FromInt(i)); | 13004 storage->set(counter, Smi::FromInt(i)); |
13027 } | 13005 } |
13028 counter++; | 13006 counter++; |
13029 } | 13007 } |
13030 } | 13008 } |
13031 DCHECK(!storage || storage->length() >= counter); | 13009 DCHECK(!storage || storage->length() >= counter); |
13032 break; | 13010 break; |
13033 } | 13011 } |
13034 | 13012 |
13035 #define TYPED_ARRAY_CASE(Type, type, TYPE, ctype, size) \ | 13013 #define TYPED_ARRAY_CASE(Type, type, TYPE, ctype, size) \ |
13036 case EXTERNAL_##TYPE##_ELEMENTS: \ | |
13037 case TYPE##_ELEMENTS: \ | 13014 case TYPE##_ELEMENTS: \ |
13038 | 13015 |
13039 TYPED_ARRAYS(TYPED_ARRAY_CASE) | 13016 TYPED_ARRAYS(TYPED_ARRAY_CASE) |
13040 #undef TYPED_ARRAY_CASE | 13017 #undef TYPED_ARRAY_CASE |
13041 { | 13018 { |
13042 int length = FixedArrayBase::cast(elements())->length(); | 13019 int length = FixedArrayBase::cast(elements())->length(); |
13043 while (counter < length) { | 13020 while (counter < length) { |
13044 if (storage != NULL) { | 13021 if (storage != NULL) { |
13045 storage->set(counter, Smi::FromInt(counter)); | 13022 storage->set(counter, Smi::FromInt(counter)); |
13046 } | 13023 } |
(...skipping 801 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
13848 JSObject::GetElementsTransitionMap(object, FAST_HOLEY_ELEMENTS); | 13825 JSObject::GetElementsTransitionMap(object, FAST_HOLEY_ELEMENTS); |
13849 | 13826 |
13850 PretenureFlag tenure = isolate->heap()->InNewSpace(*object) ? | 13827 PretenureFlag tenure = isolate->heap()->InNewSpace(*object) ? |
13851 NOT_TENURED: TENURED; | 13828 NOT_TENURED: TENURED; |
13852 Handle<FixedArray> fast_elements = | 13829 Handle<FixedArray> fast_elements = |
13853 isolate->factory()->NewFixedArray(dict->NumberOfElements(), tenure); | 13830 isolate->factory()->NewFixedArray(dict->NumberOfElements(), tenure); |
13854 dict->CopyValuesTo(*fast_elements); | 13831 dict->CopyValuesTo(*fast_elements); |
13855 JSObject::ValidateElements(object); | 13832 JSObject::ValidateElements(object); |
13856 | 13833 |
13857 JSObject::SetMapAndElements(object, new_map, fast_elements); | 13834 JSObject::SetMapAndElements(object, new_map, fast_elements); |
13858 } else if (object->HasExternalArrayElements() || | 13835 } else if (object->HasFixedTypedArrayElements()) { |
13859 object->HasFixedTypedArrayElements()) { | |
13860 // Typed arrays cannot have holes or undefined elements. | 13836 // Typed arrays cannot have holes or undefined elements. |
13861 return handle(Smi::FromInt( | 13837 return handle(Smi::FromInt( |
13862 FixedArrayBase::cast(object->elements())->length()), isolate); | 13838 FixedArrayBase::cast(object->elements())->length()), isolate); |
13863 } else if (!object->HasFastDoubleElements()) { | 13839 } else if (!object->HasFastDoubleElements()) { |
13864 EnsureWritableFastElements(object); | 13840 EnsureWritableFastElements(object); |
13865 } | 13841 } |
13866 DCHECK(object->HasFastSmiOrObjectElements() || | 13842 DCHECK(object->HasFastSmiOrObjectElements() || |
13867 object->HasFastDoubleElements()); | 13843 object->HasFastDoubleElements()); |
13868 | 13844 |
13869 // Collect holes at the end, undefined before that and the rest at the | 13845 // Collect holes at the end, undefined before that and the rest at the |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
13952 } | 13928 } |
13953 } | 13929 } |
13954 | 13930 |
13955 return isolate->factory()->NewNumberFromUint(result); | 13931 return isolate->factory()->NewNumberFromUint(result); |
13956 } | 13932 } |
13957 | 13933 |
13958 | 13934 |
13959 ExternalArrayType JSTypedArray::type() { | 13935 ExternalArrayType JSTypedArray::type() { |
13960 switch (elements()->map()->instance_type()) { | 13936 switch (elements()->map()->instance_type()) { |
13961 #define INSTANCE_TYPE_TO_ARRAY_TYPE(Type, type, TYPE, ctype, size) \ | 13937 #define INSTANCE_TYPE_TO_ARRAY_TYPE(Type, type, TYPE, ctype, size) \ |
13962 case EXTERNAL_##TYPE##_ARRAY_TYPE: \ | |
13963 case FIXED_##TYPE##_ARRAY_TYPE: \ | 13938 case FIXED_##TYPE##_ARRAY_TYPE: \ |
13964 return kExternal##Type##Array; | 13939 return kExternal##Type##Array; |
13965 | 13940 |
13966 TYPED_ARRAYS(INSTANCE_TYPE_TO_ARRAY_TYPE) | 13941 TYPED_ARRAYS(INSTANCE_TYPE_TO_ARRAY_TYPE) |
13967 #undef INSTANCE_TYPE_TO_ARRAY_TYPE | 13942 #undef INSTANCE_TYPE_TO_ARRAY_TYPE |
13968 | 13943 |
13969 default: | 13944 default: |
13970 UNREACHABLE(); | 13945 UNREACHABLE(); |
13971 return static_cast<ExternalArrayType>(-1); | 13946 return static_cast<ExternalArrayType>(-1); |
13972 } | 13947 } |
13973 } | 13948 } |
13974 | 13949 |
13975 | 13950 |
13976 size_t JSTypedArray::element_size() { | 13951 size_t JSTypedArray::element_size() { |
13977 switch (elements()->map()->instance_type()) { | 13952 switch (elements()->map()->instance_type()) { |
13978 #define INSTANCE_TYPE_TO_ELEMENT_SIZE(Type, type, TYPE, ctype, size) \ | 13953 #define INSTANCE_TYPE_TO_ELEMENT_SIZE(Type, type, TYPE, ctype, size) \ |
13979 case EXTERNAL_##TYPE##_ARRAY_TYPE: \ | 13954 case FIXED_##TYPE##_ARRAY_TYPE: \ |
13980 return size; | 13955 return size; |
13981 | 13956 |
13982 TYPED_ARRAYS(INSTANCE_TYPE_TO_ELEMENT_SIZE) | 13957 TYPED_ARRAYS(INSTANCE_TYPE_TO_ELEMENT_SIZE) |
13983 #undef INSTANCE_TYPE_TO_ELEMENT_SIZE | 13958 #undef INSTANCE_TYPE_TO_ELEMENT_SIZE |
13984 | 13959 |
13985 default: | 13960 default: |
13986 UNREACHABLE(); | 13961 UNREACHABLE(); |
13987 return 0; | 13962 return 0; |
13988 } | 13963 } |
13989 } | 13964 } |
13990 | 13965 |
13991 | 13966 |
13992 void FixedArray::SetValue(uint32_t index, Object* value) { set(index, value); } | 13967 void FixedArray::SetValue(uint32_t index, Object* value) { set(index, value); } |
13993 | 13968 |
13994 | 13969 |
13995 void FixedDoubleArray::SetValue(uint32_t index, Object* value) { | 13970 void FixedDoubleArray::SetValue(uint32_t index, Object* value) { |
13996 set(index, value->Number()); | 13971 set(index, value->Number()); |
13997 } | 13972 } |
13998 | |
13999 | |
14000 void ExternalUint8ClampedArray::SetValue(uint32_t index, Object* value) { | |
14001 uint8_t clamped_value = 0; | |
14002 if (value->IsSmi()) { | |
14003 int int_value = Smi::cast(value)->value(); | |
14004 if (int_value < 0) { | |
14005 clamped_value = 0; | |
14006 } else if (int_value > 255) { | |
14007 clamped_value = 255; | |
14008 } else { | |
14009 clamped_value = static_cast<uint8_t>(int_value); | |
14010 } | |
14011 } else if (value->IsHeapNumber()) { | |
14012 double double_value = HeapNumber::cast(value)->value(); | |
14013 if (!(double_value > 0)) { | |
14014 // NaN and less than zero clamp to zero. | |
14015 clamped_value = 0; | |
14016 } else if (double_value > 255) { | |
14017 // Greater than 255 clamp to 255. | |
14018 clamped_value = 255; | |
14019 } else { | |
14020 // Other doubles are rounded to the nearest integer. | |
14021 clamped_value = static_cast<uint8_t>(lrint(double_value)); | |
14022 } | |
14023 } else { | |
14024 // Clamp undefined to zero (default). All other types have been | |
14025 // converted to a number type further up in the call chain. | |
14026 DCHECK(value->IsUndefined()); | |
14027 } | |
14028 set(index, clamped_value); | |
14029 } | |
14030 | |
14031 | |
14032 template <typename ExternalArrayClass, typename ValueType> | |
14033 static void ExternalArrayIntSetter(ExternalArrayClass* receiver, uint32_t index, | |
14034 Object* value) { | |
14035 ValueType cast_value = 0; | |
14036 if (value->IsSmi()) { | |
14037 int int_value = Smi::cast(value)->value(); | |
14038 cast_value = static_cast<ValueType>(int_value); | |
14039 } else if (value->IsHeapNumber()) { | |
14040 double double_value = HeapNumber::cast(value)->value(); | |
14041 cast_value = static_cast<ValueType>(DoubleToInt32(double_value)); | |
14042 } else { | |
14043 // Clamp undefined to zero (default). All other types have been | |
14044 // converted to a number type further up in the call chain. | |
14045 DCHECK(value->IsUndefined()); | |
14046 } | |
14047 receiver->set(index, cast_value); | |
14048 } | |
14049 | |
14050 | |
14051 void ExternalInt8Array::SetValue(uint32_t index, Object* value) { | |
14052 ExternalArrayIntSetter<ExternalInt8Array, int8_t>(this, index, value); | |
14053 } | |
14054 | |
14055 | |
14056 void ExternalUint8Array::SetValue(uint32_t index, Object* value) { | |
14057 ExternalArrayIntSetter<ExternalUint8Array, uint8_t>(this, index, value); | |
14058 } | |
14059 | |
14060 | |
14061 void ExternalInt16Array::SetValue(uint32_t index, Object* value) { | |
14062 ExternalArrayIntSetter<ExternalInt16Array, int16_t>(this, index, value); | |
14063 } | |
14064 | |
14065 | |
14066 void ExternalUint16Array::SetValue(uint32_t index, Object* value) { | |
14067 ExternalArrayIntSetter<ExternalUint16Array, uint16_t>(this, index, value); | |
14068 } | |
14069 | |
14070 | |
14071 void ExternalInt32Array::SetValue(uint32_t index, Object* value) { | |
14072 ExternalArrayIntSetter<ExternalInt32Array, int32_t>(this, index, value); | |
14073 } | |
14074 | |
14075 | |
14076 void ExternalUint32Array::SetValue(uint32_t index, Object* value) { | |
14077 uint32_t cast_value = 0; | |
14078 if (value->IsSmi()) { | |
14079 int int_value = Smi::cast(value)->value(); | |
14080 cast_value = static_cast<uint32_t>(int_value); | |
14081 } else if (value->IsHeapNumber()) { | |
14082 double double_value = HeapNumber::cast(value)->value(); | |
14083 cast_value = static_cast<uint32_t>(DoubleToUint32(double_value)); | |
14084 } else { | |
14085 // Clamp undefined to zero (default). All other types have been | |
14086 // converted to a number type further up in the call chain. | |
14087 DCHECK(value->IsUndefined()); | |
14088 } | |
14089 set(index, cast_value); | |
14090 } | |
14091 | |
14092 | |
14093 void ExternalFloat32Array::SetValue(uint32_t index, Object* value) { | |
14094 float cast_value = std::numeric_limits<float>::quiet_NaN(); | |
14095 if (value->IsSmi()) { | |
14096 int int_value = Smi::cast(value)->value(); | |
14097 cast_value = static_cast<float>(int_value); | |
14098 } else if (value->IsHeapNumber()) { | |
14099 double double_value = HeapNumber::cast(value)->value(); | |
14100 cast_value = static_cast<float>(double_value); | |
14101 } else { | |
14102 // Clamp undefined to NaN (default). All other types have been | |
14103 // converted to a number type further up in the call chain. | |
14104 DCHECK(value->IsUndefined()); | |
14105 } | |
14106 set(index, cast_value); | |
14107 } | |
14108 | |
14109 | |
14110 void ExternalFloat64Array::SetValue(uint32_t index, Object* value) { | |
14111 double double_value = std::numeric_limits<double>::quiet_NaN(); | |
14112 if (value->IsNumber()) { | |
14113 double_value = value->Number(); | |
14114 } else { | |
14115 // Clamp undefined to NaN (default). All other types have been | |
14116 // converted to a number type further up in the call chain. | |
14117 DCHECK(value->IsUndefined()); | |
14118 } | |
14119 set(index, double_value); | |
14120 } | |
14121 | |
14122 | |
14123 void GlobalObject::InvalidatePropertyCell(Handle<GlobalObject> global, | 13973 void GlobalObject::InvalidatePropertyCell(Handle<GlobalObject> global, |
14124 Handle<Name> name) { | 13974 Handle<Name> name) { |
14125 DCHECK(!global->HasFastProperties()); | 13975 DCHECK(!global->HasFastProperties()); |
14126 auto dictionary = handle(global->global_dictionary()); | 13976 auto dictionary = handle(global->global_dictionary()); |
14127 int entry = dictionary->FindEntry(name); | 13977 int entry = dictionary->FindEntry(name); |
14128 if (entry == GlobalDictionary::kNotFound) return; | 13978 if (entry == GlobalDictionary::kNotFound) return; |
14129 PropertyCell::InvalidateEntry(dictionary, entry); | 13979 PropertyCell::InvalidateEntry(dictionary, entry); |
14130 } | 13980 } |
14131 | 13981 |
14132 | 13982 |
(...skipping 1591 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
15724 | 15574 |
15725 void JSArrayBuffer::Neuter() { | 15575 void JSArrayBuffer::Neuter() { |
15726 CHECK(is_neuterable()); | 15576 CHECK(is_neuterable()); |
15727 CHECK(is_external()); | 15577 CHECK(is_external()); |
15728 set_backing_store(NULL); | 15578 set_backing_store(NULL); |
15729 set_byte_length(Smi::FromInt(0)); | 15579 set_byte_length(Smi::FromInt(0)); |
15730 set_was_neutered(true); | 15580 set_was_neutered(true); |
15731 } | 15581 } |
15732 | 15582 |
15733 | 15583 |
15734 static ElementsKind FixedToExternalElementsKind(ElementsKind elements_kind) { | |
15735 switch (elements_kind) { | |
15736 #define TYPED_ARRAY_CASE(Type, type, TYPE, ctype, size) \ | |
15737 case TYPE##_ELEMENTS: return EXTERNAL_##TYPE##_ELEMENTS; | |
15738 | |
15739 TYPED_ARRAYS(TYPED_ARRAY_CASE) | |
15740 #undef TYPED_ARRAY_CASE | |
15741 | |
15742 default: | |
15743 UNREACHABLE(); | |
15744 return FIRST_EXTERNAL_ARRAY_ELEMENTS_KIND; | |
15745 } | |
15746 } | |
15747 | |
15748 | |
15749 Handle<JSArrayBuffer> JSTypedArray::MaterializeArrayBuffer( | 15584 Handle<JSArrayBuffer> JSTypedArray::MaterializeArrayBuffer( |
15750 Handle<JSTypedArray> typed_array) { | 15585 Handle<JSTypedArray> typed_array) { |
15751 | 15586 |
15752 Handle<Map> map(typed_array->map()); | 15587 Handle<Map> map(typed_array->map()); |
15753 Isolate* isolate = typed_array->GetIsolate(); | 15588 Isolate* isolate = typed_array->GetIsolate(); |
15754 | 15589 |
15755 DCHECK(IsFixedTypedArrayElementsKind(map->elements_kind())); | 15590 DCHECK(IsFixedTypedArrayElementsKind(map->elements_kind())); |
15756 | 15591 |
15757 Handle<Map> new_map = Map::TransitionElementsTo( | |
15758 map, | |
15759 FixedToExternalElementsKind(map->elements_kind())); | |
15760 | |
15761 Handle<FixedTypedArrayBase> fixed_typed_array( | 15592 Handle<FixedTypedArrayBase> fixed_typed_array( |
15762 FixedTypedArrayBase::cast(typed_array->elements())); | 15593 FixedTypedArrayBase::cast(typed_array->elements())); |
15763 | 15594 |
15764 Handle<JSArrayBuffer> buffer(JSArrayBuffer::cast(typed_array->buffer()), | 15595 Handle<JSArrayBuffer> buffer(JSArrayBuffer::cast(typed_array->buffer()), |
15765 isolate); | 15596 isolate); |
15766 void* backing_store = | 15597 void* backing_store = |
15767 isolate->array_buffer_allocator()->AllocateUninitialized( | 15598 isolate->array_buffer_allocator()->AllocateUninitialized( |
15768 fixed_typed_array->DataSize()); | 15599 fixed_typed_array->DataSize()); |
15769 buffer->set_backing_store(backing_store); | 15600 buffer->set_backing_store(backing_store); |
15770 buffer->set_is_external(false); | 15601 buffer->set_is_external(false); |
15771 isolate->heap()->RegisterNewArrayBuffer(isolate->heap()->InNewSpace(*buffer), | 15602 isolate->heap()->RegisterNewArrayBuffer(isolate->heap()->InNewSpace(*buffer), |
15772 backing_store, | 15603 backing_store, |
15773 fixed_typed_array->DataSize()); | 15604 fixed_typed_array->DataSize()); |
15774 memcpy(buffer->backing_store(), | 15605 memcpy(buffer->backing_store(), |
15775 fixed_typed_array->DataPtr(), | 15606 fixed_typed_array->DataPtr(), |
15776 fixed_typed_array->DataSize()); | 15607 fixed_typed_array->DataSize()); |
15777 Handle<ExternalArray> new_elements = | 15608 Handle<FixedTypedArrayBase> new_elements = |
15778 isolate->factory()->NewExternalArray( | 15609 isolate->factory()->NewFixedTypedArrayWithExternalPointer( |
15779 fixed_typed_array->length(), typed_array->type(), | 15610 fixed_typed_array->length(), typed_array->type(), |
15780 static_cast<uint8_t*>(buffer->backing_store())); | 15611 static_cast<uint8_t*>(buffer->backing_store())); |
15781 | 15612 |
15782 JSObject::SetMapAndElements(typed_array, new_map, new_elements); | 15613 typed_array->set_elements(*new_elements); |
15783 | 15614 |
15784 return buffer; | 15615 return buffer; |
15785 } | 15616 } |
15786 | 15617 |
15787 | 15618 |
15788 Handle<JSArrayBuffer> JSTypedArray::GetBuffer() { | 15619 Handle<JSArrayBuffer> JSTypedArray::GetBuffer() { |
15789 if (IsExternalArrayElementsKind(map()->elements_kind())) { | 15620 Handle<JSArrayBuffer> array_buffer(JSArrayBuffer::cast(buffer()), |
15790 Handle<Object> result(buffer(), GetIsolate()); | 15621 GetIsolate()); |
15791 return Handle<JSArrayBuffer>::cast(result); | 15622 if (array_buffer->was_neutered() || |
| 15623 array_buffer->backing_store() != nullptr) { |
| 15624 return array_buffer; |
15792 } | 15625 } |
15793 Handle<JSTypedArray> self(this); | 15626 Handle<JSTypedArray> self(this); |
15794 return MaterializeArrayBuffer(self); | 15627 return MaterializeArrayBuffer(self); |
15795 } | 15628 } |
15796 | 15629 |
15797 | 15630 |
15798 Handle<PropertyCell> PropertyCell::InvalidateEntry( | 15631 Handle<PropertyCell> PropertyCell::InvalidateEntry( |
15799 Handle<GlobalDictionary> dictionary, int entry) { | 15632 Handle<GlobalDictionary> dictionary, int entry) { |
15800 Isolate* isolate = dictionary->GetIsolate(); | 15633 Isolate* isolate = dictionary->GetIsolate(); |
15801 // Swap with a copy. | 15634 // Swap with a copy. |
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
15927 if (cell->value() != *new_value) { | 15760 if (cell->value() != *new_value) { |
15928 cell->set_value(*new_value); | 15761 cell->set_value(*new_value); |
15929 Isolate* isolate = cell->GetIsolate(); | 15762 Isolate* isolate = cell->GetIsolate(); |
15930 cell->dependent_code()->DeoptimizeDependentCodeGroup( | 15763 cell->dependent_code()->DeoptimizeDependentCodeGroup( |
15931 isolate, DependentCode::kPropertyCellChangedGroup); | 15764 isolate, DependentCode::kPropertyCellChangedGroup); |
15932 } | 15765 } |
15933 } | 15766 } |
15934 | 15767 |
15935 } // namespace internal | 15768 } // namespace internal |
15936 } // namespace v8 | 15769 } // namespace v8 |
OLD | NEW |