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 214 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
225 | 225 |
226 | 226 |
227 // ECMA-262 - 15.2.4.4 | 227 // ECMA-262 - 15.2.4.4 |
228 function ObjectValueOf() { | 228 function ObjectValueOf() { |
229 return ToObject(this); | 229 return ToObject(this); |
230 } | 230 } |
231 | 231 |
232 | 232 |
233 // ECMA-262 - 15.2.4.5 | 233 // ECMA-262 - 15.2.4.5 |
234 function ObjectHasOwnProperty(V) { | 234 function ObjectHasOwnProperty(V) { |
235 if (%IsJSProxy(this)) { | |
236 var handler = %GetHandler(this); | |
237 return CallTrap1(handler, "hasOwn", TO_STRING_INLINE(V), DerivedHasOwnTrap); | |
238 } | |
235 return %HasLocalProperty(TO_OBJECT_INLINE(this), TO_STRING_INLINE(V)); | 239 return %HasLocalProperty(TO_OBJECT_INLINE(this), TO_STRING_INLINE(V)); |
236 } | 240 } |
237 | 241 |
238 | 242 |
239 // ECMA-262 - 15.2.4.6 | 243 // ECMA-262 - 15.2.4.6 |
240 function ObjectIsPrototypeOf(V) { | 244 function ObjectIsPrototypeOf(V) { |
241 if (IS_NULL_OR_UNDEFINED(this) && !IS_UNDETECTABLE(this)) { | 245 if (IS_NULL_OR_UNDEFINED(this) && !IS_UNDETECTABLE(this)) { |
242 throw MakeTypeError("called_on_null_or_undefined", | 246 throw MakeTypeError("called_on_null_or_undefined", |
243 ["Object.prototype.isPrototypeOf"]); | 247 ["Object.prototype.isPrototypeOf"]); |
244 } | 248 } |
245 if (!IS_SPEC_OBJECT(V)) return false; | 249 if (!IS_SPEC_OBJECT(V)) return false; |
246 return %IsInPrototypeChain(this, V); | 250 return %IsInPrototypeChain(this, V); |
247 } | 251 } |
248 | 252 |
249 | 253 |
250 // ECMA-262 - 15.2.4.6 | 254 // ECMA-262 - 15.2.4.6 |
251 function ObjectPropertyIsEnumerable(V) { | 255 function ObjectPropertyIsEnumerable(V) { |
252 return %IsPropertyEnumerable(ToObject(this), ToString(V)); | 256 var P = ToString(V); |
257 if (%IsJSProxy(this)) { | |
258 var desc = GetOwnProperty(this, P); | |
259 return IS_UNDEFINED(desc) ? false : desc.isEnumerable(); | |
260 } | |
261 return %IsPropertyEnumerable(ToObject(this), P); | |
253 } | 262 } |
254 | 263 |
255 | 264 |
256 // Extensions for providing property getters and setters. | 265 // Extensions for providing property getters and setters. |
257 function ObjectDefineGetter(name, fun) { | 266 function ObjectDefineGetter(name, fun) { |
258 var receiver = this; | 267 var receiver = this; |
259 if (receiver == null && !IS_UNDETECTABLE(receiver)) { | 268 if (receiver == null && !IS_UNDETECTABLE(receiver)) { |
260 receiver = %GlobalReceiver(global); | 269 receiver = %GlobalReceiver(global); |
261 } | 270 } |
262 if (!IS_FUNCTION(fun)) { | 271 if (!IS_FUNCTION(fun)) { |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
303 } | 312 } |
304 return %LookupAccessor(ToObject(receiver), ToString(name), SETTER); | 313 return %LookupAccessor(ToObject(receiver), ToString(name), SETTER); |
305 } | 314 } |
306 | 315 |
307 | 316 |
308 function ObjectKeys(obj) { | 317 function ObjectKeys(obj) { |
309 if (!IS_SPEC_OBJECT(obj)) | 318 if (!IS_SPEC_OBJECT(obj)) |
310 throw MakeTypeError("obj_ctor_property_non_object", ["keys"]); | 319 throw MakeTypeError("obj_ctor_property_non_object", ["keys"]); |
311 if (%IsJSProxy(obj)) { | 320 if (%IsJSProxy(obj)) { |
312 var handler = %GetHandler(obj); | 321 var handler = %GetHandler(obj); |
313 var keys = handler.keys; | 322 var names = CallTrap0(handler, "keys", DerivedKeysTrap); |
314 if (IS_UNDEFINED(keys)) keys = DerivedKeysTrap; | |
315 var names = %_CallFunction(handler, keys); | |
316 return ToStringArray(names); | 323 return ToStringArray(names); |
317 } | 324 } |
318 return %LocalKeys(obj); | 325 return %LocalKeys(obj); |
319 } | 326 } |
320 | 327 |
321 | 328 |
322 // ES5 8.10.1. | 329 // ES5 8.10.1. |
323 function IsAccessorDescriptor(desc) { | 330 function IsAccessorDescriptor(desc) { |
324 if (IS_UNDEFINED(desc)) return false; | 331 if (IS_UNDEFINED(desc)) return false; |
325 return desc.hasGetter() || desc.hasSetter(); | 332 return desc.hasGetter() || desc.hasSetter(); |
(...skipping 250 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
576 desc.setValue(desc_array[VALUE_INDEX]); | 583 desc.setValue(desc_array[VALUE_INDEX]); |
577 desc.setWritable(desc_array[WRITABLE_INDEX]); | 584 desc.setWritable(desc_array[WRITABLE_INDEX]); |
578 } | 585 } |
579 desc.setEnumerable(desc_array[ENUMERABLE_INDEX]); | 586 desc.setEnumerable(desc_array[ENUMERABLE_INDEX]); |
580 desc.setConfigurable(desc_array[CONFIGURABLE_INDEX]); | 587 desc.setConfigurable(desc_array[CONFIGURABLE_INDEX]); |
581 | 588 |
582 return desc; | 589 return desc; |
583 } | 590 } |
584 | 591 |
585 | 592 |
593 // For Harmony proxies. | |
594 function GetTrap(handler, name, defaultTrap) { | |
595 var trap = handler[name]; | |
596 if (IS_UNDEFINED(trap)) { | |
597 if (IS_UNDEFINED(defaultTrap)) { | |
598 throw MakeTypeError("handler_trap_missing", [handler, name]); | |
599 } | |
600 trap = defaultTrap; | |
601 } else if (!IS_FUNCTION(trap)) { | |
602 throw MakeTypeError("handler_trap_must_be_callable", [handler, name]); | |
603 } | |
604 return trap; | |
605 } | |
606 | |
607 | |
608 function CallTrap0(handler, name, defaultTrap) { | |
609 return %_CallFunction(handler, GetTrap(handler, name, defaultTrap)); | |
610 } | |
611 | |
612 | |
613 function CallTrap1(handler, name, x, defaultTrap) { | |
Mads Ager (chromium)
2011/07/19 15:41:05
Maybe put the arguments last in the parameter list
rossberg
2011/07/21 11:08:42
Done.
| |
614 return %_CallFunction(handler, x, GetTrap(handler, name, defaultTrap)); | |
615 } | |
616 | |
617 | |
618 function CallTrap2(handler, name, x, y, defaultTrap) { | |
619 return %_CallFunction(handler, x, y, GetTrap(handler, name, defaultTrap)); | |
620 } | |
621 | |
622 | |
586 // ES5 section 8.12.2. | 623 // ES5 section 8.12.2. |
587 function GetProperty(obj, p) { | 624 function GetProperty(obj, p) { |
588 if (%IsJSProxy(obj)) { | 625 if (%IsJSProxy(obj)) { |
589 var handler = %GetHandler(obj); | 626 var handler = %GetHandler(obj); |
590 var getProperty = handler.getPropertyDescriptor; | 627 var descriptor = CallTrap1(obj, "getPropertyDescriptor", p); |
591 if (IS_UNDEFINED(getProperty)) { | |
592 throw MakeTypeError("handler_trap_missing", | |
593 [handler, "getPropertyDescriptor"]); | |
594 } | |
595 var descriptor = %_CallFunction(handler, p, getProperty); | |
596 if (IS_UNDEFINED(descriptor)) return descriptor; | 628 if (IS_UNDEFINED(descriptor)) return descriptor; |
597 var desc = ToCompletePropertyDescriptor(descriptor); | 629 var desc = ToCompletePropertyDescriptor(descriptor); |
598 if (!desc.isConfigurable()) { | 630 if (!desc.isConfigurable()) { |
599 throw MakeTypeError("proxy_prop_not_configurable", | 631 throw MakeTypeError("proxy_prop_not_configurable", |
600 [handler, "getPropertyDescriptor", p, descriptor]); | 632 [handler, "getPropertyDescriptor", p, descriptor]); |
601 } | 633 } |
602 return desc; | 634 return desc; |
603 } | 635 } |
604 var prop = GetOwnProperty(obj); | 636 var prop = GetOwnProperty(obj); |
605 if (!IS_UNDEFINED(prop)) return prop; | 637 if (!IS_UNDEFINED(prop)) return prop; |
606 var proto = %GetPrototype(obj); | 638 var proto = %GetPrototype(obj); |
607 if (IS_NULL(proto)) return void 0; | 639 if (IS_NULL(proto)) return void 0; |
608 return GetProperty(proto, p); | 640 return GetProperty(proto, p); |
609 } | 641 } |
610 | 642 |
611 | 643 |
612 // ES5 section 8.12.6 | 644 // ES5 section 8.12.6 |
613 function HasProperty(obj, p) { | 645 function HasProperty(obj, p) { |
614 if (%IsJSProxy(obj)) { | 646 if (%IsJSProxy(obj)) { |
615 var handler = %GetHandler(obj); | 647 var handler = %GetHandler(obj); |
616 var has = handler.has; | 648 return ToBoolean(CallTrap1(handler, "has", p, DerivedHasTrap)); |
617 if (IS_UNDEFINED(has)) has = DerivedHasTrap; | |
618 return ToBoolean(%_CallFunction(handler, obj, p, has)); | |
619 } | 649 } |
620 var desc = GetProperty(obj, p); | 650 var desc = GetProperty(obj, p); |
621 return IS_UNDEFINED(desc) ? false : true; | 651 return IS_UNDEFINED(desc) ? false : true; |
622 } | 652 } |
623 | 653 |
624 | 654 |
625 // ES5 section 8.12.1. | 655 // ES5 section 8.12.1. |
626 function GetOwnProperty(obj, p) { | 656 function GetOwnProperty(obj, v) { |
657 var p = ToString(v); | |
627 if (%IsJSProxy(obj)) { | 658 if (%IsJSProxy(obj)) { |
628 var handler = %GetHandler(obj); | 659 var handler = %GetHandler(obj); |
629 var getOwnProperty = handler.getOwnPropertyDescriptor; | 660 var descriptor = CallTrap1(handler, "getOwnPropertyDescriptor", p); |
630 if (IS_UNDEFINED(getOwnProperty)) { | |
631 throw MakeTypeError("handler_trap_missing", | |
632 [handler, "getOwnPropertyDescriptor"]); | |
633 } | |
634 var descriptor = %_CallFunction(handler, p, getOwnProperty); | |
635 if (IS_UNDEFINED(descriptor)) return descriptor; | 661 if (IS_UNDEFINED(descriptor)) return descriptor; |
636 var desc = ToCompletePropertyDescriptor(descriptor); | 662 var desc = ToCompletePropertyDescriptor(descriptor); |
637 if (!desc.isConfigurable()) { | 663 if (!desc.isConfigurable()) { |
638 throw MakeTypeError("proxy_prop_not_configurable", | 664 throw MakeTypeError("proxy_prop_not_configurable", |
639 [handler, "getOwnPropertyDescriptor", p, descriptor]); | 665 [handler, "getOwnPropertyDescriptor", p, descriptor]); |
640 } | 666 } |
641 return desc; | 667 return desc; |
642 } | 668 } |
643 | 669 |
644 // GetOwnProperty returns an array indexed by the constants | 670 // GetOwnProperty returns an array indexed by the constants |
645 // defined in macros.py. | 671 // defined in macros.py. |
646 // If p is not a property on obj undefined is returned. | 672 // If p is not a property on obj undefined is returned. |
647 var props = %GetOwnProperty(ToObject(obj), ToString(p)); | 673 var props = %GetOwnProperty(ToObject(obj), ToString(v)); |
648 | 674 |
649 // A false value here means that access checks failed. | 675 // A false value here means that access checks failed. |
650 if (props === false) return void 0; | 676 if (props === false) return void 0; |
651 | 677 |
652 return ConvertDescriptorArrayToDescriptor(props); | 678 return ConvertDescriptorArrayToDescriptor(props); |
653 } | 679 } |
654 | 680 |
655 | 681 |
656 // Harmony proxies. | 682 // Harmony proxies. |
657 function DefineProxyProperty(obj, p, attributes, should_throw) { | 683 function DefineProxyProperty(obj, p, attributes, should_throw) { |
658 var handler = %GetHandler(obj); | 684 var handler = %GetHandler(obj); |
659 var defineProperty = handler.defineProperty; | 685 var result = CallTrap2(handler, "defineProperty", p, attributes); |
660 if (IS_UNDEFINED(defineProperty)) { | |
661 throw MakeTypeError("handler_trap_missing", [handler, "defineProperty"]); | |
662 } | |
663 var result = %_CallFunction(handler, p, attributes, defineProperty); | |
664 if (!ToBoolean(result)) { | 686 if (!ToBoolean(result)) { |
665 if (should_throw) { | 687 if (should_throw) { |
666 throw MakeTypeError("handler_returned_false", | 688 throw MakeTypeError("handler_returned_false", |
667 [handler, "defineProperty"]); | 689 [handler, "defineProperty"]); |
668 } else { | 690 } else { |
669 return false; | 691 return false; |
670 } | 692 } |
671 } | 693 } |
672 return true; | 694 return true; |
673 } | 695 } |
(...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
882 | 904 |
883 | 905 |
884 // ES5 section 15.2.3.4. | 906 // ES5 section 15.2.3.4. |
885 function ObjectGetOwnPropertyNames(obj) { | 907 function ObjectGetOwnPropertyNames(obj) { |
886 if (!IS_SPEC_OBJECT(obj)) | 908 if (!IS_SPEC_OBJECT(obj)) |
887 throw MakeTypeError("obj_ctor_property_non_object", ["getOwnPropertyNames"]) ; | 909 throw MakeTypeError("obj_ctor_property_non_object", ["getOwnPropertyNames"]) ; |
888 | 910 |
889 // Special handling for proxies. | 911 // Special handling for proxies. |
890 if (%IsJSProxy(obj)) { | 912 if (%IsJSProxy(obj)) { |
891 var handler = %GetHandler(obj); | 913 var handler = %GetHandler(obj); |
892 var getOwnPropertyNames = handler.getOwnPropertyNames; | 914 var names = CallTrap0(handler, "getOwnPropertyNames"); |
893 if (IS_UNDEFINED(getOwnPropertyNames)) { | |
894 throw MakeTypeError("handler_trap_missing", | |
895 [handler, "getOwnPropertyNames"]); | |
896 } | |
897 var names = %_CallFunction(handler, getOwnPropertyNames); | |
898 return ToStringArray(names, "getOwnPropertyNames"); | 915 return ToStringArray(names, "getOwnPropertyNames"); |
899 } | 916 } |
900 | 917 |
901 // Find all the indexed properties. | 918 // Find all the indexed properties. |
902 | 919 |
903 // Get the local element names. | 920 // Get the local element names. |
904 var propertyNames = %GetLocalElementNames(obj); | 921 var propertyNames = %GetLocalElementNames(obj); |
905 | 922 |
906 // Get names for indexed interceptor properties. | 923 // Get names for indexed interceptor properties. |
907 if (%GetInterceptorInfo(obj) & 1) { | 924 if (%GetInterceptorInfo(obj) & 1) { |
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1017 var desc = key_values[i + 1]; | 1034 var desc = key_values[i + 1]; |
1018 DefineOwnProperty(obj, key, desc, true); | 1035 DefineOwnProperty(obj, key, desc, true); |
1019 } | 1036 } |
1020 return obj; | 1037 return obj; |
1021 } | 1038 } |
1022 | 1039 |
1023 | 1040 |
1024 // Harmony proxies. | 1041 // Harmony proxies. |
1025 function ProxyFix(obj) { | 1042 function ProxyFix(obj) { |
1026 var handler = %GetHandler(obj); | 1043 var handler = %GetHandler(obj); |
1027 var fix = handler.fix; | 1044 var props = CallTrap0(handler, "fix"); |
1028 if (IS_UNDEFINED(fix)) { | |
1029 throw MakeTypeError("handler_trap_missing", [handler, "fix"]); | |
1030 } | |
1031 var props = %_CallFunction(handler, fix); | |
1032 if (IS_UNDEFINED(props)) { | 1045 if (IS_UNDEFINED(props)) { |
1033 throw MakeTypeError("handler_returned_undefined", [handler, "fix"]); | 1046 throw MakeTypeError("handler_returned_undefined", [handler, "fix"]); |
1034 } | 1047 } |
1035 %Fix(obj); | 1048 %Fix(obj); |
1036 ObjectDefineProperties(obj, props); | 1049 ObjectDefineProperties(obj, props); |
1037 } | 1050 } |
1038 | 1051 |
1039 | 1052 |
1040 // ES5 section 15.2.3.8. | 1053 // ES5 section 15.2.3.8. |
1041 function ObjectSeal(obj) { | 1054 function ObjectSeal(obj) { |
(...skipping 477 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1519 // ---------------------------------------------------------------------------- | 1532 // ---------------------------------------------------------------------------- |
1520 | 1533 |
1521 function SetupFunction() { | 1534 function SetupFunction() { |
1522 InstallFunctions($Function.prototype, DONT_ENUM, $Array( | 1535 InstallFunctions($Function.prototype, DONT_ENUM, $Array( |
1523 "bind", FunctionBind, | 1536 "bind", FunctionBind, |
1524 "toString", FunctionToString | 1537 "toString", FunctionToString |
1525 )); | 1538 )); |
1526 } | 1539 } |
1527 | 1540 |
1528 SetupFunction(); | 1541 SetupFunction(); |
OLD | NEW |