|
|
|
Lines 733-753
ArrayToIdVector(JSContext *cx, const Val
|
Link Here
|
|---|
|
| 733 |
return false; |
733 |
return false; |
| 734 |
if (!props.append(id)) |
734 |
if (!props.append(id)) |
| 735 |
return false; |
735 |
return false; |
| 736 |
} |
736 |
} |
| 737 |
|
737 |
|
| 738 |
return true; |
738 |
return true; |
| 739 |
} |
739 |
} |
| 740 |
|
740 |
|
| 741 |
/* Derived class for all scripted proxy handlers. */ |
741 |
/* Derived class for all scripted indirect proxy handlers. */ |
| 742 |
class ScriptedProxyHandler : public IndirectProxyHandler { |
742 |
class ScriptedIndirectProxyHandler : public IndirectProxyHandler { |
| 743 |
public: |
743 |
public: |
| 744 |
ScriptedProxyHandler(); |
744 |
ScriptedIndirectProxyHandler(); |
| 745 |
virtual ~ScriptedProxyHandler(); |
745 |
virtual ~ScriptedIndirectProxyHandler(); |
| 746 |
|
746 |
|
| 747 |
/* ES5 Harmony fundamental proxy traps. */ |
747 |
/* ES5 Harmony fundamental proxy traps. */ |
| 748 |
virtual bool getPropertyDescriptor(JSContext *cx, JSObject *proxy, jsid id, bool set, |
748 |
virtual bool getPropertyDescriptor(JSContext *cx, JSObject *proxy, jsid id, bool set, |
| 749 |
PropertyDescriptor *desc) MOZ_OVERRIDE; |
749 |
PropertyDescriptor *desc) MOZ_OVERRIDE; |
| 750 |
virtual bool getOwnPropertyDescriptor(JSContext *cx, JSObject *proxy, jsid id, bool set, |
750 |
virtual bool getOwnPropertyDescriptor(JSContext *cx, JSObject *proxy, jsid id, bool set, |
| 751 |
PropertyDescriptor *desc) MOZ_OVERRIDE; |
751 |
PropertyDescriptor *desc) MOZ_OVERRIDE; |
| 752 |
virtual bool defineProperty(JSContext *cx, JSObject *proxy, jsid id, |
752 |
virtual bool defineProperty(JSContext *cx, JSObject *proxy, jsid id, |
| 753 |
PropertyDescriptor *desc) MOZ_OVERRIDE; |
753 |
PropertyDescriptor *desc) MOZ_OVERRIDE; |
|
Lines 766-791
class ScriptedProxyHandler : public Indi
|
Link Here
|
|---|
|
| 766 |
virtual bool iterate(JSContext *cx, JSObject *proxy, unsigned flags, Value *vp) MOZ_OVERRIDE; |
766 |
virtual bool iterate(JSContext *cx, JSObject *proxy, unsigned flags, Value *vp) MOZ_OVERRIDE; |
| 767 |
|
767 |
|
| 768 |
/* Spidermonkey extensions. */ |
768 |
/* Spidermonkey extensions. */ |
| 769 |
virtual bool nativeCall(JSContext *cx, IsAcceptableThis test, NativeImpl impl, |
769 |
virtual bool nativeCall(JSContext *cx, IsAcceptableThis test, NativeImpl impl, |
| 770 |
CallArgs args) MOZ_OVERRIDE; |
770 |
CallArgs args) MOZ_OVERRIDE; |
| 771 |
virtual JSType typeOf(JSContext *cx, JSObject *proxy); |
771 |
virtual JSType typeOf(JSContext *cx, JSObject *proxy); |
| 772 |
virtual bool defaultValue(JSContext *cx, JSObject *obj, JSType hint, Value *vp) MOZ_OVERRIDE; |
772 |
virtual bool defaultValue(JSContext *cx, JSObject *obj, JSType hint, Value *vp) MOZ_OVERRIDE; |
| 773 |
|
773 |
|
| 774 |
static ScriptedProxyHandler singleton; |
774 |
static ScriptedIndirectProxyHandler singleton; |
| 775 |
}; |
775 |
}; |
| 776 |
|
776 |
|
| 777 |
static int sScriptedProxyHandlerFamily = 0; |
777 |
static int sScriptedIndirectProxyHandlerFamily = 0; |
| 778 |
|
778 |
|
| 779 |
ScriptedProxyHandler::ScriptedProxyHandler() : IndirectProxyHandler(&sScriptedProxyHandlerFamily) |
779 |
ScriptedIndirectProxyHandler::ScriptedIndirectProxyHandler() |
|
|
780 |
: IndirectProxyHandler(&sScriptedIndirectProxyHandlerFamily) |
| 780 |
{ |
781 |
{ |
| 781 |
} |
782 |
} |
| 782 |
|
783 |
|
| 783 |
ScriptedProxyHandler::~ScriptedProxyHandler() |
784 |
ScriptedIndirectProxyHandler::~ScriptedIndirectProxyHandler() |
| 784 |
{ |
785 |
{ |
| 785 |
} |
786 |
} |
| 786 |
|
787 |
|
| 787 |
static bool |
788 |
static bool |
| 788 |
ReturnedValueMustNotBePrimitive(JSContext *cx, JSObject *proxy, JSAtom *atom, const Value &v) |
789 |
ReturnedValueMustNotBePrimitive(JSContext *cx, JSObject *proxy, JSAtom *atom, const Value &v) |
| 789 |
{ |
790 |
{ |
| 790 |
if (v.isPrimitive()) { |
791 |
if (v.isPrimitive()) { |
| 791 |
JSAutoByteString bytes; |
792 |
JSAutoByteString bytes; |
|
Lines 794-1017
ReturnedValueMustNotBePrimitive(JSContex
|
Link Here
|
|---|
|
| 794 |
JSDVG_SEARCH_STACK, ObjectOrNullValue(proxy), NULL, bytes.ptr()); |
795 |
JSDVG_SEARCH_STACK, ObjectOrNullValue(proxy), NULL, bytes.ptr()); |
| 795 |
} |
796 |
} |
| 796 |
return false; |
797 |
return false; |
| 797 |
} |
798 |
} |
| 798 |
return true; |
799 |
return true; |
| 799 |
} |
800 |
} |
| 800 |
|
801 |
|
| 801 |
static JSObject * |
802 |
static JSObject * |
| 802 |
GetProxyHandlerObject(JSContext *cx, JSObject *proxy) |
803 |
GetIndirectProxyHandlerObject(JSContext *cx, JSObject *proxy) |
| 803 |
{ |
804 |
{ |
| 804 |
return GetProxyPrivate(proxy).toObjectOrNull(); |
805 |
return GetProxyPrivate(proxy).toObjectOrNull(); |
| 805 |
} |
806 |
} |
| 806 |
|
807 |
|
| 807 |
bool |
808 |
bool |
| 808 |
ScriptedProxyHandler::getPropertyDescriptor(JSContext *cx, JSObject *proxy_, jsid id_, bool set, |
809 |
ScriptedIndirectProxyHandler::getPropertyDescriptor(JSContext *cx, JSObject *proxy_, jsid id_, |
| 809 |
PropertyDescriptor *desc) |
810 |
bool set, PropertyDescriptor *desc) |
| 810 |
{ |
811 |
{ |
| 811 |
RootedId id(cx, id_); |
812 |
RootedId id(cx, id_); |
| 812 |
RootedObject proxy(cx, proxy_); |
813 |
RootedObject proxy(cx, proxy_); |
| 813 |
RootedObject handler(cx, GetProxyHandlerObject(cx, proxy)); |
814 |
RootedObject handler(cx, GetIndirectProxyHandlerObject(cx, proxy)); |
| 814 |
RootedValue fval(cx), value(cx); |
815 |
RootedValue fval(cx), value(cx); |
| 815 |
return GetFundamentalTrap(cx, handler, ATOM(getPropertyDescriptor), &fval) && |
816 |
return GetFundamentalTrap(cx, handler, ATOM(getPropertyDescriptor), &fval) && |
| 816 |
Trap1(cx, handler, fval, id, value.address()) && |
817 |
Trap1(cx, handler, fval, id, value.address()) && |
| 817 |
((value.get().isUndefined() && IndicatePropertyNotFound(cx, desc)) || |
818 |
((value.get().isUndefined() && IndicatePropertyNotFound(cx, desc)) || |
| 818 |
(ReturnedValueMustNotBePrimitive(cx, proxy, ATOM(getPropertyDescriptor), value) && |
819 |
(ReturnedValueMustNotBePrimitive(cx, proxy, ATOM(getPropertyDescriptor), value) && |
| 819 |
ParsePropertyDescriptorObject(cx, proxy, value, desc))); |
820 |
ParsePropertyDescriptorObject(cx, proxy, value, desc))); |
| 820 |
} |
821 |
} |
| 821 |
|
822 |
|
| 822 |
bool |
823 |
bool |
| 823 |
ScriptedProxyHandler::getOwnPropertyDescriptor(JSContext *cx, JSObject *proxy_, jsid id_, bool set, |
824 |
ScriptedIndirectProxyHandler::getOwnPropertyDescriptor(JSContext *cx, JSObject *proxy_, jsid id_, |
| 824 |
PropertyDescriptor *desc) |
825 |
bool set, PropertyDescriptor *desc) |
| 825 |
{ |
826 |
{ |
| 826 |
RootedId id(cx, id_); |
827 |
RootedId id(cx, id_); |
| 827 |
RootedObject proxy(cx, proxy_); |
828 |
RootedObject proxy(cx, proxy_); |
| 828 |
RootedObject handler(cx, GetProxyHandlerObject(cx, proxy)); |
829 |
RootedObject handler(cx, GetIndirectProxyHandlerObject(cx, proxy)); |
| 829 |
RootedValue fval(cx), value(cx); |
830 |
RootedValue fval(cx), value(cx); |
| 830 |
return GetFundamentalTrap(cx, handler, ATOM(getOwnPropertyDescriptor), &fval) && |
831 |
return GetFundamentalTrap(cx, handler, ATOM(getOwnPropertyDescriptor), &fval) && |
| 831 |
Trap1(cx, handler, fval, id, value.address()) && |
832 |
Trap1(cx, handler, fval, id, value.address()) && |
| 832 |
((value.get().isUndefined() && IndicatePropertyNotFound(cx, desc)) || |
833 |
((value.get().isUndefined() && IndicatePropertyNotFound(cx, desc)) || |
| 833 |
(ReturnedValueMustNotBePrimitive(cx, proxy, ATOM(getPropertyDescriptor), value) && |
834 |
(ReturnedValueMustNotBePrimitive(cx, proxy, ATOM(getPropertyDescriptor), value) && |
| 834 |
ParsePropertyDescriptorObject(cx, proxy, value, desc))); |
835 |
ParsePropertyDescriptorObject(cx, proxy, value, desc))); |
| 835 |
} |
836 |
} |
| 836 |
|
837 |
|
| 837 |
bool |
838 |
bool |
| 838 |
ScriptedProxyHandler::defineProperty(JSContext *cx, JSObject *proxy, jsid id_, |
839 |
ScriptedIndirectProxyHandler::defineProperty(JSContext *cx, JSObject *proxy, jsid id_, |
| 839 |
PropertyDescriptor *desc) |
840 |
PropertyDescriptor *desc) |
| 840 |
{ |
841 |
{ |
| 841 |
RootedObject handler(cx, GetProxyHandlerObject(cx, proxy)); |
842 |
RootedObject handler(cx, GetIndirectProxyHandlerObject(cx, proxy)); |
| 842 |
RootedValue fval(cx), value(cx); |
843 |
RootedValue fval(cx), value(cx); |
| 843 |
RootedId id(cx, id_); |
844 |
RootedId id(cx, id_); |
| 844 |
return GetFundamentalTrap(cx, handler, ATOM(defineProperty), &fval) && |
845 |
return GetFundamentalTrap(cx, handler, ATOM(defineProperty), &fval) && |
| 845 |
NewPropertyDescriptorObject(cx, desc, value.address()) && |
846 |
NewPropertyDescriptorObject(cx, desc, value.address()) && |
| 846 |
Trap2(cx, handler, fval, id, value, value.address()); |
847 |
Trap2(cx, handler, fval, id, value, value.address()); |
| 847 |
} |
848 |
} |
| 848 |
|
849 |
|
| 849 |
bool |
850 |
bool |
| 850 |
ScriptedProxyHandler::getOwnPropertyNames(JSContext *cx, JSObject *proxy, AutoIdVector &props) |
851 |
ScriptedIndirectProxyHandler::getOwnPropertyNames(JSContext *cx, JSObject *proxy, |
|
|
852 |
AutoIdVector &props) |
| 851 |
{ |
853 |
{ |
| 852 |
RootedObject handler(cx, GetProxyHandlerObject(cx, proxy)); |
854 |
RootedObject handler(cx, GetIndirectProxyHandlerObject(cx, proxy)); |
| 853 |
RootedValue fval(cx), value(cx); |
855 |
RootedValue fval(cx), value(cx); |
| 854 |
return GetFundamentalTrap(cx, handler, ATOM(getOwnPropertyNames), &fval) && |
856 |
return GetFundamentalTrap(cx, handler, ATOM(getOwnPropertyNames), &fval) && |
| 855 |
Trap(cx, handler, fval, 0, NULL, value.address()) && |
857 |
Trap(cx, handler, fval, 0, NULL, value.address()) && |
| 856 |
ArrayToIdVector(cx, value, props); |
858 |
ArrayToIdVector(cx, value, props); |
| 857 |
} |
859 |
} |
| 858 |
|
860 |
|
| 859 |
bool |
861 |
bool |
| 860 |
ScriptedProxyHandler::delete_(JSContext *cx, JSObject *proxy, jsid id_, bool *bp) |
862 |
ScriptedIndirectProxyHandler::delete_(JSContext *cx, JSObject *proxy, jsid id_, bool *bp) |
| 861 |
{ |
863 |
{ |
| 862 |
RootedObject handler(cx, GetProxyHandlerObject(cx, proxy)); |
864 |
RootedObject handler(cx, GetIndirectProxyHandlerObject(cx, proxy)); |
| 863 |
RootedId id(cx, id_); |
865 |
RootedId id(cx, id_); |
| 864 |
RootedValue fval(cx), value(cx); |
866 |
RootedValue fval(cx), value(cx); |
| 865 |
return GetFundamentalTrap(cx, handler, ATOM(delete), &fval) && |
867 |
return GetFundamentalTrap(cx, handler, ATOM(delete), &fval) && |
| 866 |
Trap1(cx, handler, fval, id, value.address()) && |
868 |
Trap1(cx, handler, fval, id, value.address()) && |
| 867 |
ValueToBool(cx, value, bp); |
869 |
ValueToBool(cx, value, bp); |
| 868 |
} |
870 |
} |
| 869 |
|
871 |
|
| 870 |
bool |
872 |
bool |
| 871 |
ScriptedProxyHandler::enumerate(JSContext *cx, JSObject *proxy, AutoIdVector &props) |
873 |
ScriptedIndirectProxyHandler::enumerate(JSContext *cx, JSObject *proxy, AutoIdVector &props) |
| 872 |
{ |
874 |
{ |
| 873 |
RootedObject handler(cx, GetProxyHandlerObject(cx, proxy)); |
875 |
RootedObject handler(cx, GetIndirectProxyHandlerObject(cx, proxy)); |
| 874 |
RootedValue fval(cx), value(cx); |
876 |
RootedValue fval(cx), value(cx); |
| 875 |
return GetFundamentalTrap(cx, handler, ATOM(enumerate), &fval) && |
877 |
return GetFundamentalTrap(cx, handler, ATOM(enumerate), &fval) && |
| 876 |
Trap(cx, handler, fval, 0, NULL, value.address()) && |
878 |
Trap(cx, handler, fval, 0, NULL, value.address()) && |
| 877 |
ArrayToIdVector(cx, value, props); |
879 |
ArrayToIdVector(cx, value, props); |
| 878 |
} |
880 |
} |
| 879 |
|
881 |
|
| 880 |
bool |
882 |
bool |
| 881 |
ScriptedProxyHandler::has(JSContext *cx, JSObject *proxy_, jsid id_, bool *bp) |
883 |
ScriptedIndirectProxyHandler::has(JSContext *cx, JSObject *proxy_, jsid id_, bool *bp) |
| 882 |
{ |
884 |
{ |
| 883 |
RootedObject proxy(cx, proxy_); |
885 |
RootedObject proxy(cx, proxy_); |
| 884 |
RootedId id(cx, id_); |
886 |
RootedId id(cx, id_); |
| 885 |
RootedObject handler(cx, GetProxyHandlerObject(cx, proxy)); |
887 |
RootedObject handler(cx, GetIndirectProxyHandlerObject(cx, proxy)); |
| 886 |
RootedValue fval(cx), value(cx); |
888 |
RootedValue fval(cx), value(cx); |
| 887 |
if (!GetDerivedTrap(cx, handler, ATOM(has), &fval)) |
889 |
if (!GetDerivedTrap(cx, handler, ATOM(has), &fval)) |
| 888 |
return false; |
890 |
return false; |
| 889 |
if (!js_IsCallable(fval)) |
891 |
if (!js_IsCallable(fval)) |
| 890 |
return BaseProxyHandler::has(cx, proxy, id, bp); |
892 |
return BaseProxyHandler::has(cx, proxy, id, bp); |
| 891 |
return Trap1(cx, handler, fval, id, value.address()) && |
893 |
return Trap1(cx, handler, fval, id, value.address()) && |
| 892 |
ValueToBool(cx, value, bp); |
894 |
ValueToBool(cx, value, bp); |
| 893 |
} |
895 |
} |
| 894 |
|
896 |
|
| 895 |
bool |
897 |
bool |
| 896 |
ScriptedProxyHandler::hasOwn(JSContext *cx, JSObject *proxy_, jsid id_, bool *bp) |
898 |
ScriptedIndirectProxyHandler::hasOwn(JSContext *cx, JSObject *proxy_, jsid id_, bool *bp) |
| 897 |
{ |
899 |
{ |
| 898 |
RootedObject proxy(cx, proxy_); |
900 |
RootedObject proxy(cx, proxy_); |
| 899 |
RootedId id(cx, id_); |
901 |
RootedId id(cx, id_); |
| 900 |
RootedObject handler(cx, GetProxyHandlerObject(cx, proxy)); |
902 |
RootedObject handler(cx, GetIndirectProxyHandlerObject(cx, proxy)); |
| 901 |
RootedValue fval(cx), value(cx); |
903 |
RootedValue fval(cx), value(cx); |
| 902 |
if (!GetDerivedTrap(cx, handler, ATOM(hasOwn), &fval)) |
904 |
if (!GetDerivedTrap(cx, handler, ATOM(hasOwn), &fval)) |
| 903 |
return false; |
905 |
return false; |
| 904 |
if (!js_IsCallable(fval)) |
906 |
if (!js_IsCallable(fval)) |
| 905 |
return BaseProxyHandler::hasOwn(cx, proxy, id, bp); |
907 |
return BaseProxyHandler::hasOwn(cx, proxy, id, bp); |
| 906 |
return Trap1(cx, handler, fval, id, value.address()) && |
908 |
return Trap1(cx, handler, fval, id, value.address()) && |
| 907 |
ValueToBool(cx, value, bp); |
909 |
ValueToBool(cx, value, bp); |
| 908 |
} |
910 |
} |
| 909 |
|
911 |
|
| 910 |
bool |
912 |
bool |
| 911 |
ScriptedProxyHandler::get(JSContext *cx, JSObject *proxy_, JSObject *receiver_, jsid id_, Value *vp) |
913 |
ScriptedIndirectProxyHandler::get(JSContext *cx, JSObject *proxy_, JSObject *receiver_, jsid id_, |
|
|
914 |
Value *vp) |
| 912 |
{ |
915 |
{ |
| 913 |
RootedId id(cx, id_); |
916 |
RootedId id(cx, id_); |
| 914 |
RootedObject proxy(cx, proxy_), receiver(cx, receiver_); |
917 |
RootedObject proxy(cx, proxy_), receiver(cx, receiver_); |
| 915 |
RootedObject handler(cx, GetProxyHandlerObject(cx, proxy)); |
918 |
RootedObject handler(cx, GetIndirectProxyHandlerObject(cx, proxy)); |
| 916 |
JSString *str = ToString(cx, IdToValue(id)); |
919 |
JSString *str = ToString(cx, IdToValue(id)); |
| 917 |
if (!str) |
920 |
if (!str) |
| 918 |
return false; |
921 |
return false; |
| 919 |
RootedValue value(cx, StringValue(str)); |
922 |
RootedValue value(cx, StringValue(str)); |
| 920 |
Value argv[] = { ObjectOrNullValue(receiver), value }; |
923 |
Value argv[] = { ObjectOrNullValue(receiver), value }; |
| 921 |
AutoValueArray ava(cx, argv, 2); |
924 |
AutoValueArray ava(cx, argv, 2); |
| 922 |
RootedValue fval(cx); |
925 |
RootedValue fval(cx); |
| 923 |
if (!GetDerivedTrap(cx, handler, ATOM(get), &fval)) |
926 |
if (!GetDerivedTrap(cx, handler, ATOM(get), &fval)) |
| 924 |
return false; |
927 |
return false; |
| 925 |
if (!js_IsCallable(fval)) |
928 |
if (!js_IsCallable(fval)) |
| 926 |
return BaseProxyHandler::get(cx, proxy, receiver, id, vp); |
929 |
return BaseProxyHandler::get(cx, proxy, receiver, id, vp); |
| 927 |
return Trap(cx, handler, fval, 2, argv, vp); |
930 |
return Trap(cx, handler, fval, 2, argv, vp); |
| 928 |
} |
931 |
} |
| 929 |
|
932 |
|
| 930 |
bool |
933 |
bool |
| 931 |
ScriptedProxyHandler::set(JSContext *cx, JSObject *proxy_, JSObject *receiver_, jsid id_, bool strict, |
934 |
ScriptedIndirectProxyHandler::set(JSContext *cx, JSObject *proxy_, JSObject *receiver_, jsid id_, |
| 932 |
Value *vp) |
935 |
bool strict, Value *vp) |
| 933 |
{ |
936 |
{ |
| 934 |
RootedId id(cx, id_); |
937 |
RootedId id(cx, id_); |
| 935 |
RootedObject proxy(cx, proxy_), receiver(cx, receiver_); |
938 |
RootedObject proxy(cx, proxy_), receiver(cx, receiver_); |
| 936 |
RootedObject handler(cx, GetProxyHandlerObject(cx, proxy)); |
939 |
RootedObject handler(cx, GetIndirectProxyHandlerObject(cx, proxy)); |
| 937 |
JSString *str = ToString(cx, IdToValue(id)); |
940 |
JSString *str = ToString(cx, IdToValue(id)); |
| 938 |
if (!str) |
941 |
if (!str) |
| 939 |
return false; |
942 |
return false; |
| 940 |
RootedValue value(cx, StringValue(str)); |
943 |
RootedValue value(cx, StringValue(str)); |
| 941 |
Value argv[] = { ObjectOrNullValue(receiver), value, *vp }; |
944 |
Value argv[] = { ObjectOrNullValue(receiver), value, *vp }; |
| 942 |
AutoValueArray ava(cx, argv, 3); |
945 |
AutoValueArray ava(cx, argv, 3); |
| 943 |
RootedValue fval(cx); |
946 |
RootedValue fval(cx); |
| 944 |
if (!GetDerivedTrap(cx, handler, ATOM(set), &fval)) |
947 |
if (!GetDerivedTrap(cx, handler, ATOM(set), &fval)) |
| 945 |
return false; |
948 |
return false; |
| 946 |
if (!js_IsCallable(fval)) |
949 |
if (!js_IsCallable(fval)) |
| 947 |
return BaseProxyHandler::set(cx, proxy, receiver, id, strict, vp); |
950 |
return BaseProxyHandler::set(cx, proxy, receiver, id, strict, vp); |
| 948 |
return Trap(cx, handler, fval, 3, argv, value.address()); |
951 |
return Trap(cx, handler, fval, 3, argv, value.address()); |
| 949 |
} |
952 |
} |
| 950 |
|
953 |
|
| 951 |
bool |
954 |
bool |
| 952 |
ScriptedProxyHandler::keys(JSContext *cx, JSObject *proxy_, AutoIdVector &props) |
955 |
ScriptedIndirectProxyHandler::keys(JSContext *cx, JSObject *proxy_, AutoIdVector &props) |
| 953 |
{ |
956 |
{ |
| 954 |
RootedObject proxy(cx, proxy_); |
957 |
RootedObject proxy(cx, proxy_); |
| 955 |
RootedObject handler(cx, GetProxyHandlerObject(cx, proxy)); |
958 |
RootedObject handler(cx, GetIndirectProxyHandlerObject(cx, proxy)); |
| 956 |
RootedValue value(cx); |
959 |
RootedValue value(cx); |
| 957 |
if (!GetDerivedTrap(cx, handler, ATOM(keys), &value)) |
960 |
if (!GetDerivedTrap(cx, handler, ATOM(keys), &value)) |
| 958 |
return false; |
961 |
return false; |
| 959 |
if (!js_IsCallable(value)) |
962 |
if (!js_IsCallable(value)) |
| 960 |
return BaseProxyHandler::keys(cx, proxy, props); |
963 |
return BaseProxyHandler::keys(cx, proxy, props); |
| 961 |
return Trap(cx, handler, value, 0, NULL, value.address()) && |
964 |
return Trap(cx, handler, value, 0, NULL, value.address()) && |
| 962 |
ArrayToIdVector(cx, value, props); |
965 |
ArrayToIdVector(cx, value, props); |
| 963 |
} |
966 |
} |
| 964 |
|
967 |
|
| 965 |
bool |
968 |
bool |
| 966 |
ScriptedProxyHandler::iterate(JSContext *cx, JSObject *proxy_, unsigned flags, Value *vp) |
969 |
ScriptedIndirectProxyHandler::iterate(JSContext *cx, JSObject *proxy_, unsigned flags, Value *vp) |
| 967 |
{ |
970 |
{ |
| 968 |
RootedObject proxy(cx, proxy_); |
971 |
RootedObject proxy(cx, proxy_); |
| 969 |
RootedObject handler(cx, GetProxyHandlerObject(cx, proxy)); |
972 |
RootedObject handler(cx, GetIndirectProxyHandlerObject(cx, proxy)); |
| 970 |
RootedValue value(cx); |
973 |
RootedValue value(cx); |
| 971 |
if (!GetDerivedTrap(cx, handler, ATOM(iterate), &value)) |
974 |
if (!GetDerivedTrap(cx, handler, ATOM(iterate), &value)) |
| 972 |
return false; |
975 |
return false; |
| 973 |
if (!js_IsCallable(value)) |
976 |
if (!js_IsCallable(value)) |
| 974 |
return BaseProxyHandler::iterate(cx, proxy, flags, vp); |
977 |
return BaseProxyHandler::iterate(cx, proxy, flags, vp); |
| 975 |
return Trap(cx, handler, value, 0, NULL, vp) && |
978 |
return Trap(cx, handler, value, 0, NULL, vp) && |
| 976 |
ReturnedValueMustNotBePrimitive(cx, proxy, ATOM(iterate), *vp); |
979 |
ReturnedValueMustNotBePrimitive(cx, proxy, ATOM(iterate), *vp); |
| 977 |
} |
980 |
} |
| 978 |
|
981 |
|
| 979 |
bool |
982 |
bool |
| 980 |
ScriptedProxyHandler::nativeCall(JSContext *cx, IsAcceptableThis test, NativeImpl impl, |
983 |
ScriptedIndirectProxyHandler::nativeCall(JSContext *cx, IsAcceptableThis test, NativeImpl impl, |
| 981 |
CallArgs args) |
984 |
CallArgs args) |
| 982 |
{ |
985 |
{ |
| 983 |
return BaseProxyHandler::nativeCall(cx, test, impl, args); |
986 |
return BaseProxyHandler::nativeCall(cx, test, impl, args); |
| 984 |
} |
987 |
} |
| 985 |
|
988 |
|
| 986 |
|
|
|
| 987 |
JSType |
989 |
JSType |
| 988 |
ScriptedProxyHandler::typeOf(JSContext *cx, JSObject *proxy) |
990 |
ScriptedIndirectProxyHandler::typeOf(JSContext *cx, JSObject *proxy) |
| 989 |
{ |
991 |
{ |
| 990 |
/* |
992 |
/* |
| 991 |
* This function is only here to prevent a regression in |
993 |
* This function is only here to prevent a regression in |
| 992 |
* js1_8_5/extensions/scripted-proxies.js. It will be removed when the |
994 |
* js1_8_5/extensions/scripted-proxies.js. It will be removed when the |
| 993 |
* direct proxy refactor is complete. |
995 |
* direct proxy refactor is complete. |
| 994 |
*/ |
996 |
*/ |
| 995 |
return BaseProxyHandler::typeOf(cx, proxy); |
997 |
return BaseProxyHandler::typeOf(cx, proxy); |
| 996 |
} |
998 |
} |
| 997 |
|
999 |
|
| 998 |
bool |
1000 |
bool |
| 999 |
ScriptedProxyHandler::defaultValue(JSContext *cx, JSObject *proxy, JSType hint, |
1001 |
ScriptedIndirectProxyHandler::defaultValue(JSContext *cx, JSObject *proxy, JSType hint, Value *vp) |
| 1000 |
Value *vp) |
|
|
| 1001 |
{ |
1002 |
{ |
| 1002 |
/* |
1003 |
/* |
| 1003 |
* This function is only here to prevent bug 757063. It will be removed when |
1004 |
* This function is only here to prevent bug 757063. It will be removed when |
| 1004 |
* the direct proxy refactor is complete. |
1005 |
* the direct proxy refactor is complete. |
| 1005 |
*/ |
1006 |
*/ |
| 1006 |
return BaseProxyHandler::defaultValue(cx, proxy, hint, vp); |
1007 |
return BaseProxyHandler::defaultValue(cx, proxy, hint, vp); |
| 1007 |
} |
1008 |
} |
| 1008 |
|
1009 |
|
| 1009 |
ScriptedProxyHandler ScriptedProxyHandler::singleton; |
1010 |
ScriptedIndirectProxyHandler ScriptedIndirectProxyHandler::singleton; |
| 1010 |
|
1011 |
|
| 1011 |
bool |
1012 |
bool |
| 1012 |
Proxy::getPropertyDescriptor(JSContext *cx, JSObject *proxy, jsid id, bool set, |
1013 |
Proxy::getPropertyDescriptor(JSContext *cx, JSObject *proxy, jsid id, bool set, |
| 1013 |
PropertyDescriptor *desc) |
1014 |
PropertyDescriptor *desc) |
| 1014 |
{ |
1015 |
{ |
| 1015 |
JS_CHECK_RECURSION(cx, return false); |
1016 |
JS_CHECK_RECURSION(cx, return false); |
| 1016 |
return GetProxyHandler(proxy)->getPropertyDescriptor(cx, proxy, id, set, desc); |
1017 |
return GetProxyHandler(proxy)->getPropertyDescriptor(cx, proxy, id, set, desc); |
| 1017 |
} |
1018 |
} |
|
Lines 1788-1805
proxy_create(JSContext *cx, unsigned arg
|
Link Here
|
|---|
|
| 1788 |
proto = &vp[3].toObject(); |
1789 |
proto = &vp[3].toObject(); |
| 1789 |
parent = proto->getParent(); |
1790 |
parent = proto->getParent(); |
| 1790 |
} else { |
1791 |
} else { |
| 1791 |
JS_ASSERT(IsFunctionObject(vp[0])); |
1792 |
JS_ASSERT(IsFunctionObject(vp[0])); |
| 1792 |
proto = NULL; |
1793 |
proto = NULL; |
| 1793 |
} |
1794 |
} |
| 1794 |
if (!parent) |
1795 |
if (!parent) |
| 1795 |
parent = vp[0].toObject().getParent(); |
1796 |
parent = vp[0].toObject().getParent(); |
| 1796 |
JSObject *proxy = NewProxyObject(cx, &ScriptedProxyHandler::singleton, ObjectValue(*handler), |
1797 |
JSObject *proxy = NewProxyObject(cx, &ScriptedIndirectProxyHandler::singleton, |
| 1797 |
proto, parent); |
1798 |
ObjectValue(*handler), proto, parent); |
| 1798 |
if (!proxy) |
1799 |
if (!proxy) |
| 1799 |
return false; |
1800 |
return false; |
| 1800 |
|
1801 |
|
| 1801 |
vp->setObject(*proxy); |
1802 |
vp->setObject(*proxy); |
| 1802 |
return true; |
1803 |
return true; |
| 1803 |
} |
1804 |
} |
| 1804 |
|
1805 |
|
| 1805 |
static JSBool |
1806 |
static JSBool |
|
Lines 1825-1843
proxy_createFunction(JSContext *cx, unsi
|
Link Here
|
|---|
|
| 1825 |
return false; |
1826 |
return false; |
| 1826 |
JSObject *construct = NULL; |
1827 |
JSObject *construct = NULL; |
| 1827 |
if (argc > 2) { |
1828 |
if (argc > 2) { |
| 1828 |
construct = ValueToCallable(cx, &vp[4]); |
1829 |
construct = ValueToCallable(cx, &vp[4]); |
| 1829 |
if (!construct) |
1830 |
if (!construct) |
| 1830 |
return false; |
1831 |
return false; |
| 1831 |
} |
1832 |
} |
| 1832 |
|
1833 |
|
| 1833 |
JSObject *proxy = NewProxyObject(cx, &ScriptedProxyHandler::singleton, |
1834 |
JSObject *proxy = NewProxyObject(cx, &ScriptedIndirectProxyHandler::singleton, |
| 1834 |
ObjectValue(*handler), |
1835 |
ObjectValue(*handler), proto, parent, call, construct); |
| 1835 |
proto, parent, call, construct); |
|
|
| 1836 |
if (!proxy) |
1836 |
if (!proxy) |
| 1837 |
return false; |
1837 |
return false; |
| 1838 |
|
1838 |
|
| 1839 |
vp->setObject(*proxy); |
1839 |
vp->setObject(*proxy); |
| 1840 |
return true; |
1840 |
return true; |
| 1841 |
} |
1841 |
} |
| 1842 |
|
1842 |
|
| 1843 |
static JSFunctionSpec static_methods[] = { |
1843 |
static JSFunctionSpec static_methods[] = { |