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 473 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
484 PropertyDescriptor.prototype.getSet = function() { | 484 PropertyDescriptor.prototype.getSet = function() { |
485 return this.set_; | 485 return this.set_; |
486 } | 486 } |
487 | 487 |
488 | 488 |
489 PropertyDescriptor.prototype.hasSetter = function() { | 489 PropertyDescriptor.prototype.hasSetter = function() { |
490 return this.hasSetter_; | 490 return this.hasSetter_; |
491 } | 491 } |
492 | 492 |
493 | 493 |
494 // Converts an array returned from Runtime_GetOwnProperty to an actual | |
495 // property descriptor. For a description of the array layout please | |
496 // see the runtime.cc file. | |
497 function ConvertDescriptorArrayToDescriptor(desc_array) { | |
antonm
2011/02/04 11:41:33
maybe you want to add something like assert(desc_a
Rico
2011/02/04 12:14:18
Done.
| |
498 if (IS_UNDEFINED(desc_array)) { | |
499 return void 0; | |
500 } | |
494 | 501 |
495 // ES5 section 8.12.1. | |
496 function GetOwnProperty(obj, p) { | |
497 var desc = new PropertyDescriptor(); | 502 var desc = new PropertyDescriptor(); |
498 | 503 // This is an accessor. |
499 // GetOwnProperty returns an array indexed by the constants | 504 if (desc_array[IS_ACCESSOR_INDEX]) { |
500 // defined in macros.py. | 505 desc.setGet(desc_array[GETTER_INDEX]); |
501 // If p is not a property on obj undefined is returned. | 506 desc.setSet(desc_array[SETTER_INDEX]); |
502 var props = %GetOwnProperty(ToObject(obj), ToString(p)); | |
503 | |
504 if (IS_UNDEFINED(props)) return void 0; | |
505 | |
506 // This is an accessor | |
507 if (props[IS_ACCESSOR_INDEX]) { | |
508 desc.setGet(props[GETTER_INDEX]); | |
509 desc.setSet(props[SETTER_INDEX]); | |
510 } else { | 507 } else { |
511 desc.setValue(props[VALUE_INDEX]); | 508 desc.setValue(desc_array[VALUE_INDEX]); |
512 desc.setWritable(props[WRITABLE_INDEX]); | 509 desc.setWritable(desc_array[WRITABLE_INDEX]); |
513 } | 510 } |
514 desc.setEnumerable(props[ENUMERABLE_INDEX]); | 511 desc.setEnumerable(desc_array[ENUMERABLE_INDEX]); |
515 desc.setConfigurable(props[CONFIGURABLE_INDEX]); | 512 desc.setConfigurable(desc_array[CONFIGURABLE_INDEX]); |
516 | 513 |
517 return desc; | 514 return desc; |
518 } | 515 } |
519 | 516 |
520 | 517 |
521 // ES5 section 8.12.2. | 518 // ES5 section 8.12.2. |
522 function GetProperty(obj, p) { | 519 function GetProperty(obj, p) { |
523 var prop = GetOwnProperty(obj); | 520 var prop = GetOwnProperty(obj); |
524 if (!IS_UNDEFINED(prop)) return prop; | 521 if (!IS_UNDEFINED(prop)) return prop; |
525 var proto = obj.__proto__; | 522 var proto = obj.__proto__; |
526 if (IS_NULL(proto)) return void 0; | 523 if (IS_NULL(proto)) return void 0; |
527 return GetProperty(proto, p); | 524 return GetProperty(proto, p); |
528 } | 525 } |
529 | 526 |
530 | 527 |
531 // ES5 section 8.12.6 | 528 // ES5 section 8.12.6 |
532 function HasProperty(obj, p) { | 529 function HasProperty(obj, p) { |
533 var desc = GetProperty(obj, p); | 530 var desc = GetProperty(obj, p); |
534 return IS_UNDEFINED(desc) ? false : true; | 531 return IS_UNDEFINED(desc) ? false : true; |
535 } | 532 } |
536 | 533 |
537 | 534 |
535 // ES5 section 8.12.1. | |
536 function GetOwnProperty(obj, p) { | |
537 // GetOwnProperty returns an array indexed by the constants | |
538 // defined in macros.py. | |
539 // If p is not a property on obj undefined is returned. | |
antonm
2011/02/04 11:41:33
you might want to clarify what returned false mean
Rico
2011/02/04 12:14:18
Done.
| |
540 var props = %GetOwnProperty(ToObject(obj), ToString(p)); | |
541 | |
542 if (props == false) return void 0; | |
543 | |
544 return ConvertDescriptorArrayToDescriptor(props); | |
545 } | |
546 | |
547 | |
538 // ES5 8.12.9. | 548 // ES5 8.12.9. |
539 function DefineOwnProperty(obj, p, desc, should_throw) { | 549 function DefineOwnProperty(obj, p, desc, should_throw) { |
540 var current = GetOwnProperty(obj, p); | 550 var current_or_access = %GetOwnProperty(ToObject(obj), ToString(p)); |
551 if (current_or_access == false) return void 0; | |
antonm
2011/02/04 11:41:33
===?
Rico
2011/02/04 12:14:18
No, this will not return true on the return value
| |
552 | |
553 var current = ConvertDescriptorArrayToDescriptor(current_or_access); | |
541 var extensible = %IsExtensible(ToObject(obj)); | 554 var extensible = %IsExtensible(ToObject(obj)); |
542 | 555 |
543 // Error handling according to spec. | 556 // Error handling according to spec. |
544 // Step 3 | 557 // Step 3 |
545 if (IS_UNDEFINED(current) && !extensible) | 558 if (IS_UNDEFINED(current) && !extensible) |
546 throw MakeTypeError("define_disallowed", ["defineProperty"]); | 559 throw MakeTypeError("define_disallowed", ["defineProperty"]); |
547 | 560 |
548 if (!IS_UNDEFINED(current)) { | 561 if (!IS_UNDEFINED(current)) { |
549 // Step 5 and 6 | 562 // Step 5 and 6 |
550 if ((IsGenericDescriptor(desc) || | 563 if ((IsGenericDescriptor(desc) || |
(...skipping 653 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1204 // ---------------------------------------------------------------------------- | 1217 // ---------------------------------------------------------------------------- |
1205 | 1218 |
1206 function SetupFunction() { | 1219 function SetupFunction() { |
1207 InstallFunctions($Function.prototype, DONT_ENUM, $Array( | 1220 InstallFunctions($Function.prototype, DONT_ENUM, $Array( |
1208 "bind", FunctionBind, | 1221 "bind", FunctionBind, |
1209 "toString", FunctionToString | 1222 "toString", FunctionToString |
1210 )); | 1223 )); |
1211 } | 1224 } |
1212 | 1225 |
1213 SetupFunction(); | 1226 SetupFunction(); |
OLD | NEW |