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 "v8.h" | 5 #include "v8.h" |
6 | 6 |
7 #include "accessors.h" | 7 #include "accessors.h" |
8 #include "allocation-site-scopes.h" | 8 #include "allocation-site-scopes.h" |
9 #include "api.h" | 9 #include "api.h" |
10 #include "arguments.h" | 10 #include "arguments.h" |
(...skipping 13223 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
13234 if (FLAG_trace_external_array_abuse && | 13234 if (FLAG_trace_external_array_abuse && |
13235 IsExternalArrayElementsKind(object->GetElementsKind())) { | 13235 IsExternalArrayElementsKind(object->GetElementsKind())) { |
13236 CheckArrayAbuse(object, "external elements write", index); | 13236 CheckArrayAbuse(object, "external elements write", index); |
13237 } | 13237 } |
13238 if (FLAG_trace_js_array_abuse && | 13238 if (FLAG_trace_js_array_abuse && |
13239 !IsExternalArrayElementsKind(object->GetElementsKind())) { | 13239 !IsExternalArrayElementsKind(object->GetElementsKind())) { |
13240 if (object->IsJSArray()) { | 13240 if (object->IsJSArray()) { |
13241 CheckArrayAbuse(object, "elements write", index, true); | 13241 CheckArrayAbuse(object, "elements write", index, true); |
13242 } | 13242 } |
13243 } | 13243 } |
| 13244 if (object->IsJSArray() && JSArray::ChangeOfReadOnlyLength( |
| 13245 Handle<JSArray>::cast(object), index)) { |
| 13246 if (strict_mode == SLOPPY) { |
| 13247 return value; |
| 13248 } else { |
| 13249 return JSArray::ReadOnlyLengthError(Handle<JSArray>::cast(object)); |
| 13250 } |
| 13251 } |
13244 switch (object->GetElementsKind()) { | 13252 switch (object->GetElementsKind()) { |
13245 case FAST_SMI_ELEMENTS: | 13253 case FAST_SMI_ELEMENTS: |
13246 case FAST_ELEMENTS: | 13254 case FAST_ELEMENTS: |
13247 case FAST_HOLEY_SMI_ELEMENTS: | 13255 case FAST_HOLEY_SMI_ELEMENTS: |
13248 case FAST_HOLEY_ELEMENTS: | 13256 case FAST_HOLEY_ELEMENTS: |
13249 return SetFastElement(object, index, value, strict_mode, check_prototype); | 13257 return SetFastElement(object, index, value, strict_mode, check_prototype); |
13250 case FAST_DOUBLE_ELEMENTS: | 13258 case FAST_DOUBLE_ELEMENTS: |
13251 case FAST_HOLEY_DOUBLE_ELEMENTS: | 13259 case FAST_HOLEY_DOUBLE_ELEMENTS: |
13252 return SetFastDoubleElement(object, index, value, strict_mode, | 13260 return SetFastDoubleElement(object, index, value, strict_mode, |
13253 check_prototype); | 13261 check_prototype); |
(...skipping 265 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
13519 // Check to see if we need to update the length. For now, we make | 13527 // Check to see if we need to update the length. For now, we make |
13520 // sure that the length stays within 32-bits (unsigned). | 13528 // sure that the length stays within 32-bits (unsigned). |
13521 if (index >= old_len && index != 0xffffffff) { | 13529 if (index >= old_len && index != 0xffffffff) { |
13522 Handle<Object> len = array->GetIsolate()->factory()->NewNumber( | 13530 Handle<Object> len = array->GetIsolate()->factory()->NewNumber( |
13523 static_cast<double>(index) + 1); | 13531 static_cast<double>(index) + 1); |
13524 array->set_length(*len); | 13532 array->set_length(*len); |
13525 } | 13533 } |
13526 } | 13534 } |
13527 | 13535 |
13528 | 13536 |
| 13537 bool JSArray::IsReadOnlyLengthDescriptor(Handle<Map> jsarray_map) { |
| 13538 Isolate* isolate = jsarray_map->GetIsolate(); |
| 13539 ASSERT(!jsarray_map->is_dictionary_map()); |
| 13540 LookupResult lookup(isolate); |
| 13541 Handle<Name> length_string = isolate->factory()->length_string(); |
| 13542 jsarray_map->LookupDescriptor(NULL, *length_string, &lookup); |
| 13543 return lookup.IsReadOnly(); |
| 13544 } |
| 13545 |
| 13546 |
| 13547 bool JSArray::ChangeOfReadOnlyLength(Handle<JSArray> array, |
| 13548 uint32_t index) { |
| 13549 int length = Smi::cast(array->length())->value(); |
| 13550 if (length < 0 || static_cast<uint32_t>(length) <= index) { |
| 13551 Isolate* isolate = array->GetIsolate(); |
| 13552 LookupResult lookup(isolate); |
| 13553 Handle<Name> length_string = isolate->factory()->length_string(); |
| 13554 array->LocalLookupRealNamedProperty(length_string, &lookup); |
| 13555 return lookup.IsReadOnly(); |
| 13556 } |
| 13557 return false; |
| 13558 } |
| 13559 |
| 13560 |
| 13561 MaybeHandle<Object> JSArray::ReadOnlyLengthError(Handle<JSArray> array) { |
| 13562 Isolate* isolate = array->GetIsolate(); |
| 13563 Handle<Name> length = isolate->factory()->length_string(); |
| 13564 Handle<Object> args[2] = { length, array }; |
| 13565 Handle<Object> error = isolate->factory()->NewTypeError( |
| 13566 "strict_read_only_property", HandleVector(args, ARRAY_SIZE(args))); |
| 13567 return isolate->Throw<Object>(error); |
| 13568 } |
| 13569 |
| 13570 |
13529 MaybeHandle<Object> JSObject::GetElementWithInterceptor( | 13571 MaybeHandle<Object> JSObject::GetElementWithInterceptor( |
13530 Handle<JSObject> object, | 13572 Handle<JSObject> object, |
13531 Handle<Object> receiver, | 13573 Handle<Object> receiver, |
13532 uint32_t index) { | 13574 uint32_t index) { |
13533 Isolate* isolate = object->GetIsolate(); | 13575 Isolate* isolate = object->GetIsolate(); |
13534 | 13576 |
13535 // Make sure that the top context does not change when doing | 13577 // Make sure that the top context does not change when doing |
13536 // callbacks or interceptor calls. | 13578 // callbacks or interceptor calls. |
13537 AssertNoContextChange ncc(isolate); | 13579 AssertNoContextChange ncc(isolate); |
13538 | 13580 |
(...skipping 3737 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
17276 #define ERROR_MESSAGES_TEXTS(C, T) T, | 17318 #define ERROR_MESSAGES_TEXTS(C, T) T, |
17277 static const char* error_messages_[] = { | 17319 static const char* error_messages_[] = { |
17278 ERROR_MESSAGES_LIST(ERROR_MESSAGES_TEXTS) | 17320 ERROR_MESSAGES_LIST(ERROR_MESSAGES_TEXTS) |
17279 }; | 17321 }; |
17280 #undef ERROR_MESSAGES_TEXTS | 17322 #undef ERROR_MESSAGES_TEXTS |
17281 return error_messages_[reason]; | 17323 return error_messages_[reason]; |
17282 } | 17324 } |
17283 | 17325 |
17284 | 17326 |
17285 } } // namespace v8::internal | 17327 } } // namespace v8::internal |
OLD | NEW |