| OLD | NEW |
| 1 // Copyright 2006-2008 the V8 project authors. All rights reserved. | 1 // Copyright 2006-2008 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 486 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 497 GlobalObject* global = Top::context()->global(); | 497 GlobalObject* global = Top::context()->global(); |
| 498 | 498 |
| 499 // According to ECMA-262, section 12.2, page 62, the property must | 499 // According to ECMA-262, section 12.2, page 62, the property must |
| 500 // not be deletable. | 500 // not be deletable. |
| 501 PropertyAttributes attributes = DONT_DELETE; | 501 PropertyAttributes attributes = DONT_DELETE; |
| 502 | 502 |
| 503 // Lookup the property locally in the global object. If it isn't | 503 // Lookup the property locally in the global object. If it isn't |
| 504 // there, we add the property and take special precautions to always | 504 // there, we add the property and take special precautions to always |
| 505 // add it as a local property even in case of callbacks in the | 505 // add it as a local property even in case of callbacks in the |
| 506 // prototype chain (this rules out using SetProperty). | 506 // prototype chain (this rules out using SetProperty). |
| 507 // We have IgnoreAttributesAndSetLocalProperty for this. |
| 507 LookupResult lookup; | 508 LookupResult lookup; |
| 508 global->LocalLookup(*name, &lookup); | 509 global->LocalLookup(*name, &lookup); |
| 509 if (!lookup.IsProperty()) { | 510 if (!lookup.IsProperty()) { |
| 510 Object* value = (assign) ? args[1] : Heap::undefined_value(); | 511 Object* value = (assign) ? args[1] : Heap::undefined_value(); |
| 511 return global->AddProperty(*name, value, attributes); | 512 return global->IgnoreAttributesAndSetLocalProperty(*name, |
| 513 » » » » » » value, |
| 514 » » » » » » attributes); |
| 512 } | 515 } |
| 513 | 516 |
| 514 // Determine if this is a redeclaration of something read-only. | 517 // Determine if this is a redeclaration of something read-only. |
| 515 if (lookup.IsReadOnly()) { | 518 if (lookup.IsReadOnly()) { |
| 516 return ThrowRedeclarationError("const", name); | 519 return ThrowRedeclarationError("const", name); |
| 517 } | 520 } |
| 518 | 521 |
| 519 // Determine if this is a redeclaration of an intercepted read-only | 522 // Determine if this is a redeclaration of an intercepted read-only |
| 520 // property and figure out if the property exists at all. | 523 // property and figure out if the property exists at all. |
| 521 bool found = true; | 524 bool found = true; |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 561 | 564 |
| 562 // According to ECMA-262, section 12.2, page 62, the property must | 565 // According to ECMA-262, section 12.2, page 62, the property must |
| 563 // not be deletable. Since it's a const, it must be READ_ONLY too. | 566 // not be deletable. Since it's a const, it must be READ_ONLY too. |
| 564 PropertyAttributes attributes = | 567 PropertyAttributes attributes = |
| 565 static_cast<PropertyAttributes>(DONT_DELETE | READ_ONLY); | 568 static_cast<PropertyAttributes>(DONT_DELETE | READ_ONLY); |
| 566 | 569 |
| 567 // Lookup the property locally in the global object. If it isn't | 570 // Lookup the property locally in the global object. If it isn't |
| 568 // there, we add the property and take special precautions to always | 571 // there, we add the property and take special precautions to always |
| 569 // add it as a local property even in case of callbacks in the | 572 // add it as a local property even in case of callbacks in the |
| 570 // prototype chain (this rules out using SetProperty). | 573 // prototype chain (this rules out using SetProperty). |
| 574 // We use IgnoreAttributesAndSetLocalProperty instead |
| 571 LookupResult lookup; | 575 LookupResult lookup; |
| 572 global->LocalLookup(*name, &lookup); | 576 global->LocalLookup(*name, &lookup); |
| 573 if (!lookup.IsProperty()) { | 577 if (!lookup.IsProperty()) { |
| 574 return global->AddProperty(*name, *value, attributes); | 578 return global->IgnoreAttributesAndSetLocalProperty(*name, |
| 579 » » » » » » *value, |
| 580 » » » » » » attributes); |
| 575 } | 581 } |
| 576 | 582 |
| 577 // Determine if this is a redeclaration of something not | 583 // Determine if this is a redeclaration of something not |
| 578 // read-only. In case the result is hidden behind an interceptor we | 584 // read-only. In case the result is hidden behind an interceptor we |
| 579 // need to ask it for the property attributes. | 585 // need to ask it for the property attributes. |
| 580 if (!lookup.IsReadOnly()) { | 586 if (!lookup.IsReadOnly()) { |
| 581 if (lookup.type() != INTERCEPTOR) { | 587 if (lookup.type() != INTERCEPTOR) { |
| 582 return ThrowRedeclarationError("var", name); | 588 return ThrowRedeclarationError("var", name); |
| 583 } | 589 } |
| 584 | 590 |
| (...skipping 785 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1370 | 1376 |
| 1371 if (name->AsArrayIndex(&index)) { | 1377 if (name->AsArrayIndex(&index)) { |
| 1372 ASSERT(attr == NONE); | 1378 ASSERT(attr == NONE); |
| 1373 return js_object->SetElement(index, *value); | 1379 return js_object->SetElement(index, *value); |
| 1374 } else { | 1380 } else { |
| 1375 return js_object->SetProperty(*name, *value, attr); | 1381 return js_object->SetProperty(*name, *value, attr); |
| 1376 } | 1382 } |
| 1377 } | 1383 } |
| 1378 | 1384 |
| 1379 | 1385 |
| 1380 static Object* Runtime_AddProperty(Arguments args) { | |
| 1381 NoHandleAllocation ha; | |
| 1382 ASSERT(args.length() == 4); | |
| 1383 | |
| 1384 CONVERT_CHECKED(JSObject, object, args[0]); | |
| 1385 CONVERT_CHECKED(String, name, args[1]); | |
| 1386 RUNTIME_ASSERT(!object->HasLocalProperty(name)); | |
| 1387 CONVERT_CHECKED(Smi, attr_obj, args[3]); | |
| 1388 | |
| 1389 int attr = attr_obj->value(); | |
| 1390 RUNTIME_ASSERT((attr & ~(READ_ONLY | DONT_ENUM | DONT_DELETE)) == 0); | |
| 1391 PropertyAttributes attributes = static_cast<PropertyAttributes>(attr); | |
| 1392 | |
| 1393 return object->AddProperty(name, args[2], attributes); | |
| 1394 } | |
| 1395 | |
| 1396 | |
| 1397 static Object* Runtime_SetProperty(Arguments args) { | 1386 static Object* Runtime_SetProperty(Arguments args) { |
| 1398 NoHandleAllocation ha; | 1387 NoHandleAllocation ha; |
| 1399 RUNTIME_ASSERT(args.length() == 3 || args.length() == 4); | 1388 RUNTIME_ASSERT(args.length() == 3 || args.length() == 4); |
| 1400 | 1389 |
| 1401 Handle<Object> object = args.at<Object>(0); | 1390 Handle<Object> object = args.at<Object>(0); |
| 1402 Handle<Object> key = args.at<Object>(1); | 1391 Handle<Object> key = args.at<Object>(1); |
| 1403 Handle<Object> value = args.at<Object>(2); | 1392 Handle<Object> value = args.at<Object>(2); |
| 1404 | 1393 |
| 1405 // Compute attributes. | 1394 // Compute attributes. |
| 1406 PropertyAttributes attributes = NONE; | 1395 PropertyAttributes attributes = NONE; |
| 1407 if (args.length() == 4) { | 1396 if (args.length() == 4) { |
| 1408 CONVERT_CHECKED(Smi, value_obj, args[3]); | 1397 CONVERT_CHECKED(Smi, value_obj, args[3]); |
| 1409 int value = value_obj->value(); | 1398 int unchecked_value = value_obj->value(); |
| 1410 // Only attribute bits should be set. | 1399 // Only attribute bits should be set. |
| 1411 ASSERT((value & ~(READ_ONLY | DONT_ENUM | DONT_DELETE)) == 0); | 1400 RUNTIME_ASSERT( |
| 1412 attributes = static_cast<PropertyAttributes>(value); | 1401 (unchecked_value & ~(READ_ONLY | DONT_ENUM | DONT_DELETE)) == 0); |
| 1402 attributes = static_cast<PropertyAttributes>(unchecked_value); |
| 1413 } | 1403 } |
| 1414 return Runtime::SetObjectProperty(object, key, value, attributes); | 1404 return Runtime::SetObjectProperty(object, key, value, attributes); |
| 1415 } | 1405 } |
| 1416 | 1406 |
| 1417 | 1407 |
| 1418 // Set a local property, even if it is READ_ONLY. If the property does not | 1408 // Set a local property, even if it is READ_ONLY. If the property does not |
| 1419 // exist, it will be added with attributes NONE. | 1409 // exist, it will be added with attributes NONE. |
| 1420 static Object* Runtime_IgnoreAttributesAndSetProperty(Arguments args) { | 1410 static Object* Runtime_IgnoreAttributesAndSetProperty(Arguments args) { |
| 1421 NoHandleAllocation ha; | 1411 NoHandleAllocation ha; |
| 1422 ASSERT(args.length() == 3); | 1412 RUNTIME_ASSERT(args.length() == 3 || args.length() == 4); |
| 1423 | |
| 1424 CONVERT_CHECKED(JSObject, object, args[0]); | 1413 CONVERT_CHECKED(JSObject, object, args[0]); |
| 1425 CONVERT_CHECKED(String, name, args[1]); | 1414 CONVERT_CHECKED(String, name, args[1]); |
| 1415 // Compute attributes. |
| 1416 PropertyAttributes attributes = NONE; |
| 1417 if (args.length() == 4) { |
| 1418 CONVERT_CHECKED(Smi, value_obj, args[3]); |
| 1419 int unchecked_value = value_obj->value(); |
| 1420 // Only attribute bits should be set. |
| 1421 RUNTIME_ASSERT( |
| 1422 (unchecked_value & ~(READ_ONLY | DONT_ENUM | DONT_DELETE)) == 0); |
| 1423 attributes = static_cast<PropertyAttributes>(unchecked_value); |
| 1424 } |
| 1426 | 1425 |
| 1427 return object->IgnoreAttributesAndSetLocalProperty(name, args[2], NONE); | 1426 return object-> |
| 1427 IgnoreAttributesAndSetLocalProperty(name, args[2], attributes); |
| 1428 } | 1428 } |
| 1429 | 1429 |
| 1430 | 1430 |
| 1431 static Object* Runtime_DeleteProperty(Arguments args) { | 1431 static Object* Runtime_DeleteProperty(Arguments args) { |
| 1432 NoHandleAllocation ha; | 1432 NoHandleAllocation ha; |
| 1433 ASSERT(args.length() == 2); | 1433 ASSERT(args.length() == 2); |
| 1434 | 1434 |
| 1435 CONVERT_CHECKED(JSObject, object, args[0]); | 1435 CONVERT_CHECKED(JSObject, object, args[0]); |
| 1436 CONVERT_CHECKED(String, key, args[1]); | 1436 CONVERT_CHECKED(String, key, args[1]); |
| 1437 return object->DeleteProperty(key); | 1437 return object->DeleteProperty(key); |
| (...skipping 3589 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5027 | 5027 |
| 5028 void Runtime::PerformGC(Object* result) { | 5028 void Runtime::PerformGC(Object* result) { |
| 5029 Failure* failure = Failure::cast(result); | 5029 Failure* failure = Failure::cast(result); |
| 5030 // Try to do a garbage collection; ignore it if it fails. The C | 5030 // Try to do a garbage collection; ignore it if it fails. The C |
| 5031 // entry stub will throw an out-of-memory exception in that case. | 5031 // entry stub will throw an out-of-memory exception in that case. |
| 5032 Heap::CollectGarbage(failure->requested(), failure->allocation_space()); | 5032 Heap::CollectGarbage(failure->requested(), failure->allocation_space()); |
| 5033 } | 5033 } |
| 5034 | 5034 |
| 5035 | 5035 |
| 5036 } } // namespace v8::internal | 5036 } } // namespace v8::internal |
| OLD | NEW |