| 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 464 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 475 | 475 |
| 476 PropertyDescriptor.prototype.hasSetter = function() { | 476 PropertyDescriptor.prototype.hasSetter = function() { |
| 477 return this.hasSetter_; | 477 return this.hasSetter_; |
| 478 } | 478 } |
| 479 | 479 |
| 480 | 480 |
| 481 | 481 |
| 482 // ES5 section 8.12.1. | 482 // ES5 section 8.12.1. |
| 483 function GetOwnProperty(obj, p) { | 483 function GetOwnProperty(obj, p) { |
| 484 var desc = new PropertyDescriptor(); | 484 var desc = new PropertyDescriptor(); |
| 485 | 485 |
| 486 // An array with: | 486 // An array with: |
| 487 // obj is a data property [false, value, Writeable, Enumerable, Configurable] | 487 // obj is a data property [false, value, Writeable, Enumerable, Configurable] |
| 488 // obj is an accessor [true, Get, Set, Enumerable, Configurable] | 488 // obj is an accessor [true, Get, Set, Enumerable, Configurable] |
| 489 var props = %GetOwnProperty(ToObject(obj), ToString(p)); | 489 var props = %GetOwnProperty(ToObject(obj), ToString(p)); |
| 490 | 490 |
| 491 if (IS_UNDEFINED(props)) return void 0; | 491 if (IS_UNDEFINED(props)) return void 0; |
| 492 | 492 |
| 493 // This is an accessor | 493 // This is an accessor |
| 494 if (props[0]) { | 494 if (props[0]) { |
| 495 desc.setGet(props[1]); | 495 desc.setGet(props[1]); |
| (...skipping 19 matching lines...) Expand all Loading... |
| 515 } | 515 } |
| 516 | 516 |
| 517 | 517 |
| 518 // ES5 section 8.12.6 | 518 // ES5 section 8.12.6 |
| 519 function HasProperty(obj, p) { | 519 function HasProperty(obj, p) { |
| 520 var desc = GetProperty(obj, p); | 520 var desc = GetProperty(obj, p); |
| 521 return IS_UNDEFINED(desc) ? false : true; | 521 return IS_UNDEFINED(desc) ? false : true; |
| 522 } | 522 } |
| 523 | 523 |
| 524 | 524 |
| 525 // ES5 8.12.9. | 525 // ES5 8.12.9. |
| 526 function DefineOwnProperty(obj, p, desc, should_throw) { | 526 function DefineOwnProperty(obj, p, desc, should_throw) { |
| 527 var current = GetOwnProperty(obj, p); | 527 var current = GetOwnProperty(obj, p); |
| 528 var extensible = %IsExtensible(ToObject(obj)); | 528 var extensible = %IsExtensible(ToObject(obj)); |
| 529 | 529 |
| 530 // Error handling according to spec. | 530 // Error handling according to spec. |
| 531 // Step 3 | 531 // Step 3 |
| 532 if (IS_UNDEFINED(current) && !extensible) | 532 if (IS_UNDEFINED(current) && !extensible) |
| 533 throw MakeTypeError("define_disallowed", ["defineProperty"]); | 533 throw MakeTypeError("define_disallowed", ["defineProperty"]); |
| 534 | 534 |
| 535 if (!IS_UNDEFINED(current) && !current.isConfigurable()) { | 535 if (!IS_UNDEFINED(current) && !current.isConfigurable()) { |
| (...skipping 15 matching lines...) Expand all Loading... |
| 551 // Step 11 | 551 // Step 11 |
| 552 if (IsAccessorDescriptor(desc) && IsAccessorDescriptor(current)) { | 552 if (IsAccessorDescriptor(desc) && IsAccessorDescriptor(current)) { |
| 553 if (desc.hasSetter() && !SameValue(desc.getSet(), current.getSet())){ | 553 if (desc.hasSetter() && !SameValue(desc.getSet(), current.getSet())){ |
| 554 throw MakeTypeError("redefine_disallowed", ["defineProperty"]); | 554 throw MakeTypeError("redefine_disallowed", ["defineProperty"]); |
| 555 } | 555 } |
| 556 if (desc.hasGetter() && !SameValue(desc.getGet(),current.getGet())) | 556 if (desc.hasGetter() && !SameValue(desc.getGet(),current.getGet())) |
| 557 throw MakeTypeError("redefine_disallowed", ["defineProperty"]); | 557 throw MakeTypeError("redefine_disallowed", ["defineProperty"]); |
| 558 } | 558 } |
| 559 } | 559 } |
| 560 | 560 |
| 561 // Send flags - enumerable and configurable are common - writable is | 561 // Send flags - enumerable and configurable are common - writable is |
| 562 // only send to the data descriptor. | 562 // only send to the data descriptor. |
| 563 // Take special care if enumerable and configurable is not defined on | 563 // Take special care if enumerable and configurable is not defined on |
| 564 // desc (we need to preserve the existing values from current). | 564 // desc (we need to preserve the existing values from current). |
| 565 var flag = NONE; | 565 var flag = NONE; |
| 566 if (desc.hasEnumerable()) { | 566 if (desc.hasEnumerable()) { |
| 567 flag |= desc.isEnumerable() ? 0 : DONT_ENUM; | 567 flag |= desc.isEnumerable() ? 0 : DONT_ENUM; |
| 568 } else if (!IS_UNDEFINED(current)) { | 568 } else if (!IS_UNDEFINED(current)) { |
| 569 flag |= current.isEnumerable() ? 0 : DONT_ENUM; | 569 flag |= current.isEnumerable() ? 0 : DONT_ENUM; |
| 570 } else { | 570 } else { |
| 571 flag |= DONT_ENUM; | 571 flag |= DONT_ENUM; |
| (...skipping 23 matching lines...) Expand all Loading... |
| 595 | 595 |
| 596 // ES5 section 15.2.3.2. | 596 // ES5 section 15.2.3.2. |
| 597 function ObjectGetPrototypeOf(obj) { | 597 function ObjectGetPrototypeOf(obj) { |
| 598 if ((!IS_OBJECT(obj) || IS_NULL_OR_UNDEFINED(obj)) && !IS_FUNCTION(obj) && | 598 if ((!IS_OBJECT(obj) || IS_NULL_OR_UNDEFINED(obj)) && !IS_FUNCTION(obj) && |
| 599 !IS_UNDETECTABLE(obj)) | 599 !IS_UNDETECTABLE(obj)) |
| 600 throw MakeTypeError("obj_ctor_property_non_object", ["getPrototypeOf"]); | 600 throw MakeTypeError("obj_ctor_property_non_object", ["getPrototypeOf"]); |
| 601 return obj.__proto__; | 601 return obj.__proto__; |
| 602 } | 602 } |
| 603 | 603 |
| 604 | 604 |
| 605 // ES5 section 15.2.3.3 | 605 // ES5 section 15.2.3.3 |
| 606 function ObjectGetOwnPropertyDescriptor(obj, p) { | 606 function ObjectGetOwnPropertyDescriptor(obj, p) { |
| 607 if ((!IS_OBJECT(obj) || IS_NULL_OR_UNDEFINED(obj)) && !IS_FUNCTION(obj) && | 607 if ((!IS_OBJECT(obj) || IS_NULL_OR_UNDEFINED(obj)) && !IS_FUNCTION(obj) && |
| 608 !IS_UNDETECTABLE(obj)) | 608 !IS_UNDETECTABLE(obj)) |
| 609 throw MakeTypeError("obj_ctor_property_non_object", ["getOwnPropertyDescript
or"]); | 609 throw MakeTypeError("obj_ctor_property_non_object", ["getOwnPropertyDescript
or"]); |
| 610 var desc = GetOwnProperty(obj, p); | 610 var desc = GetOwnProperty(obj, p); |
| 611 return FromPropertyDescriptor(desc); | 611 return FromPropertyDescriptor(desc); |
| 612 } | 612 } |
| 613 | 613 |
| 614 | 614 |
| 615 // ES5 section 15.2.3.4. | 615 // ES5 section 15.2.3.4. |
| (...skipping 382 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 998 | 998 |
| 999 // ---------------------------------------------------------------------------- | 999 // ---------------------------------------------------------------------------- |
| 1000 | 1000 |
| 1001 function SetupFunction() { | 1001 function SetupFunction() { |
| 1002 InstallFunctions($Function.prototype, DONT_ENUM, $Array( | 1002 InstallFunctions($Function.prototype, DONT_ENUM, $Array( |
| 1003 "toString", FunctionToString | 1003 "toString", FunctionToString |
| 1004 )); | 1004 )); |
| 1005 } | 1005 } |
| 1006 | 1006 |
| 1007 SetupFunction(); | 1007 SetupFunction(); |
| OLD | NEW |