Changeset 56314 in webkit for trunk/JavaScriptCore/API/tests/testapi.c
- Timestamp:
- Mar 21, 2010, 12:40:04 AM (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/JavaScriptCore/API/tests/testapi.c
r56189 r56314 43 43 #endif 44 44 45 bool JSObjectSetPrivateProperty(JSContextRef ctx, JSObjectRef object, JSStringRef propertyName, JSValueRef value); 46 JSValueRef JSObjectGetPrivateProperty(JSContextRef ctx, JSObjectRef object, JSStringRef propertyName); 47 bool JSObjectDeletePrivateProperty(JSContextRef ctx, JSObjectRef object, JSStringRef propertyName); 48 45 49 static JSGlobalContextRef context; 46 50 static int failed; … … 754 758 755 759 static JSValueRef jsNumberValue = NULL; 760 761 static JSObjectRef aHeapRef = NULL; 756 762 757 763 static void makeGlobalNumberValue(JSContextRef context) { … … 870 876 JSObjectSetProperty(context, globalObject, EmptyObjectIString, EmptyObject, kJSPropertyAttributeNone, NULL); 871 877 JSStringRelease(EmptyObjectIString); 872 878 879 JSStringRef lengthStr = JSStringCreateWithUTF8CString("length"); 880 aHeapRef = JSObjectMakeArray(context, 0, 0, 0); 881 JSObjectSetProperty(context, aHeapRef, lengthStr, JSValueMakeNumber(context, 10), 0, 0); 882 JSStringRef privatePropertyName = JSStringCreateWithUTF8CString("privateProperty"); 883 if (!JSObjectSetPrivateProperty(context, myObject, privatePropertyName, aHeapRef)) { 884 printf("FAIL: Could not set private property.\n"); 885 failed = 1; 886 } else { 887 printf("PASS: Set private property.\n"); 888 } 889 if (JSObjectSetPrivateProperty(context, aHeapRef, privatePropertyName, aHeapRef)) { 890 printf("FAIL: JSObjectSetPrivateProperty should fail on non-API objects.\n"); 891 failed = 1; 892 } else { 893 printf("PASS: Did not allow JSObjectSetPrivateProperty on a non-API object.\n"); 894 } 895 if (JSObjectGetPrivateProperty(context, myObject, privatePropertyName) != aHeapRef) { 896 printf("FAIL: Could not retrieve private property.\n"); 897 failed = 1; 898 } else 899 printf("PASS: Retrieved private property.\n"); 900 if (JSObjectGetPrivateProperty(context, aHeapRef, privatePropertyName)) { 901 printf("FAIL: JSObjectGetPrivateProperty should return NULL when called on a non-API object.\n"); 902 failed = 1; 903 } else 904 printf("PASS: JSObjectGetPrivateProperty return NULL.\n"); 905 906 if (JSObjectGetProperty(context, myObject, privatePropertyName, 0) == aHeapRef) { 907 printf("FAIL: Accessed private property through ordinary property lookup.\n"); 908 failed = 1; 909 } else 910 printf("PASS: Cannot access private property through ordinary property lookup.\n"); 911 912 JSGarbageCollect(context); 913 914 for (int i = 0; i < 10000; i++) 915 JSObjectMake(context, 0, 0); 916 917 if (JSValueToNumber(context, JSObjectGetProperty(context, aHeapRef, lengthStr, 0), 0) != 10) { 918 printf("FAIL: Private property has been collected.\n"); 919 failed = 1; 920 } else 921 printf("PASS: Private property does not appear to have been collected.\n"); 922 JSStringRelease(lengthStr); 923 873 924 JSStringRef validJSON = JSStringCreateWithUTF8CString("{\"aProperty\":true}"); 874 925 JSValueRef jsonObject = JSValueMakeFromJSONString(context, validJSON);
Note:
See TracChangeset
for help on using the changeset viewer.