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) { |
| 498 if (desc_array == false) { |
| 499 throw 'Internal error: invalid desc_array'; |
| 500 } |
494 | 501 |
495 // ES5 section 8.12.1. | 502 if (IS_UNDEFINED(desc_array)) { |
496 function GetOwnProperty(obj, p) { | 503 return void 0; |
| 504 } |
| 505 |
497 var desc = new PropertyDescriptor(); | 506 var desc = new PropertyDescriptor(); |
498 | 507 // This is an accessor. |
499 // GetOwnProperty returns an array indexed by the constants | 508 if (desc_array[IS_ACCESSOR_INDEX]) { |
500 // defined in macros.py. | 509 desc.setGet(desc_array[GETTER_INDEX]); |
501 // If p is not a property on obj undefined is returned. | 510 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 { | 511 } else { |
511 desc.setValue(props[VALUE_INDEX]); | 512 desc.setValue(desc_array[VALUE_INDEX]); |
512 desc.setWritable(props[WRITABLE_INDEX]); | 513 desc.setWritable(desc_array[WRITABLE_INDEX]); |
513 } | 514 } |
514 desc.setEnumerable(props[ENUMERABLE_INDEX]); | 515 desc.setEnumerable(desc_array[ENUMERABLE_INDEX]); |
515 desc.setConfigurable(props[CONFIGURABLE_INDEX]); | 516 desc.setConfigurable(desc_array[CONFIGURABLE_INDEX]); |
516 | 517 |
517 return desc; | 518 return desc; |
518 } | 519 } |
519 | 520 |
520 | 521 |
521 // ES5 section 8.12.2. | 522 // ES5 section 8.12.2. |
522 function GetProperty(obj, p) { | 523 function GetProperty(obj, p) { |
523 var prop = GetOwnProperty(obj); | 524 var prop = GetOwnProperty(obj); |
524 if (!IS_UNDEFINED(prop)) return prop; | 525 if (!IS_UNDEFINED(prop)) return prop; |
525 var proto = obj.__proto__; | 526 var proto = obj.__proto__; |
526 if (IS_NULL(proto)) return void 0; | 527 if (IS_NULL(proto)) return void 0; |
527 return GetProperty(proto, p); | 528 return GetProperty(proto, p); |
528 } | 529 } |
529 | 530 |
530 | 531 |
531 // ES5 section 8.12.6 | 532 // ES5 section 8.12.6 |
532 function HasProperty(obj, p) { | 533 function HasProperty(obj, p) { |
533 var desc = GetProperty(obj, p); | 534 var desc = GetProperty(obj, p); |
534 return IS_UNDEFINED(desc) ? false : true; | 535 return IS_UNDEFINED(desc) ? false : true; |
535 } | 536 } |
536 | 537 |
537 | 538 |
| 539 // ES5 section 8.12.1. |
| 540 function GetOwnProperty(obj, p) { |
| 541 // GetOwnProperty returns an array indexed by the constants |
| 542 // defined in macros.py. |
| 543 // If p is not a property on obj undefined is returned. |
| 544 var props = %GetOwnProperty(ToObject(obj), ToString(p)); |
| 545 |
| 546 // A false value here means that access checks failed. |
| 547 if (props == false) return void 0; |
| 548 |
| 549 return ConvertDescriptorArrayToDescriptor(props); |
| 550 } |
| 551 |
| 552 |
538 // ES5 8.12.9. | 553 // ES5 8.12.9. |
539 function DefineOwnProperty(obj, p, desc, should_throw) { | 554 function DefineOwnProperty(obj, p, desc, should_throw) { |
540 var current = GetOwnProperty(obj, p); | 555 var current_or_access = %GetOwnProperty(ToObject(obj), ToString(p)); |
| 556 // A false value here means that access checks failed. |
| 557 if (current_or_access == false) return void 0; |
| 558 |
| 559 var current = ConvertDescriptorArrayToDescriptor(current_or_access); |
541 var extensible = %IsExtensible(ToObject(obj)); | 560 var extensible = %IsExtensible(ToObject(obj)); |
542 | 561 |
543 // Error handling according to spec. | 562 // Error handling according to spec. |
544 // Step 3 | 563 // Step 3 |
545 if (IS_UNDEFINED(current) && !extensible) | 564 if (IS_UNDEFINED(current) && !extensible) |
546 throw MakeTypeError("define_disallowed", ["defineProperty"]); | 565 throw MakeTypeError("define_disallowed", ["defineProperty"]); |
547 | 566 |
548 if (!IS_UNDEFINED(current)) { | 567 if (!IS_UNDEFINED(current)) { |
549 // Step 5 and 6 | 568 // Step 5 and 6 |
550 if ((IsGenericDescriptor(desc) || | 569 if ((IsGenericDescriptor(desc) || |
(...skipping 653 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1204 // ---------------------------------------------------------------------------- | 1223 // ---------------------------------------------------------------------------- |
1205 | 1224 |
1206 function SetupFunction() { | 1225 function SetupFunction() { |
1207 InstallFunctions($Function.prototype, DONT_ENUM, $Array( | 1226 InstallFunctions($Function.prototype, DONT_ENUM, $Array( |
1208 "bind", FunctionBind, | 1227 "bind", FunctionBind, |
1209 "toString", FunctionToString | 1228 "toString", FunctionToString |
1210 )); | 1229 )); |
1211 } | 1230 } |
1212 | 1231 |
1213 SetupFunction(); | 1232 SetupFunction(); |
OLD | NEW |