Title: [242982] trunk/Source/_javascript_Core
- Revision
- 242982
- Author
- [email protected]
- Date
- 2019-03-14 18:28:49 -0700 (Thu, 14 Mar 2019)
Log 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):
Modified Paths
Diff
Modified: trunk/Source/_javascript_Core/API/JSScript.h (242981 => 242982)
--- trunk/Source/_javascript_Core/API/JSScript.h 2019-03-15 01:27:58 UTC (rev 242981)
+++ trunk/Source/_javascript_Core/API/JSScript.h 2019-03-15 01:28:49 UTC (rev 242982)
@@ -100,6 +100,12 @@
/*!
@method
+ @abstract Returns true when evaluating this JSScript will use the bytecode cache. Returns false otherwise.
+ */
+- (BOOL)isUsingBytecodeCache;
+
+/*!
+ @method
@abstract Returns the JSScriptType of this JSScript.
*/
- (JSScriptType)type;
Modified: trunk/Source/_javascript_Core/API/JSScript.mm (242981 => 242982)
--- trunk/Source/_javascript_Core/API/JSScript.mm 2019-03-15 01:27:58 UTC (rev 242981)
+++ trunk/Source/_javascript_Core/API/JSScript.mm 2019-03-15 01:28:49 UTC (rev 242982)
@@ -220,6 +220,11 @@
return YES;
}
+- (BOOL)isUsingBytecodeCache
+{
+ return !!m_cachedBytecode.size();
+}
+
- (NSURL *)sourceURL
{
return m_sourceURL.get();
Modified: trunk/Source/_javascript_Core/API/tests/testapi.mm (242981 => 242982)
--- trunk/Source/_javascript_Core/API/tests/testapi.mm 2019-03-15 01:27:58 UTC (rev 242981)
+++ trunk/Source/_javascript_Core/API/tests/testapi.mm 2019-03-15 01:28:49 UTC (rev 242982)
@@ -2237,6 +2237,41 @@
checkResult(@"Removed all cache files", removedAll);
}
+static void testIsUsingBytecodeCacheAccessor()
+{
+ NSURL* cachePath = tempFile(@"foo.program.cache");
+ NSURL* sourceURL = [NSURL URLWithString:@"my-path"];
+ NSString *source = @"function foo() { return 1337; } foo();";
+
+ @autoreleasepool {
+ JSVirtualMachine *vm = [[JSVirtualMachine alloc] init];
+ JSContext* context = [[JSContext alloc] initWithVirtualMachine:vm];
+ JSScript *script = [JSScript scriptOfType:kJSScriptTypeProgram withSource:source andSourceURL:sourceURL andBytecodeCache:cachePath inVirtualMachine:vm error:nil];
+ RELEASE_ASSERT(script);
+ checkResult(@"Should not yet be using the bytecode cache", ![script isUsingBytecodeCache]);
+ checkResult(@"Should be able to cache the script", [script cacheBytecodeWithError:nil]);
+ checkResult(@"Should now using the bytecode cache", [script isUsingBytecodeCache]);
+ JSC::Options::forceDiskCache() = true;
+ JSValue *result = [context evaluateJSScript:script];
+ JSC::Options::forceDiskCache() = false;
+ checkResult(@"Result should be 1337", [result isNumber] && [result toInt32] == 1337);
+ }
+
+ @autoreleasepool {
+ JSVirtualMachine *vm = [[JSVirtualMachine alloc] init];
+ JSContext* context = [[JSContext alloc] initWithVirtualMachine:vm];
+ JSScript *script = [JSScript scriptOfType:kJSScriptTypeProgram withSource:source andSourceURL:sourceURL andBytecodeCache:cachePath inVirtualMachine:vm error:nil];
+ RELEASE_ASSERT(script);
+ checkResult(@"Should be using the bytecode cache", [script isUsingBytecodeCache]);
+ JSValue *result = [context evaluateJSScript:script];
+ checkResult(@"Result should be 1337", [result isNumber] && [result toInt32] == 1337);
+ }
+
+ NSFileManager* fileManager = [NSFileManager defaultManager];
+ BOOL removedAll = [fileManager removeItemAtURL:cachePath error:nil];
+ checkResult(@"Successfully removed cache file", removedAll);
+}
+
@interface JSContextFileLoaderDelegate : JSContext <JSModuleLoaderDelegate>
+ (instancetype)newContext;
@@ -2446,6 +2481,7 @@
RUN(testProgramJSScriptException());
RUN(testCacheFileFailsWhenItsAlreadyCached());
RUN(testCanCacheManyFilesWithTheSameVM());
+ RUN(testIsUsingBytecodeCacheAccessor());
RUN(testLoaderRejectsNilScriptURL());
RUN(testLoaderRejectsFailedFetch());
Modified: trunk/Source/_javascript_Core/ChangeLog (242981 => 242982)
--- trunk/Source/_javascript_Core/ChangeLog 2019-03-15 01:27:58 UTC (rev 242981)
+++ trunk/Source/_javascript_Core/ChangeLog 2019-03-15 01:28:49 UTC (rev 242982)
@@ -1,5 +1,19 @@
2019-03-14 Saam barati <[email protected]>
+ 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):
+
+2019-03-14 Saam barati <[email protected]>
+
Remove retain cycle from JSScript and also don't keep the cache file descriptor open so many JSScripts can be cached in a loop
https://bugs.webkit.org/show_bug.cgi?id=195782
<rdar://problem/48880625>
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes