Title: [240194] trunk/Source/_javascript_Core
- Revision
- 240194
- Author
- keith_mil...@apple.com
- Date
- 2019-01-18 19:35:44 -0800 (Fri, 18 Jan 2019)
Log Message
JSScript API should only take ascii files.
https://bugs.webkit.org/show_bug.cgi?id=193420
Reviewed by Saam Barati.
This patch leaves the UTF8 method for binary compatablity, which
will be removed later.
* API/JSScript.h:
* API/JSScript.mm:
(fillBufferWithContentsOfFile):
(+[JSScript scriptFromASCIIFile:inVirtualMachine:withCodeSigning:andBytecodeCache:]):
(+[JSScript scriptFromUTF8File:inVirtualMachine:withCodeSigning:andBytecodeCache:]):
* API/tests/testapi.mm:
(-[JSContextFileLoaderDelegate context:fetchModuleForIdentifier:withResolveHandler:andRejectHandler:]):
Modified Paths
Diff
Modified: trunk/Source/_javascript_Core/API/JSScript.h (240193 => 240194)
--- trunk/Source/_javascript_Core/API/JSScript.h 2019-01-19 03:27:29 UTC (rev 240193)
+++ trunk/Source/_javascript_Core/API/JSScript.h 2019-01-19 03:35:44 UTC (rev 240194)
@@ -52,7 +52,15 @@
@param cachePath A URL containing the path where the VM should cache for future execution.
@result The new script.
@discussion the files at filePath, codeSigningPath, and cachePath should not be externally modified for the lifecycle of vm. Note that codeSigningPath and cachePath are not used currently, but that will change in the near future.
+
+ If the file at filePath is not ascii this method will return nil.
*/
++ (nullable instancetype)scriptFromASCIIFile:(NSURL *)filePath inVirtualMachine:(JSVirtualMachine *)vm withCodeSigning:(nullable NSURL *)codeSigningPath andBytecodeCache:(nullable NSURL *)cachePath;
+
+
+/*!
+ This is deprecated and is equivalent to scriptFromASCIIFile:inVirtualMachine:withCodeSigning:andBytecodeCache:.
+ */
+ (nullable instancetype)scriptFromUTF8File:(NSURL *)filePath inVirtualMachine:(JSVirtualMachine *)vm withCodeSigning:(nullable NSURL *)codeSigningPath andBytecodeCache:(nullable NSURL *)cachePath;
@end
Modified: trunk/Source/_javascript_Core/API/JSScript.mm (240193 => 240194)
--- trunk/Source/_javascript_Core/API/JSScript.mm 2019-01-19 03:27:29 UTC (rev 240193)
+++ trunk/Source/_javascript_Core/API/JSScript.mm 2019-01-19 03:35:44 UTC (rev 240194)
@@ -62,7 +62,7 @@
return readSize == buffer.size() - initialSize;
}
-static bool fillBufferWithContentsOfFile(const String& fileName, Vector<char>& buffer)
+static bool fillBufferWithContentsOfFile(const String& fileName, Vector<LChar>& buffer)
{
FILE* f = fopen(fileName.utf8().data(), "rb");
if (!f) {
@@ -77,7 +77,7 @@
}
-+ (instancetype)scriptFromUTF8File:(NSURL *)filePath inVirtualMachine:(JSVirtualMachine *)vm withCodeSigning:(NSURL *)codeSigningPath andBytecodeCache:(NSURL *)cachePath
++ (instancetype)scriptFromASCIIFile:(NSURL *)filePath inVirtualMachine:(JSVirtualMachine *)vm withCodeSigning:(NSURL *)codeSigningPath andBytecodeCache:(NSURL *)cachePath
{
// FIXME: This should check codeSigning.
UNUSED_PARAM(codeSigningPath);
@@ -88,15 +88,23 @@
if (!filePathURL.isLocalFile())
return nil;
// FIXME: This should mmap the contents of the file instead of copying it into dirty memory.
- Vector<char> buffer;
+ Vector<LChar> buffer;
if (!fillBufferWithContentsOfFile(filePathURL.fileSystemPath(), buffer))
return nil;
+ if (!charactersAreAllASCII(buffer.data(), buffer.size()))
+ return nil;
+
JSScript *result = [[JSScript alloc] init];
result->m_source = String::fromUTF8WithLatin1Fallback(buffer.data(), buffer.size());
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];
+}
+
const String& getJSScriptSourceCode(JSScript *module) { return module->m_source; }
@end
Modified: trunk/Source/_javascript_Core/API/tests/testapi.mm (240193 => 240194)
--- trunk/Source/_javascript_Core/API/tests/testapi.mm 2019-01-19 03:27:29 UTC (rev 240193)
+++ trunk/Source/_javascript_Core/API/tests/testapi.mm 2019-01-19 03:35:44 UTC (rev 240194)
@@ -2017,7 +2017,7 @@
- (void)context:(JSContext *)context fetchModuleForIdentifier:(JSValue *)identifier withResolveHandler:(JSValue *)resolve andRejectHandler:(JSValue *)reject
{
NSURL *filePath = [NSURL URLWithString:[identifier toString]];
- auto *script = [JSScript scriptFromUTF8File:filePath inVirtualMachine:[context virtualMachine] withCodeSigning:nil andBytecodeCache:nil];
+ auto *script = [JSScript scriptFromASCIIFile:filePath inVirtualMachine:[context virtualMachine] withCodeSigning:nil andBytecodeCache:nil];
if (script)
[resolve callWithArguments:@[script]];
else
Modified: trunk/Source/_javascript_Core/ChangeLog (240193 => 240194)
--- trunk/Source/_javascript_Core/ChangeLog 2019-01-19 03:27:29 UTC (rev 240193)
+++ trunk/Source/_javascript_Core/ChangeLog 2019-01-19 03:35:44 UTC (rev 240194)
@@ -1,3 +1,21 @@
+2019-01-18 Keith Miller <keith_mil...@apple.com>
+
+ JSScript API should only take ascii files.
+ https://bugs.webkit.org/show_bug.cgi?id=193420
+
+ Reviewed by Saam Barati.
+
+ This patch leaves the UTF8 method for binary compatablity, which
+ will be removed later.
+
+ * API/JSScript.h:
+ * API/JSScript.mm:
+ (fillBufferWithContentsOfFile):
+ (+[JSScript scriptFromASCIIFile:inVirtualMachine:withCodeSigning:andBytecodeCache:]):
+ (+[JSScript scriptFromUTF8File:inVirtualMachine:withCodeSigning:andBytecodeCache:]):
+ * API/tests/testapi.mm:
+ (-[JSContextFileLoaderDelegate context:fetchModuleForIdentifier:withResolveHandler:andRejectHandler:]):
+
2019-01-18 David Kilzer <ddkil...@apple.com>
Follow-up: Gigacages should start allocations from a slide
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes