Changeset 242982 in webkit
- Timestamp:
- Mar 14, 2019, 6:28:49 PM (7 years ago)
- Location:
- trunk/Source/JavaScriptCore
- Files:
-
- 4 edited
-
API/JSScript.h (modified) (1 diff)
-
API/JSScript.mm (modified) (1 diff)
-
API/tests/testapi.mm (modified) (2 diffs)
-
ChangeLog (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/JavaScriptCore/API/JSScript.h
r241929 r242982 101 101 /*! 102 102 @method 103 @abstract Returns true when evaluating this JSScript will use the bytecode cache. Returns false otherwise. 104 */ 105 - (BOOL)isUsingBytecodeCache; 106 107 /*! 108 @method 103 109 @abstract Returns the JSScriptType of this JSScript. 104 110 */ -
trunk/Source/JavaScriptCore/API/JSScript.mm
r242980 r242982 221 221 } 222 222 223 - (BOOL)isUsingBytecodeCache 224 { 225 return !!m_cachedBytecode.size(); 226 } 227 223 228 - (NSURL *)sourceURL 224 229 { -
trunk/Source/JavaScriptCore/API/tests/testapi.mm
r242980 r242982 2238 2238 } 2239 2239 2240 static void testIsUsingBytecodeCacheAccessor() 2241 { 2242 NSURL* cachePath = tempFile(@"foo.program.cache"); 2243 NSURL* sourceURL = [NSURL URLWithString:@"my-path"]; 2244 NSString *source = @"function foo() { return 1337; } foo();"; 2245 2246 @autoreleasepool { 2247 JSVirtualMachine *vm = [[JSVirtualMachine alloc] init]; 2248 JSContext* context = [[JSContext alloc] initWithVirtualMachine:vm]; 2249 JSScript *script = [JSScript scriptOfType:kJSScriptTypeProgram withSource:source andSourceURL:sourceURL andBytecodeCache:cachePath inVirtualMachine:vm error:nil]; 2250 RELEASE_ASSERT(script); 2251 checkResult(@"Should not yet be using the bytecode cache", ![script isUsingBytecodeCache]); 2252 checkResult(@"Should be able to cache the script", [script cacheBytecodeWithError:nil]); 2253 checkResult(@"Should now using the bytecode cache", [script isUsingBytecodeCache]); 2254 JSC::Options::forceDiskCache() = true; 2255 JSValue *result = [context evaluateJSScript:script]; 2256 JSC::Options::forceDiskCache() = false; 2257 checkResult(@"Result should be 1337", [result isNumber] && [result toInt32] == 1337); 2258 } 2259 2260 @autoreleasepool { 2261 JSVirtualMachine *vm = [[JSVirtualMachine alloc] init]; 2262 JSContext* context = [[JSContext alloc] initWithVirtualMachine:vm]; 2263 JSScript *script = [JSScript scriptOfType:kJSScriptTypeProgram withSource:source andSourceURL:sourceURL andBytecodeCache:cachePath inVirtualMachine:vm error:nil]; 2264 RELEASE_ASSERT(script); 2265 checkResult(@"Should be using the bytecode cache", [script isUsingBytecodeCache]); 2266 JSValue *result = [context evaluateJSScript:script]; 2267 checkResult(@"Result should be 1337", [result isNumber] && [result toInt32] == 1337); 2268 } 2269 2270 NSFileManager* fileManager = [NSFileManager defaultManager]; 2271 BOOL removedAll = [fileManager removeItemAtURL:cachePath error:nil]; 2272 checkResult(@"Successfully removed cache file", removedAll); 2273 } 2274 2240 2275 @interface JSContextFileLoaderDelegate : JSContext <JSModuleLoaderDelegate> 2241 2276 … … 2447 2482 RUN(testCacheFileFailsWhenItsAlreadyCached()); 2448 2483 RUN(testCanCacheManyFilesWithTheSameVM()); 2484 RUN(testIsUsingBytecodeCacheAccessor()); 2449 2485 2450 2486 RUN(testLoaderRejectsNilScriptURL()); -
trunk/Source/JavaScriptCore/ChangeLog
r242980 r242982 1 2019-03-14 Saam barati <sbarati@apple.com> 2 3 JSScript should have an accessor saying if it's cached or not 4 https://bugs.webkit.org/show_bug.cgi?id=195783 5 6 Reviewed by Michael Saboff. 7 8 * API/JSScript.h: 9 * API/JSScript.mm: 10 (-[JSScript isUsingBytecodeCache]): 11 * API/tests/testapi.mm: 12 (testIsUsingBytecodeCacheAccessor): 13 (testObjectiveCAPI): 14 1 15 2019-03-14 Saam barati <sbarati@apple.com> 2 16
Note:
See TracChangeset
for help on using the changeset viewer.