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

Side by Side Diff: src/objects.cc

Issue 279773002: Fix Array.prototype.push and Array.prototype.unshift for read-only length. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Whitespace Created 6 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « src/objects.h ('k') | test/mjsunit/array-push-unshift-read-only-length.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 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 13221 matching lines...) Expand 10 before | Expand all | Expand 10 after
13232 if (FLAG_trace_external_array_abuse && 13232 if (FLAG_trace_external_array_abuse &&
13233 IsExternalArrayElementsKind(object->GetElementsKind())) { 13233 IsExternalArrayElementsKind(object->GetElementsKind())) {
13234 CheckArrayAbuse(object, "external elements write", index); 13234 CheckArrayAbuse(object, "external elements write", index);
13235 } 13235 }
13236 if (FLAG_trace_js_array_abuse && 13236 if (FLAG_trace_js_array_abuse &&
13237 !IsExternalArrayElementsKind(object->GetElementsKind())) { 13237 !IsExternalArrayElementsKind(object->GetElementsKind())) {
13238 if (object->IsJSArray()) { 13238 if (object->IsJSArray()) {
13239 CheckArrayAbuse(object, "elements write", index, true); 13239 CheckArrayAbuse(object, "elements write", index, true);
13240 } 13240 }
13241 } 13241 }
13242 if (object->IsJSArray() && JSArray::WouldChangeReadOnlyLength(
13243 Handle<JSArray>::cast(object), index)) {
13244 if (strict_mode == SLOPPY) {
13245 return value;
13246 } else {
13247 return JSArray::ReadOnlyLengthError(Handle<JSArray>::cast(object));
13248 }
13249 }
13242 switch (object->GetElementsKind()) { 13250 switch (object->GetElementsKind()) {
13243 case FAST_SMI_ELEMENTS: 13251 case FAST_SMI_ELEMENTS:
13244 case FAST_ELEMENTS: 13252 case FAST_ELEMENTS:
13245 case FAST_HOLEY_SMI_ELEMENTS: 13253 case FAST_HOLEY_SMI_ELEMENTS:
13246 case FAST_HOLEY_ELEMENTS: 13254 case FAST_HOLEY_ELEMENTS:
13247 return SetFastElement(object, index, value, strict_mode, check_prototype); 13255 return SetFastElement(object, index, value, strict_mode, check_prototype);
13248 case FAST_DOUBLE_ELEMENTS: 13256 case FAST_DOUBLE_ELEMENTS:
13249 case FAST_HOLEY_DOUBLE_ELEMENTS: 13257 case FAST_HOLEY_DOUBLE_ELEMENTS:
13250 return SetFastDoubleElement(object, index, value, strict_mode, 13258 return SetFastDoubleElement(object, index, value, strict_mode,
13251 check_prototype); 13259 check_prototype);
(...skipping 265 matching lines...) Expand 10 before | Expand all | Expand 10 after
13517 // Check to see if we need to update the length. For now, we make 13525 // Check to see if we need to update the length. For now, we make
13518 // sure that the length stays within 32-bits (unsigned). 13526 // sure that the length stays within 32-bits (unsigned).
13519 if (index >= old_len && index != 0xffffffff) { 13527 if (index >= old_len && index != 0xffffffff) {
13520 Handle<Object> len = array->GetIsolate()->factory()->NewNumber( 13528 Handle<Object> len = array->GetIsolate()->factory()->NewNumber(
13521 static_cast<double>(index) + 1); 13529 static_cast<double>(index) + 1);
13522 array->set_length(*len); 13530 array->set_length(*len);
13523 } 13531 }
13524 } 13532 }
13525 13533
13526 13534
13535 bool JSArray::IsReadOnlyLengthDescriptor(Handle<Map> jsarray_map) {
13536 Isolate* isolate = jsarray_map->GetIsolate();
13537 ASSERT(!jsarray_map->is_dictionary_map());
13538 LookupResult lookup(isolate);
13539 Handle<Name> length_string = isolate->factory()->length_string();
13540 jsarray_map->LookupDescriptor(NULL, *length_string, &lookup);
13541 return lookup.IsReadOnly();
13542 }
13543
13544
13545 bool JSArray::WouldChangeReadOnlyLength(Handle<JSArray> array,
13546 uint32_t index) {
13547 uint32_t length = 0;
13548 CHECK(array->length()->ToArrayIndex(&length));
13549 if (length <= index) {
13550 Isolate* isolate = array->GetIsolate();
13551 LookupResult lookup(isolate);
13552 Handle<Name> length_string = isolate->factory()->length_string();
13553 array->LocalLookupRealNamedProperty(length_string, &lookup);
13554 return lookup.IsReadOnly();
13555 }
13556 return false;
13557 }
13558
13559
13560 MaybeHandle<Object> JSArray::ReadOnlyLengthError(Handle<JSArray> array) {
13561 Isolate* isolate = array->GetIsolate();
13562 Handle<Name> length = isolate->factory()->length_string();
13563 Handle<Object> args[2] = { length, array };
13564 Handle<Object> error = isolate->factory()->NewTypeError(
13565 "strict_read_only_property", HandleVector(args, ARRAY_SIZE(args)));
13566 return isolate->Throw<Object>(error);
13567 }
13568
13569
13527 MaybeHandle<Object> JSObject::GetElementWithInterceptor( 13570 MaybeHandle<Object> JSObject::GetElementWithInterceptor(
13528 Handle<JSObject> object, 13571 Handle<JSObject> object,
13529 Handle<Object> receiver, 13572 Handle<Object> receiver,
13530 uint32_t index) { 13573 uint32_t index) {
13531 Isolate* isolate = object->GetIsolate(); 13574 Isolate* isolate = object->GetIsolate();
13532 13575
13533 // Make sure that the top context does not change when doing 13576 // Make sure that the top context does not change when doing
13534 // callbacks or interceptor calls. 13577 // callbacks or interceptor calls.
13535 AssertNoContextChange ncc(isolate); 13578 AssertNoContextChange ncc(isolate);
13536 13579
(...skipping 3743 matching lines...) Expand 10 before | Expand all | Expand 10 after
17280 #define ERROR_MESSAGES_TEXTS(C, T) T, 17323 #define ERROR_MESSAGES_TEXTS(C, T) T,
17281 static const char* error_messages_[] = { 17324 static const char* error_messages_[] = {
17282 ERROR_MESSAGES_LIST(ERROR_MESSAGES_TEXTS) 17325 ERROR_MESSAGES_LIST(ERROR_MESSAGES_TEXTS)
17283 }; 17326 };
17284 #undef ERROR_MESSAGES_TEXTS 17327 #undef ERROR_MESSAGES_TEXTS
17285 return error_messages_[reason]; 17328 return error_messages_[reason];
17286 } 17329 }
17287 17330
17288 17331
17289 } } // namespace v8::internal 17332 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/objects.h ('k') | test/mjsunit/array-push-unshift-read-only-length.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698