Changeset 186966 in webkit for trunk/Source/JavaScriptCore/API
- Timestamp:
- Jul 17, 2015, 3:40:40 PM (10 years ago)
- Location:
- trunk/Source/JavaScriptCore/API
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/JavaScriptCore/API/JSContextRef.cpp
r185346 r186966 60 60 using namespace JSC; 61 61 62 static RuntimeFlags javaScriptRuntimeFlags(const JSGlobalObject* globalObject) 63 { 64 RuntimeFlags runtimeFlags = JSGlobalObject::javaScriptRuntimeFlags(globalObject); 65 runtimeFlags.setPromiseDisabled(true); 66 return runtimeFlags; 67 } 68 69 const GlobalObjectMethodTable JSC::javaScriptCoreAPIGlobalObjectMethodTable = { &JSGlobalObject::allowsAccessFrom, &JSGlobalObject::supportsProfiling, &JSGlobalObject::supportsRichSourceInfo, &JSGlobalObject::shouldInterruptScript, &javaScriptRuntimeFlags, nullptr, &JSGlobalObject::shouldInterruptScriptBeforeTimeout }; 62 const GlobalObjectMethodTable JSC::javaScriptCoreAPIGlobalObjectMethodTable = { &JSGlobalObject::allowsAccessFrom, &JSGlobalObject::supportsProfiling, &JSGlobalObject::supportsRichSourceInfo, &JSGlobalObject::shouldInterruptScript, &JSGlobalObject::javaScriptRuntimeFlags, nullptr, &JSGlobalObject::shouldInterruptScriptBeforeTimeout }; 70 63 71 64 // From the API's perspective, a context group remains alive iff -
trunk/Source/JavaScriptCore/API/tests/testapi.c
r183754 r186966 1855 1855 { 1856 1856 JSStringRef promiseProperty = JSStringCreateWithUTF8CString("Promise"); 1857 ASSERT( !JSObjectHasProperty(context, globalObject, promiseProperty));1857 ASSERT(JSObjectHasProperty(context, globalObject, promiseProperty)); 1858 1858 JSStringRelease(promiseProperty); 1859 1859 } 1860 1860 { 1861 1861 JSStringRef script = JSStringCreateWithUTF8CString("typeof Promise"); 1862 JSStringRef undefined = JSStringCreateWithUTF8CString("undefined");1862 JSStringRef function = JSStringCreateWithUTF8CString("function"); 1863 1863 JSValueRef value = JSEvaluateScript(context, script, NULL, NULL, 1, NULL); 1864 1864 ASSERT(JSValueIsString(context, value)); 1865 1865 JSStringRef valueAsString = JSValueToStringCopy(context, value, NULL); 1866 ASSERT(JSStringIsEqual(valueAsString, undefined));1866 ASSERT(JSStringIsEqual(valueAsString, function)); 1867 1867 JSStringRelease(valueAsString); 1868 JSStringRelease( undefined);1868 JSStringRelease(function); 1869 1869 JSStringRelease(script); 1870 1870 } 1871 printf("PASS: Promise is not exposed under JSContext API.\n"); 1871 printf("PASS: Promise is exposed under JSContext API.\n"); 1872 } 1873 1874 // Check microtasks. 1875 { 1876 JSGlobalContextRef context = JSGlobalContextCreateInGroup(NULL, NULL); 1877 { 1878 JSObjectRef globalObject = JSContextGetGlobalObject(context); 1879 JSValueRef exception; 1880 JSStringRef code = JSStringCreateWithUTF8CString("result = 0; Promise.resolve(42).then(function (value) { result = value; });"); 1881 JSStringRef file = JSStringCreateWithUTF8CString(""); 1882 assertTrue(JSEvaluateScript(context, code, globalObject, file, 1, &exception), "An exception should not be thrown"); 1883 JSStringRelease(code); 1884 JSStringRelease(file); 1885 1886 JSStringRef resultProperty = JSStringCreateWithUTF8CString("result"); 1887 ASSERT(JSObjectHasProperty(context, globalObject, resultProperty)); 1888 1889 JSValueRef resultValue = JSObjectGetProperty(context, globalObject, resultProperty, &exception); 1890 assertEqualsAsNumber(resultValue, 42); 1891 JSStringRelease(resultProperty); 1892 } 1893 JSGlobalContextRelease(context); 1872 1894 } 1873 1895 -
trunk/Source/JavaScriptCore/API/tests/testapi.mm
r185122 r186966 541 541 @autoreleasepool { 542 542 JSContext *context = [[JSContext alloc] init]; 543 checkResult(@"Promise is not exposed",[context[@"Promise"] isUndefined]);543 checkResult(@"Promise is exposed", ![context[@"Promise"] isUndefined]); 544 544 JSValue *result = [context evaluateScript:@"typeof Promise"]; 545 checkResult(@"typeof Promise is 'undefined'", result.isString && [result isEqualToObject:@"undefined"]); 545 checkResult(@"typeof Promise is 'function'", result.isString && [result isEqualToObject:@"function"]); 546 } 547 548 @autoreleasepool { 549 JSVirtualMachine* vm = [[JSVirtualMachine alloc] init]; 550 JSContext* context = [[JSContext alloc] initWithVirtualMachine:vm]; 551 [context evaluateScript:@"result = 0; Promise.resolve(42).then(function (value) { result = value; });"]; 552 checkResult(@"Microtask is drained", [context[@"result"] isEqualToObject:@42]); 546 553 } 547 554
Note:
See TracChangeset
for help on using the changeset viewer.