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

Side by Side Diff: src/objects.cc

Issue 6712059: Follow jsc on not throwing when trying to add a property to a non-extensible object. (Closed) Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge/
Patch Set: Created 9 years, 9 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
OLDNEW
1 // Copyright 2010 the V8 project authors. All rights reserved. 1 // Copyright 2010 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 1420 matching lines...) Expand 10 before | Expand all | Expand 10 after
1431 { MaybeObject* maybe_result = dict->Add(name, store_value, details); 1431 { MaybeObject* maybe_result = dict->Add(name, store_value, details);
1432 if (!maybe_result->ToObject(&result)) return maybe_result; 1432 if (!maybe_result->ToObject(&result)) return maybe_result;
1433 } 1433 }
1434 if (dict != result) set_properties(StringDictionary::cast(result)); 1434 if (dict != result) set_properties(StringDictionary::cast(result));
1435 return value; 1435 return value;
1436 } 1436 }
1437 1437
1438 1438
1439 MaybeObject* JSObject::AddProperty(String* name, 1439 MaybeObject* JSObject::AddProperty(String* name,
1440 Object* value, 1440 Object* value,
1441 PropertyAttributes attributes) { 1441 PropertyAttributes attributes,
1442 StrictModeFlag strict_mode) {
1442 ASSERT(!IsJSGlobalProxy()); 1443 ASSERT(!IsJSGlobalProxy());
1443 Heap* heap = GetHeap(); 1444 Heap* heap = GetHeap();
1444 if (!map()->is_extensible()) { 1445 if (!map()->is_extensible()) {
1445 Handle<Object> args[1] = {Handle<String>(name)}; 1446 if (strict_mode == kNonStrictMode) {
1446 return heap->isolate()->Throw( 1447 return heap->undefined_value();
1447 *FACTORY->NewTypeError("object_not_extensible", HandleVector(args, 1))); 1448 } else {
1449 Handle<Object> args[1] = {Handle<String>(name)};
1450 return heap->isolate()->Throw(
1451 *FACTORY->NewTypeError("object_not_extensible",
1452 HandleVector(args, 1)));
1453 }
1448 } 1454 }
1449 if (HasFastProperties()) { 1455 if (HasFastProperties()) {
1450 // Ensure the descriptor array does not get too big. 1456 // Ensure the descriptor array does not get too big.
1451 if (map()->instance_descriptors()->number_of_descriptors() < 1457 if (map()->instance_descriptors()->number_of_descriptors() <
1452 DescriptorArray::kMaxNumberOfDescriptors) { 1458 DescriptorArray::kMaxNumberOfDescriptors) {
1453 if (value->IsJSFunction() && !heap->InNewSpace(value)) { 1459 if (value->IsJSFunction() && !heap->InNewSpace(value)) {
1454 return AddConstantFunctionProperty(name, 1460 return AddConstantFunctionProperty(name,
1455 JSFunction::cast(value), 1461 JSFunction::cast(value),
1456 attributes); 1462 attributes);
1457 } else { 1463 } else {
(...skipping 20 matching lines...) Expand all
1478 StrictModeFlag strict_mode) { 1484 StrictModeFlag strict_mode) {
1479 // Check local property, ignore interceptor. 1485 // Check local property, ignore interceptor.
1480 LookupResult result; 1486 LookupResult result;
1481 LocalLookupRealNamedProperty(name, &result); 1487 LocalLookupRealNamedProperty(name, &result);
1482 if (result.IsFound()) { 1488 if (result.IsFound()) {
1483 // An existing property, a map transition or a null descriptor was 1489 // An existing property, a map transition or a null descriptor was
1484 // found. Use set property to handle all these cases. 1490 // found. Use set property to handle all these cases.
1485 return SetProperty(&result, name, value, attributes, strict_mode); 1491 return SetProperty(&result, name, value, attributes, strict_mode);
1486 } 1492 }
1487 // Add a new real property. 1493 // Add a new real property.
1488 return AddProperty(name, value, attributes); 1494 return AddProperty(name, value, attributes, strict_mode);
1489 } 1495 }
1490 1496
1491 1497
1492 MaybeObject* JSObject::ReplaceSlowProperty(String* name, 1498 MaybeObject* JSObject::ReplaceSlowProperty(String* name,
1493 Object* value, 1499 Object* value,
1494 PropertyAttributes attributes) { 1500 PropertyAttributes attributes) {
1495 StringDictionary* dictionary = property_dictionary(); 1501 StringDictionary* dictionary = property_dictionary();
1496 int old_index = dictionary->FindEntry(name); 1502 int old_index = dictionary->FindEntry(name);
1497 int new_enumeration_index = 0; // 0 means "Use the next available index." 1503 int new_enumeration_index = 0; // 0 means "Use the next available index."
1498 if (old_index != -1) { 1504 if (old_index != -1) {
(...skipping 483 matching lines...) Expand 10 before | Expand all | Expand 10 after
1982 LookupCallbackSetterInPrototypes(name, &accessor_result); 1988 LookupCallbackSetterInPrototypes(name, &accessor_result);
1983 if (accessor_result.IsProperty()) { 1989 if (accessor_result.IsProperty()) {
1984 return SetPropertyWithCallback(accessor_result.GetCallbackObject(), 1990 return SetPropertyWithCallback(accessor_result.GetCallbackObject(),
1985 name, 1991 name,
1986 value, 1992 value,
1987 accessor_result.holder()); 1993 accessor_result.holder());
1988 } 1994 }
1989 } 1995 }
1990 if (!result->IsFound()) { 1996 if (!result->IsFound()) {
1991 // Neither properties nor transitions found. 1997 // Neither properties nor transitions found.
1992 return AddProperty(name, value, attributes); 1998 return AddProperty(name, value, attributes, strict_mode);
1993 } 1999 }
1994 if (result->IsReadOnly() && result->IsProperty()) { 2000 if (result->IsReadOnly() && result->IsProperty()) {
1995 if (strict_mode == kStrictMode) { 2001 if (strict_mode == kStrictMode) {
1996 HandleScope scope; 2002 HandleScope scope;
1997 Handle<String> key(name); 2003 Handle<String> key(name);
1998 Handle<Object> holder(this); 2004 Handle<Object> holder(this);
1999 Handle<Object> args[2] = { key, holder }; 2005 Handle<Object> args[2] = { key, holder };
2000 return heap->isolate()->Throw(*heap->isolate()->factory()->NewTypeError( 2006 return heap->isolate()->Throw(*heap->isolate()->factory()->NewTypeError(
2001 "strict_read_only_property", HandleVector(args, 2))); 2007 "strict_read_only_property", HandleVector(args, 2)));
2002 } else { 2008 } else {
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
2089 ASSERT(proto->IsJSGlobalObject()); 2095 ASSERT(proto->IsJSGlobalObject());
2090 return JSObject::cast(proto)->SetLocalPropertyIgnoreAttributes( 2096 return JSObject::cast(proto)->SetLocalPropertyIgnoreAttributes(
2091 name, 2097 name,
2092 value, 2098 value,
2093 attributes); 2099 attributes);
2094 } 2100 }
2095 2101
2096 // Check for accessor in prototype chain removed here in clone. 2102 // Check for accessor in prototype chain removed here in clone.
2097 if (!result.IsFound()) { 2103 if (!result.IsFound()) {
2098 // Neither properties nor transitions found. 2104 // Neither properties nor transitions found.
2099 return AddProperty(name, value, attributes); 2105 return AddProperty(name, value, attributes, kNonStrictMode);
2100 } 2106 }
2101 2107
2102 PropertyDetails details = PropertyDetails(attributes, NORMAL); 2108 PropertyDetails details = PropertyDetails(attributes, NORMAL);
2103 2109
2104 // Check of IsReadOnly removed from here in clone. 2110 // Check of IsReadOnly removed from here in clone.
2105 switch (result.type()) { 2111 switch (result.type()) {
2106 case NORMAL: 2112 case NORMAL:
2107 return SetNormalizedProperty(name, value, details); 2113 return SetNormalizedProperty(name, value, details);
2108 case FIELD: 2114 case FIELD:
2109 return FastPropertyAtPut(result.GetFieldIndex(), value); 2115 return FastPropertyAtPut(result.GetFieldIndex(), value);
(...skipping 5230 matching lines...) Expand 10 before | Expand all | Expand 10 after
7340 if (check_prototype) { 7346 if (check_prototype) {
7341 bool found; 7347 bool found;
7342 MaybeObject* result = 7348 MaybeObject* result =
7343 // Strict mode not needed. No-setter case already handled. 7349 // Strict mode not needed. No-setter case already handled.
7344 SetElementWithCallbackSetterInPrototypes(index, value, &found); 7350 SetElementWithCallbackSetterInPrototypes(index, value, &found);
7345 if (found) return result; 7351 if (found) return result;
7346 } 7352 }
7347 // When we set the is_extensible flag to false we always force 7353 // When we set the is_extensible flag to false we always force
7348 // the element into dictionary mode (and force them to stay there). 7354 // the element into dictionary mode (and force them to stay there).
7349 if (!map()->is_extensible()) { 7355 if (!map()->is_extensible()) {
7350 Handle<Object> number(isolate->factory()->NewNumberFromUint(index)); 7356 if (strict_mode == kNonStrictMode) {
7351 Handle<String> index_string( 7357 return isolate->heap()->undefined_value();
7352 isolate->factory()->NumberToString(number)); 7358 } else {
7353 Handle<Object> args[1] = { index_string }; 7359 Handle<Object> number(isolate->factory()->NewNumberFromUint(index));
7354 return isolate->Throw( 7360 Handle<String> index_string(
7355 *isolate->factory()->NewTypeError("object_not_extensible", 7361 isolate->factory()->NumberToString(number));
7356 HandleVector(args, 1))); 7362 Handle<Object> args[1] = { index_string };
7363 return isolate->Throw(
7364 *isolate->factory()->NewTypeError("object_not_extensible",
7365 HandleVector(args, 1)));
7366 }
7357 } 7367 }
7358 Object* result; 7368 Object* result;
7359 { MaybeObject* maybe_result = dictionary->AtNumberPut(index, value); 7369 { MaybeObject* maybe_result = dictionary->AtNumberPut(index, value);
7360 if (!maybe_result->ToObject(&result)) return maybe_result; 7370 if (!maybe_result->ToObject(&result)) return maybe_result;
7361 } 7371 }
7362 if (elms != FixedArray::cast(result)) { 7372 if (elms != FixedArray::cast(result)) {
7363 set_elements(FixedArray::cast(result)); 7373 set_elements(FixedArray::cast(result));
7364 } 7374 }
7365 } 7375 }
7366 7376
(...skipping 2795 matching lines...) Expand 10 before | Expand all | Expand 10 after
10162 if (break_point_objects()->IsUndefined()) return 0; 10172 if (break_point_objects()->IsUndefined()) return 0;
10163 // Single beak point. 10173 // Single beak point.
10164 if (!break_point_objects()->IsFixedArray()) return 1; 10174 if (!break_point_objects()->IsFixedArray()) return 1;
10165 // Multiple break points. 10175 // Multiple break points.
10166 return FixedArray::cast(break_point_objects())->length(); 10176 return FixedArray::cast(break_point_objects())->length();
10167 } 10177 }
10168 #endif 10178 #endif
10169 10179
10170 10180
10171 } } // namespace v8::internal 10181 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/objects.h ('k') | test/cctest/test-api.cc » ('j') | test/mjsunit/strict-mode.js » ('J')

Powered by Google App Engine
This is Rietveld 408576698