Diff
Modified: trunk/Source/_javascript_Core/API/JSAPIGlobalObject.mm (244400 => 244401)
--- trunk/Source/_javascript_Core/API/JSAPIGlobalObject.mm 2019-04-17 20:20:40 UTC (rev 244400)
+++ trunk/Source/_javascript_Core/API/JSAPIGlobalObject.mm 2019-04-17 21:35:06 UTC (rev 244401)
@@ -194,18 +194,10 @@
if (UNLIKELY([jsScript type] != kJSScriptTypeModule))
return rejectPromise("The JSScript that was provided did not have expected type of kJSScriptTypeModule."_s);
- // FIXME: The SPI we're deprecating did not require sourceURL, so we just
- // ignore this check for such use cases until we can remove that SPI. Once
- // we do that, we can remove the null check for sourceURL:
- // https://bugs.webkit.org/show_bug.cgi?id=194909
- if (NSURL *sourceURL = [jsScript sourceURL]) {
- String oldModuleKey { [sourceURL absoluteString] };
- if (UNLIKELY(Identifier::fromString(&vm, oldModuleKey) != moduleKey))
- return rejectPromise(makeString("The same JSScript was provided for two different identifiers, previously: ", oldModuleKey, " and now: ", moduleKey.string()));
- } else {
- [jsScript setSourceURL:[NSURL URLWithString:static_cast<NSString *>(moduleKey.string())]];
- source = [jsScript jsSourceCode];
- }
+ NSURL *sourceURL = [jsScript sourceURL];
+ String oldModuleKey { [sourceURL absoluteString] };
+ if (UNLIKELY(Identifier::fromString(&vm, oldModuleKey) != moduleKey))
+ return rejectPromise(makeString("The same JSScript was provided for two different identifiers, previously: ", oldModuleKey, " and now: ", moduleKey.string()));
args.append(source);
call(exec, deferredPromise->JSPromiseDeferred::resolve(), args, "This should never be seen...");
Modified: trunk/Source/_javascript_Core/API/JSScript.h (244400 => 244401)
--- trunk/Source/_javascript_Core/API/JSScript.h 2019-04-17 20:20:40 UTC (rev 244400)
+++ trunk/Source/_javascript_Core/API/JSScript.h 2019-04-17 21:35:06 UTC (rev 244401)
@@ -47,21 +47,6 @@
@interface JSScript : NSObject
/*!
- This SPI is deprecated and should not be used. Use "scriptOfType:withSource:andSourceURL:andBytecodeCache:inVirtualMachine:error:" instead.
- */
-+ (nullable instancetype)scriptWithSource:(NSString *)source inVirtualMachine:(JSVirtualMachine *)vm JSC_API_DEPRECATED("Use +scriptOfType:withSource:andSourceURL:andBytecodeCache:inVirtualMachine:error: instead.", macos(JSC_MAC_TBA, JSC_MAC_TBA), ios(JSC_IOS_TBA, JSC_IOS_TBA));
-
-/*!
- This SPI is deprecated and should not be used. Use "scriptOfType:memoryMappedFromASCIIFile:withSourceURL:andBytecodeCache:inVirtualMachine:error:" instead.
- */
-+ (nullable instancetype)scriptFromASCIIFile:(NSURL *)filePath inVirtualMachine:(JSVirtualMachine *)vm withCodeSigning:(nullable NSURL *)codeSigningPath andBytecodeCache:(nullable NSURL *)cachePath JSC_API_DEPRECATED("Use +scriptOfType:memoryMappedFromASCIIFile:withSourceURL:andBytecodeCache:inVirtualMachine:error: instead.", macos(JSC_MAC_TBA, JSC_MAC_TBA), ios(JSC_IOS_TBA, JSC_IOS_TBA));
-
-/*!
- This API is deprecated and should not be used.
- */
-+ (nullable instancetype)scriptFromUTF8File:(NSURL *)filePath inVirtualMachine:(JSVirtualMachine *)vm withCodeSigning:(nullable NSURL *)codeSigningPath andBytecodeCache:(nullable NSURL *)cachePath JSC_API_DEPRECATED("Do not use this. Use +scriptOfType:memoryMappedFromASCIIFile:withSourceURL:andBytecodeCache:inVirtualMachine:error: or +scriptOfType:withSource:andSourceURL:andBytecodeCache:inVirtualMachine:error: instead", macos(JSC_MAC_TBA, JSC_MAC_TBA), ios(JSC_IOS_TBA, JSC_IOS_TBA));
-
-/*!
@method
@abstract Create a JSScript for the specified virtual machine.
@param type The type of _javascript_ source.
Modified: trunk/Source/_javascript_Core/API/JSScript.mm (244400 => 244401)
--- trunk/Source/_javascript_Core/API/JSScript.mm 2019-04-17 20:20:40 UTC (rev 244400)
+++ trunk/Source/_javascript_Core/API/JSScript.mm 2019-04-17 21:35:06 UTC (rev 244401)
@@ -53,75 +53,6 @@
RefPtr<JSC::CachedBytecode> m_cachedBytecode;
}
-+ (instancetype)scriptWithSource:(NSString *)source inVirtualMachine:(JSVirtualMachine *)vm
-{
- JSScript *result = [[[JSScript alloc] init] autorelease];
- result->m_source = source;
- result->m_virtualMachine = vm;
- result->m_type = kJSScriptTypeModule;
- return result;
-}
-
-template<typename Vector>
-static bool fillBufferWithContentsOfFile(FILE* file, Vector& buffer)
-{
- // We might have injected "use strict"; at the top.
- size_t initialSize = buffer.size();
- if (fseek(file, 0, SEEK_END) == -1)
- return false;
- long bufferCapacity = ftell(file);
- if (bufferCapacity == -1)
- return false;
- if (fseek(file, 0, SEEK_SET) == -1)
- return false;
- buffer.resize(bufferCapacity + initialSize);
- size_t readSize = fread(buffer.data() + initialSize, 1, buffer.size(), file);
- return readSize == buffer.size() - initialSize;
-}
-
-static bool fillBufferWithContentsOfFile(const String& fileName, Vector<LChar>& buffer)
-{
- FILE* f = fopen(fileName.utf8().data(), "rb");
- if (!f) {
- fprintf(stderr, "Could not open file: %s\n", fileName.utf8().data());
- return false;
- }
-
- bool result = fillBufferWithContentsOfFile(f, buffer);
- fclose(f);
-
- return result;
-}
-
-
-+ (instancetype)scriptFromASCIIFile:(NSURL *)filePath inVirtualMachine:(JSVirtualMachine *)vm withCodeSigning:(NSURL *)codeSigningPath andBytecodeCache:(NSURL *)cachePath
-{
- UNUSED_PARAM(codeSigningPath);
- UNUSED_PARAM(cachePath);
-
- URL filePathURL([filePath absoluteURL]);
- if (!filePathURL.isLocalFile())
- return nil;
-
- Vector<LChar> buffer;
- if (!fillBufferWithContentsOfFile(filePathURL.fileSystemPath(), buffer))
- return nil;
-
- if (!charactersAreAllASCII(buffer.data(), buffer.size()))
- return nil;
-
- JSScript *result = [[[JSScript alloc] init] autorelease];
- result->m_virtualMachine = vm;
- result->m_source = String::fromUTF8WithLatin1Fallback(buffer.data(), buffer.size());
- result->m_type = kJSScriptTypeModule;
- return result;
-}
-
-+ (instancetype)scriptFromUTF8File:(NSURL *)filePath inVirtualMachine:(JSVirtualMachine *)vm withCodeSigning:(NSURL *)codeSigningPath andBytecodeCache:(NSURL *)cachePath
-{
- return [JSScript scriptFromASCIIFile:filePath inVirtualMachine:vm withCodeSigning:codeSigningPath andBytecodeCache:cachePath];
-}
-
static JSScript *createError(NSString *message, NSError** error)
{
if (error)
@@ -331,11 +262,6 @@
return YES;
}
-- (void)setSourceURL:(NSURL *)url
-{
- m_sourceURL = url;
-}
-
@end
#endif
Modified: trunk/Source/_javascript_Core/API/JSScriptInternal.h (244400 => 244401)
--- trunk/Source/_javascript_Core/API/JSScriptInternal.h 2019-04-17 20:20:40 UTC (rev 244400)
+++ trunk/Source/_javascript_Core/API/JSScriptInternal.h 2019-04-17 21:35:06 UTC (rev 244401)
@@ -52,8 +52,6 @@
- (JSC::JSSourceCode*)jsSourceCode;
- (JSC::SourceCode)sourceCode;
- (BOOL)writeCache:(String&)error;
-// FIXME: Remove this once we require sourceURL upon creation: https://bugs.webkit.org/show_bug.cgi?id=194909
-- (void)setSourceURL:(NSURL *)url;
@end
Modified: trunk/Source/_javascript_Core/API/tests/testapi.mm (244400 => 244401)
--- trunk/Source/_javascript_Core/API/tests/testapi.mm 2019-04-17 20:20:40 UTC (rev 244400)
+++ trunk/Source/_javascript_Core/API/tests/testapi.mm 2019-04-17 21:35:06 UTC (rev 244401)
@@ -1877,11 +1877,21 @@
{
@autoreleasepool {
auto *context = [JSContextFetchDelegate contextWithBlockForFetch:^(JSContext *context, JSValue *identifier, JSValue *resolve, JSValue *reject) {
- if ([identifier isEqualToObject:@"file:///directory/bar.js"])
- [resolve callWithArguments:@[[JSScript scriptWithSource:@"import \"../foo.js\"; export let exp = null;" inVirtualMachine:[context virtualMachine]]]];
- else if ([identifier isEqualToObject:@"file:///foo.js"])
- [resolve callWithArguments:@[[JSScript scriptWithSource:@"globalThis.ran = null;" inVirtualMachine:[context virtualMachine]]]];
- else
+ if ([identifier isEqualToObject:@"file:///directory/bar.js"]) {
+ [resolve callWithArguments:@[[JSScript scriptOfType:kJSScriptTypeModule
+ withSource:@"import \"../foo.js\"; export let exp = null;"
+ andSourceURL:[NSURL fileURLWithPath:@"/directory/bar.js"]
+ andBytecodeCache:nil
+ inVirtualMachine:[context virtualMachine]
+ error:nil]]];
+ } else if ([identifier isEqualToObject:@"file:///foo.js"]) {
+ [resolve callWithArguments:@[[JSScript scriptOfType:kJSScriptTypeModule
+ withSource:@"globalThis.ran = null;"
+ andSourceURL:[NSURL fileURLWithPath:@"/foo.js"]
+ andBytecodeCache:nil
+ inVirtualMachine:[context virtualMachine]
+ error:nil]]];
+ } else
[reject callWithArguments:@[[JSValue valueWithNewErrorFromMessage:@"Weird path" inContext:context]]];
}];
context.moduleLoaderDelegate = context;
@@ -1895,11 +1905,21 @@
{
@autoreleasepool {
auto *context = [JSContextFetchDelegate contextWithBlockForFetch:^(JSContext *context, JSValue *identifier, JSValue *resolve, JSValue *reject) {
- if ([identifier isEqualToObject:@"file:///directory/bar.js"])
- [resolve callWithArguments:@[[JSScript scriptWithSource:@"import { n } from \"../foo.js\"; export let exp = n;" inVirtualMachine:[context virtualMachine]]]];
- else if ([identifier isEqualToObject:@"file:///foo.js"])
- [resolve callWithArguments:@[[JSScript scriptWithSource:@"import \"directory/bar.js\"; globalThis.ran = null; export let n = null;" inVirtualMachine:[context virtualMachine]]]];
- else
+ if ([identifier isEqualToObject:@"file:///directory/bar.js"]) {
+ [resolve callWithArguments:@[[JSScript scriptOfType:kJSScriptTypeModule
+ withSource:@"import { n } from \"../foo.js\"; export let exp = n;"
+ andSourceURL:[NSURL fileURLWithPath:@"/directory/bar.js"]
+ andBytecodeCache:nil
+ inVirtualMachine:[context virtualMachine]
+ error:nil]]];
+ } else if ([identifier isEqualToObject:@"file:///foo.js"]) {
+ [resolve callWithArguments:@[[JSScript scriptOfType:kJSScriptTypeModule
+ withSource:@"import \"directory/bar.js\"; globalThis.ran = null; export let n = null;"
+ andSourceURL:[NSURL fileURLWithPath:@"/foo.js"]
+ andBytecodeCache:nil
+ inVirtualMachine:[context virtualMachine]
+ error:nil]]];
+ } else
[reject callWithArguments:@[[JSValue valueWithNewErrorFromMessage:@"Weird path" inContext:context]]];
}];
context.moduleLoaderDelegate = context;
@@ -1914,13 +1934,28 @@
{
@autoreleasepool {
auto *context = [JSContextFetchDelegate contextWithBlockForFetch:^(JSContext *context, JSValue *identifier, JSValue *resolve, JSValue *reject) {
- if ([identifier isEqualToObject:@"file:///directory/bar.js"])
- [resolve callWithArguments:@[[JSScript scriptWithSource:@"import { n } from \"../foo.js\"; export let foo = n;" inVirtualMachine:[context virtualMachine]]]];
- else if ([identifier isEqualToObject:@"file:///foo.js"])
- [resolve callWithArguments:@[[JSScript scriptWithSource:@"import \"otherDirectory/baz.js\"; export let n = null;" inVirtualMachine:[context virtualMachine]]]];
- else if ([identifier isEqualToObject:@"file:///otherDirectory/baz.js"])
- [resolve callWithArguments:@[[JSScript scriptWithSource:@"import { foo } from \"../directory/bar.js\"; globalThis.ran = null; export let exp = foo;" inVirtualMachine:[context virtualMachine]]]];
- else
+ if ([identifier isEqualToObject:@"file:///directory/bar.js"]) {
+ [resolve callWithArguments:@[[JSScript scriptOfType:kJSScriptTypeModule
+ withSource:@"import { n } from \"../foo.js\"; export let foo = n;"
+ andSourceURL:[NSURL fileURLWithPath:@"/directory/bar.js"]
+ andBytecodeCache:nil
+ inVirtualMachine:[context virtualMachine]
+ error:nil]]];
+ } else if ([identifier isEqualToObject:@"file:///foo.js"]) {
+ [resolve callWithArguments:@[[JSScript scriptOfType:kJSScriptTypeModule
+ withSource:@"import \"otherDirectory/baz.js\"; export let n = null;"
+ andSourceURL:[NSURL fileURLWithPath:@"/foo.js"]
+ andBytecodeCache:nil
+ inVirtualMachine:[context virtualMachine]
+ error:nil]]];
+ } else if ([identifier isEqualToObject:@"file:///otherDirectory/baz.js"]) {
+ [resolve callWithArguments:@[[JSScript scriptOfType:kJSScriptTypeModule
+ withSource:@"import { foo } from \"../directory/bar.js\"; globalThis.ran = null; export let exp = foo;"
+ andSourceURL:[NSURL fileURLWithPath:@"/otherDirectory/baz.js"]
+ andBytecodeCache:nil
+ inVirtualMachine:[context virtualMachine]
+ error:nil]]];
+ } else
[reject callWithArguments:@[[JSValue valueWithNewErrorFromMessage:@"Weird path" inContext:context]]];
}];
context.moduleLoaderDelegate = context;
@@ -1934,9 +1969,14 @@
{
@autoreleasepool {
auto *context = [JSContextFetchDelegate contextWithBlockForFetch:^(JSContext *context, JSValue *identifier, JSValue *resolve, JSValue *reject) {
- if ([identifier isEqualToObject:@"file:///directory/bar.js"])
- [resolve callWithArguments:@[[JSScript scriptWithSource:@"export let exp = null; globalThis.ran = null;" inVirtualMachine:[context virtualMachine]]]];
- else
+ if ([identifier isEqualToObject:@"file:///directory/bar.js"]) {
+ [resolve callWithArguments:@[[JSScript scriptOfType:kJSScriptTypeModule
+ withSource:@"export let exp = null; globalThis.ran = null;"
+ andSourceURL:[NSURL fileURLWithPath:@"/directory/bar.js"]
+ andBytecodeCache:nil
+ inVirtualMachine:[context virtualMachine]
+ error:nil]]];
+ } else
[reject callWithArguments:@[[JSValue valueWithNewErrorFromMessage:@"Weird path" inContext:context]]];
}];
context.moduleLoaderDelegate = context;
@@ -1973,8 +2013,13 @@
static void testImportModuleTwice()
{
@autoreleasepool {
- auto *context = [JSContextFetchDelegate contextWithBlockForFetch:^(JSContext * context, JSValue *, JSValue *resolve, JSValue *) {
- [resolve callWithArguments:@[[JSScript scriptWithSource:@"ran++; export let exp = 1;" inVirtualMachine:[context virtualMachine]]]];
+ auto *context = [JSContextFetchDelegate contextWithBlockForFetch:^(JSContext * context, JSValue *, JSValue *resolve, JSValue *) {
+ [resolve callWithArguments:@[[JSScript scriptOfType:kJSScriptTypeModule
+ withSource:@"ran++; export let exp = 1;"
+ andSourceURL:[NSURL fileURLWithPath:@"/baz.js"]
+ andBytecodeCache:nil
+ inVirtualMachine:[context virtualMachine]
+ error:nil]]];
}];
context.moduleLoaderDelegate = context;
context[@"ran"] = @(0);
@@ -2309,7 +2354,12 @@
- (void)context:(JSContext *)context fetchModuleForIdentifier:(JSValue *)identifier withResolveHandler:(JSValue *)resolve andRejectHandler:(JSValue *)reject
{
NSURL *filePath = [NSURL URLWithString:[identifier toString]];
- auto *script = [JSScript scriptFromASCIIFile:filePath inVirtualMachine:context.virtualMachine withCodeSigning:nil andBytecodeCache:nil];
+ auto* script = [JSScript scriptOfType:kJSScriptTypeModule
+ memoryMappedFromASCIIFile:filePath
+ withSourceURL:filePath
+ andBytecodeCache:nil
+ inVirtualMachine:context.virtualMachine
+ error:nil];
if (script)
[resolve callWithArguments:@[script]];
else
Modified: trunk/Source/_javascript_Core/ChangeLog (244400 => 244401)
--- trunk/Source/_javascript_Core/ChangeLog 2019-04-17 20:20:40 UTC (rev 244400)
+++ trunk/Source/_javascript_Core/ChangeLog 2019-04-17 21:35:06 UTC (rev 244401)
@@ -1,3 +1,29 @@
+2019-04-17 Saam Barati <sbar...@apple.com>
+
+ Remove deprecated JSScript SPI
+ https://bugs.webkit.org/show_bug.cgi?id=194909
+ <rdar://problem/48283499>
+
+ Reviewed by Keith Miller.
+
+ * API/JSAPIGlobalObject.mm:
+ (JSC::JSAPIGlobalObject::moduleLoaderFetch):
+ * API/JSScript.h:
+ * API/JSScript.mm:
+ (+[JSScript scriptWithSource:inVirtualMachine:]): Deleted.
+ (fillBufferWithContentsOfFile): Deleted.
+ (+[JSScript scriptFromASCIIFile:inVirtualMachine:withCodeSigning:andBytecodeCache:]): Deleted.
+ (+[JSScript scriptFromUTF8File:inVirtualMachine:withCodeSigning:andBytecodeCache:]): Deleted.
+ (-[JSScript setSourceURL:]): Deleted.
+ * API/JSScriptInternal.h:
+ * API/tests/testapi.mm:
+ (testFetch):
+ (testFetchWithTwoCycle):
+ (testFetchWithThreeCycle):
+ (testLoaderResolvesAbsoluteScriptURL):
+ (testImportModuleTwice):
+ (-[JSContextFileLoaderDelegate context:fetchModuleForIdentifier:withResolveHandler:andRejectHandler:]):
+
2019-04-17 Keith Rollin <krol...@apple.com>
Remove JSCBuiltins.cpp from Copy Headers phase