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 290 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
301 if (receiver == null && !IS_UNDETECTABLE(receiver)) { | 301 if (receiver == null && !IS_UNDETECTABLE(receiver)) { |
302 receiver = %GlobalReceiver(global); | 302 receiver = %GlobalReceiver(global); |
303 } | 303 } |
304 return %LookupAccessor(ToObject(receiver), ToString(name), SETTER); | 304 return %LookupAccessor(ToObject(receiver), ToString(name), SETTER); |
305 } | 305 } |
306 | 306 |
307 | 307 |
308 function ObjectKeys(obj) { | 308 function ObjectKeys(obj) { |
309 if (!IS_SPEC_OBJECT(obj)) | 309 if (!IS_SPEC_OBJECT(obj)) |
310 throw MakeTypeError("obj_ctor_property_non_object", ["keys"]); | 310 throw MakeTypeError("obj_ctor_property_non_object", ["keys"]); |
| 311 if (%IsJSProxy(obj)) { |
| 312 var handler = %GetHandler(obj); |
| 313 var keys = handler.keys; |
| 314 if (IS_UNDEFINED(keys)) keys = DerivedKeysTrap; |
| 315 var names = %_CallFunction(handler, keys); |
| 316 return ToStringArray(names); |
| 317 } |
311 return %LocalKeys(obj); | 318 return %LocalKeys(obj); |
312 } | 319 } |
313 | 320 |
314 | 321 |
315 // ES5 8.10.1. | 322 // ES5 8.10.1. |
316 function IsAccessorDescriptor(desc) { | 323 function IsAccessorDescriptor(desc) { |
317 if (IS_UNDEFINED(desc)) return false; | 324 if (IS_UNDEFINED(desc)) return false; |
318 return desc.hasGetter() || desc.hasSetter(); | 325 return desc.hasGetter() || desc.hasSetter(); |
319 } | 326 } |
320 | 327 |
(...skipping 257 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
578 | 585 |
579 // ES5 section 8.12.2. | 586 // ES5 section 8.12.2. |
580 function GetProperty(obj, p) { | 587 function GetProperty(obj, p) { |
581 if (%IsJSProxy(obj)) { | 588 if (%IsJSProxy(obj)) { |
582 var handler = %GetHandler(obj); | 589 var handler = %GetHandler(obj); |
583 var getProperty = handler.getPropertyDescriptor; | 590 var getProperty = handler.getPropertyDescriptor; |
584 if (IS_UNDEFINED(getProperty)) { | 591 if (IS_UNDEFINED(getProperty)) { |
585 throw MakeTypeError("handler_trap_missing", | 592 throw MakeTypeError("handler_trap_missing", |
586 [handler, "getPropertyDescriptor"]); | 593 [handler, "getPropertyDescriptor"]); |
587 } | 594 } |
588 var descriptor = getProperty.call(handler, p); | 595 var descriptor = %_CallFunction(handler, p, getProperty); |
589 if (IS_UNDEFINED(descriptor)) return descriptor; | 596 if (IS_UNDEFINED(descriptor)) return descriptor; |
590 var desc = ToCompletePropertyDescriptor(descriptor); | 597 var desc = ToCompletePropertyDescriptor(descriptor); |
591 if (!desc.configurable) { | 598 if (!desc.configurable) { |
592 throw MakeTypeError("proxy_prop_not_configurable", | 599 throw MakeTypeError("proxy_prop_not_configurable", |
593 [handler, "getPropertyDescriptor", p, descriptor]); | 600 [handler, "getPropertyDescriptor", p, descriptor]); |
594 } | 601 } |
595 return desc; | 602 return desc; |
596 } | 603 } |
597 var prop = GetOwnProperty(obj); | 604 var prop = GetOwnProperty(obj); |
598 if (!IS_UNDEFINED(prop)) return prop; | 605 if (!IS_UNDEFINED(prop)) return prop; |
599 var proto = %GetPrototype(obj); | 606 var proto = %GetPrototype(obj); |
600 if (IS_NULL(proto)) return void 0; | 607 if (IS_NULL(proto)) return void 0; |
601 return GetProperty(proto, p); | 608 return GetProperty(proto, p); |
602 } | 609 } |
603 | 610 |
604 | 611 |
605 // ES5 section 8.12.6 | 612 // ES5 section 8.12.6 |
606 function HasProperty(obj, p) { | 613 function HasProperty(obj, p) { |
607 if (%IsJSProxy(obj)) { | 614 if (%IsJSProxy(obj)) { |
608 var handler = %GetHandler(obj); | 615 var handler = %GetHandler(obj); |
609 var has = handler.has; | 616 var has = handler.has; |
610 if (IS_UNDEFINED(has)) has = DerivedHasTrap; | 617 if (IS_UNDEFINED(has)) has = DerivedHasTrap; |
611 return ToBoolean(has.call(handler, obj, p)); | 618 return ToBoolean(%_CallFunction(handler, obj, p, has)); |
612 } | 619 } |
613 var desc = GetProperty(obj, p); | 620 var desc = GetProperty(obj, p); |
614 return IS_UNDEFINED(desc) ? false : true; | 621 return IS_UNDEFINED(desc) ? false : true; |
615 } | 622 } |
616 | 623 |
617 | 624 |
618 // ES5 section 8.12.1. | 625 // ES5 section 8.12.1. |
619 function GetOwnProperty(obj, p) { | 626 function GetOwnProperty(obj, p) { |
620 // GetOwnProperty returns an array indexed by the constants | 627 // GetOwnProperty returns an array indexed by the constants |
621 // defined in macros.py. | 628 // defined in macros.py. |
622 // If p is not a property on obj undefined is returned. | 629 // If p is not a property on obj undefined is returned. |
623 var props = %GetOwnProperty(ToObject(obj), ToString(p)); | 630 var props = %GetOwnProperty(ToObject(obj), ToString(p)); |
624 | 631 |
625 // A false value here means that access checks failed. | 632 // A false value here means that access checks failed. |
626 if (props === false) return void 0; | 633 if (props === false) return void 0; |
627 | 634 |
628 return ConvertDescriptorArrayToDescriptor(props); | 635 return ConvertDescriptorArrayToDescriptor(props); |
629 } | 636 } |
630 | 637 |
631 | 638 |
632 // Harmony proxies. | 639 // Harmony proxies. |
633 function DefineProxyProperty(obj, p, attributes, should_throw) { | 640 function DefineProxyProperty(obj, p, attributes, should_throw) { |
634 var handler = %GetHandler(obj); | 641 var handler = %GetHandler(obj); |
635 var defineProperty = handler.defineProperty; | 642 var defineProperty = handler.defineProperty; |
636 if (IS_UNDEFINED(defineProperty)) { | 643 if (IS_UNDEFINED(defineProperty)) { |
637 throw MakeTypeError("handler_trap_missing", [handler, "defineProperty"]); | 644 throw MakeTypeError("handler_trap_missing", [handler, "defineProperty"]); |
638 } | 645 } |
639 var result = defineProperty.call(handler, p, attributes); | 646 var result = %_CallFunction(handler, p, attributes, defineProperty); |
640 if (!ToBoolean(result)) { | 647 if (!ToBoolean(result)) { |
641 if (should_throw) { | 648 if (should_throw) { |
642 throw MakeTypeError("handler_failed", [handler, "defineProperty"]); | 649 throw MakeTypeError("handler_failed", [handler, "defineProperty"]); |
643 } else { | 650 } else { |
644 return false; | 651 return false; |
645 } | 652 } |
646 } | 653 } |
647 return true; | 654 return true; |
648 } | 655 } |
649 | 656 |
(...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
861 throw MakeTypeError("obj_ctor_property_non_object", ["getOwnPropertyNames"])
; | 868 throw MakeTypeError("obj_ctor_property_non_object", ["getOwnPropertyNames"])
; |
862 | 869 |
863 // Special handling for proxies. | 870 // Special handling for proxies. |
864 if (%IsJSProxy(obj)) { | 871 if (%IsJSProxy(obj)) { |
865 var handler = %GetHandler(obj); | 872 var handler = %GetHandler(obj); |
866 var getOwnPropertyNames = handler.getOwnPropertyNames; | 873 var getOwnPropertyNames = handler.getOwnPropertyNames; |
867 if (IS_UNDEFINED(getOwnPropertyNames)) { | 874 if (IS_UNDEFINED(getOwnPropertyNames)) { |
868 throw MakeTypeError("handler_trap_missing", | 875 throw MakeTypeError("handler_trap_missing", |
869 [handler, "getOwnPropertyNames"]); | 876 [handler, "getOwnPropertyNames"]); |
870 } | 877 } |
871 var names = getOwnPropertyNames.call(handler); | 878 var names = %_CallFunction(handler, getOwnPropertyNames); |
872 return ToStringArray(names, "getOwnPropertyNames"); | 879 return ToStringArray(names, "getOwnPropertyNames"); |
873 } | 880 } |
874 | 881 |
875 // Find all the indexed properties. | 882 // Find all the indexed properties. |
876 | 883 |
877 // Get the local element names. | 884 // Get the local element names. |
878 var propertyNames = %GetLocalElementNames(obj); | 885 var propertyNames = %GetLocalElementNames(obj); |
879 | 886 |
880 // Get names for indexed interceptor properties. | 887 // Get names for indexed interceptor properties. |
881 if (%GetInterceptorInfo(obj) & 1) { | 888 if (%GetInterceptorInfo(obj) & 1) { |
(...skipping 575 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1457 // ---------------------------------------------------------------------------- | 1464 // ---------------------------------------------------------------------------- |
1458 | 1465 |
1459 function SetupFunction() { | 1466 function SetupFunction() { |
1460 InstallFunctions($Function.prototype, DONT_ENUM, $Array( | 1467 InstallFunctions($Function.prototype, DONT_ENUM, $Array( |
1461 "bind", FunctionBind, | 1468 "bind", FunctionBind, |
1462 "toString", FunctionToString | 1469 "toString", FunctionToString |
1463 )); | 1470 )); |
1464 } | 1471 } |
1465 | 1472 |
1466 SetupFunction(); | 1473 SetupFunction(); |
OLD | NEW |