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