⚠ Archived content — this site is no longer maintained.   Current WebKit documentation is at docs.webkit.org.

Changeset 242982 in webkit


Ignore:
Timestamp:
Mar 14, 2019, 6:28:49 PM (7 years ago)
Author:
sbarati@apple.com
Message:

JSScript should have an accessor saying if it's cached or not
https://bugs.webkit.org/show_bug.cgi?id=195783

Reviewed by Michael Saboff.

  • API/JSScript.h:
  • API/JSScript.mm:

(-[JSScript isUsingBytecodeCache]):

  • API/tests/testapi.mm:

(testIsUsingBytecodeCacheAccessor):
(testObjectiveCAPI):

Location:
trunk/Source/JavaScriptCore
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/JavaScriptCore/API/JSScript.h

    r241929 r242982  
    101101/*!
    102102 @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
    103109 @abstract Returns the JSScriptType of this JSScript.
    104110 */
  • trunk/Source/JavaScriptCore/API/JSScript.mm

    r242980 r242982  
    221221}
    222222
     223- (BOOL)isUsingBytecodeCache
     224{
     225    return !!m_cachedBytecode.size();
     226}
     227
    223228- (NSURL *)sourceURL
    224229{
  • trunk/Source/JavaScriptCore/API/tests/testapi.mm

    r242980 r242982  
    22382238}
    22392239
     2240static 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
    22402275@interface JSContextFileLoaderDelegate : JSContext <JSModuleLoaderDelegate>
    22412276
     
    24472482    RUN(testCacheFileFailsWhenItsAlreadyCached());
    24482483    RUN(testCanCacheManyFilesWithTheSameVM());
     2484    RUN(testIsUsingBytecodeCacheAccessor());
    24492485
    24502486    RUN(testLoaderRejectsNilScriptURL());
  • trunk/Source/JavaScriptCore/ChangeLog

    r242980 r242982  
     12019-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
    1152019-03-14  Saam barati  <sbarati@apple.com>
    216
Note: See TracChangeset for help on using the changeset viewer.