Revert "Revert "New: Support to compile deep structured project in the web browser""

This commit is contained in:
cacaodev
2022-04-01 12:17:50 +02:00
committed by GitHub
parent 3e83bd2363
commit fa2ea8f809
13 changed files with 705 additions and 374 deletions
+208 -8
View File
@@ -2,13 +2,213 @@
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CPBundleIdentifier</key>
<string>com.280n.AppKit</string>
<key>CPBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CPBundleName</key>
<string>AppKit</string>
<key>CPBundlePackageType</key>
<string>FMWK</string>
<key>CPBundleIdentifier</key>
<string>com.280n.AppKit</string>
<key>CPBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CPBundleName</key>
<string>AppKit</string>
<key>CPBundlePackageType</key>
<string>FMWK</string>
<key>CPCompileIncludeFileArray</key>
<array>
<string>Platform/Platform.h</string>
<string>Platform/DOM/CPDOMDisplayServer.h</string>
</array>
<key>CPFileTranslationDictionary</key>
<dict>
<key>_CPCibCustomObject.j</key>
<string>Cib/_CPCibCustomObject.j</string>
<key>_CPCibCustomView.j</key>
<string>Cib/_CPCibCustomView.j</string>
<key>CPCib.j</key>
<string>Cib/CPCib.j</string>
<key>_CPLocalizableString.j</key>
<string>Cib/_CPLocalizableString.j</string>
<key>CPCibConnector.j</key>
<string>Cib/CPCibConnector.j</string>
<key>CPCibHelpConnector.j</key>
<string>Cib/CPCibHelpConnector.j</string>
<key>_CPCibCustomResource.j</key>
<string>Cib/_CPCibCustomResource.j</string>
<key>_CPCibProxyObject.j</key>
<string>Cib/_CPCibProxyObject.j</string>
<key>_CPCibObjectData.j</key>
<string>Cib/_CPCibObjectData.j</string>
<key>CPCibLoading.j</key>
<string>Cib/CPCibLoading.j</string>
<key>_CPCibWindowTemplate.j</key>
<string>Cib/_CPCibWindowTemplate.j</string>
<key>CPCibRuntimeAttributesConnector.j</key>
<string>Cib/CPCibRuntimeAttributesConnector.j</string>
<key>_CPCibClassSwapper.j</key>
<string>Cib/_CPCibClassSwapper.j</string>
<key>CPCibControlConnector.j</key>
<string>Cib/CPCibControlConnector.j</string>
<key>CPCibOutletConnector.j</key>
<string>Cib/CPCibOutletConnector.j</string>
<key>_CPCibKeyedUnarchiver.j</key>
<string>Cib/_CPCibKeyedUnarchiver.j</string>
<key>CPCibBindingConnector.j</key>
<string>Cib/CPCibBindingConnector.j</string>
<key>_CPObjectAnimator.j</key>
<string>CoreAnimation/_CPObjectAnimator.j</string>
<key>CAAnimation.j</key>
<string>CoreAnimation/CAAnimation.j</string>
<key>CABackingStore.j</key>
<string>CoreAnimation/CABackingStore.j</string>
<key>CABasicAnimation.j</key>
<string>CoreAnimation/CABasicAnimation.j</string>
<key>CAFlashLayer.j</key>
<string>CoreAnimation/CAFlashLayer.j</string>
<key>CAKeyframeAnimation.j</key>
<string>CoreAnimation/CAKeyframeAnimation.j</string>
<key>CALayer.j</key>
<string>CoreAnimation/CALayer.j</string>
<key>CAMediaTimingFunction.j</key>
<string>CoreAnimation/CAMediaTimingFunction.j</string>
<key>CAPropertyAnimation.j</key>
<string>CoreAnimation/CAPropertyAnimation.j</string>
<key>CPAnimationContext.j</key>
<string>CoreAnimation/CPAnimationContext.j</string>
<key>CPViewAnimator.j</key>
<string>CoreAnimation/CPViewAnimator.j</string>
<key>CSSAnimation.j</key>
<string>CoreAnimation/CSSAnimation.j</string>
<key>CGGradient.j</key>
<string>CoreGraphics/CGGradient.j</string>
<key>CGContextText.j</key>
<string>CoreGraphics/CGContextText.j</string>
<key>CGAffineTransform.j</key>
<string>CoreGraphics/CGAffineTransform.j</string>
<key>CGColorSpace.j</key>
<string>CoreGraphics/CGColorSpace.j</string>
<key>CGContext.j</key>
<string>CoreGraphics/CGContext.j</string>
<key>CGGeometry.j</key>
<string>CoreGraphics/CGGeometry.j</string>
<key>CGContextVML.j</key>
<string>CoreGraphics/CGContextVML.j</string>
<key>CGPath.j</key>
<string>CoreGraphics/CGPath.j</string>
<key>CGContextCanvas.j</key>
<string>CoreGraphics/CGContextCanvas.j</string>
<key>CGColor.j</key>
<string>CoreGraphics/CGColor.j</string>
<key>_CPDatePickerCalendar.j</key>
<string>CPDatePicker/_CPDatePickerCalendar.j</string>
<key>_CPDatePickerTextField.j</key>
<string>CPDatePicker/_CPDatePickerTextField.j</string>
<key>_CPDatePickerClock.j</key>
<string>CPDatePicker/_CPDatePickerClock.j</string>
<key>CPDatePicker.j</key>
<string>CPDatePicker/CPDatePicker.j</string>
<key>_CPMenuWindow.j</key>
<string>CPMenu/_CPMenuWindow.j</string>
<key>CPMenu.j</key>
<string>CPMenu/CPMenu.j</string>
<key>_CPMenuManager.j</key>
<string>CPMenu/_CPMenuManager.j</string>
<key>_CPMenuBarWindow.j</key>
<string>CPMenu/_CPMenuBarWindow.j</string>
<key>CPMenuItem.j</key>
<string>CPMenuItem/CPMenuItem.j</string>
<key>_CPMenuItemView.j</key>
<string>CPMenuItem/_CPMenuItemView.j</string>
<key>_CPMenuItemStandardView.j</key>
<string>CPMenuItem/_CPMenuItemStandardView.j</string>
<key>_CPMenuItemSeparatorView.j</key>
<string>CPMenuItem/_CPMenuItemSeparatorView.j</string>
<key>_CPMenuItemMenuBarView.j</key>
<string>CPMenuItem/_CPMenuItemMenuBarView.j</string>
<key>_CPRuleEditorViewSliceRow.j</key>
<string>CPRuleEditor/_CPRuleEditorViewSliceRow.j</string>
<key>CPPredicateEditor.j</key>
<string>CPRuleEditor/CPPredicateEditor.j</string>
<key>CPRuleEditor.j</key>
<string>CPRuleEditor/CPRuleEditor.j</string>
<key>_CPRuleEditorLocalizer.j</key>
<string>CPRuleEditor/_CPRuleEditorLocalizer.j</string>
<key>CPPredicateEditorRowTemplate.j</key>
<string>CPRuleEditor/CPPredicateEditorRowTemplate.j</string>
<key>_CPRuleEditorViewSlice.j</key>
<string>CPRuleEditor/_CPRuleEditorViewSlice.j</string>
<key>CPRuleEditor_Constants.j</key>
<string>CPRuleEditor/CPRuleEditor_Constants.j</string>
<key>_CPPredicateEditorRowNode.j</key>
<string>CPRuleEditor/_CPPredicateEditorRowNode.j</string>
<key>_CPPredicateEditorTree.j</key>
<string>CPRuleEditor/_CPPredicateEditorTree.j</string>
<key>CPTextStorage.j</key>
<string>CPTextView/CPTextStorage.j</string>
<key>_CPRTFParser.j</key>
<string>CPTextView/_CPRTFParser.j</string>
<key>_CPRTFProducer.j</key>
<string>CPTextView/_CPRTFProducer.j</string>
<key>CPTextContainer.j</key>
<string>CPTextView/CPTextContainer.j</string>
<key>CPLayoutManager.j</key>
<string>CPTextView/CPLayoutManager.j</string>
<key>CPTextView.j</key>
<string>CPTextView/CPTextView.j</string>
<key>CPFontDescriptor.j</key>
<string>CPTextView/CPFontDescriptor.j</string>
<key>CPFontPanel.j</key>
<string>CPTextView/CPFontPanel.j</string>
<key>CPParagraphStyle.j</key>
<string>CPTextView/CPParagraphStyle.j</string>
<key>CPTypesetter.j</key>
<string>CPTextView/CPTypesetter.j</string>
<key>CPWindow_Constants.j</key>
<string>CPWindow/CPWindow_Constants.j</string>
<key>_CPStandardWindowView.j</key>
<string>CPWindow/_CPStandardWindowView.j</string>
<key>_CPShadowWindowView.j</key>
<string>CPWindow/_CPShadowWindowView.j</string>
<key>_CPToolTipWindowView.j</key>
<string>CPWindow/_CPToolTipWindowView.j</string>
<key>_CPBorderlessWindowView.j</key>
<string>CPWindow/_CPBorderlessWindowView.j</string>
<key>_CPBorderlessBridgeWindowView.j</key>
<string>CPWindow/_CPBorderlessBridgeWindowView.j</string>
<key>_CPDocModalWindowView.j</key>
<string>CPWindow/_CPDocModalWindowView.j</string>
<key>_CPModalWindowView.j</key>
<string>CPWindow/_CPModalWindowView.j</string>
<key>_CPPopoverWindowView.j</key>
<string>CPWindow/_CPPopoverWindowView.j</string>
<key>_CPWindowView.j</key>
<string>CPWindow/_CPWindowView.j</string>
<key>_CPTitleableWindowView.j</key>
<string>CPWindow/_CPTitleableWindowView.j</string>
<key>CPWindow.j</key>
<string>CPWindow/CPWindow.j</string>
<key>_CPHUDWindowView.j</key>
<string>CPWindow/_CPHUDWindowView.j</string>
<key>CPPlatform.j</key>
<string>Platform/CPPlatform.j</string>
<key>CPPlatformString.j</key>
<string>Platform/CPPlatformString.j</string>
<key>CPPlatformWindow.j</key>
<string>Platform/CPPlatformWindow.j</string>
<key>CPPlatformWindow+DOM.j</key>
<string>Platform/DOM/CPPlatformWindow+DOM.j</string>
<key>CPPlatformPasteboard.j</key>
<string>Platform/DOM/CPPlatformPasteboard.j</string>
<key>CPDOMWindowLayer.j</key>
<string>Platform/DOM/CPDOMWindowLayer.j</string>
<key>CPPlatformWindow+DOMKeys.j</key>
<string>Platform/DOM/CPPlatformWindow+DOMKeys.j</string>
</dict>
</dict>
</plist>
+1 -1
View File
@@ -233,7 +233,7 @@ ObjectiveJFlattener.prototype.serializeFunctions = function() {
var functionString = executable._function.toString().replace(", require, exports, module, system, print, window", ""); // HACK
var relative = this.rootPath.relative(path).toString();
this.functionsBuffer.push("ObjectiveJ.FileExecutable._cacheFunction(new CFURL("+JSON.stringify(relative)+", baseURL),\n"+functionString+");");
this.functionsBuffer.push("ObjectiveJ.StaticResource._cacheFunction(new CFURL("+JSON.stringify(relative)+", baseURL),\n"+functionString+");");
}
var bundle = this.context.global.CFBundle.bundleContainingURL(path);
+57
View File
@@ -10,5 +10,62 @@
<string>Foundation</string>
<key>CPBundlePackageType</key>
<string>FMWK</string>
<key>CPFileTranslationDictionary</key>
<dict>
<key>_CPAggregateExpression.j</key>
<string>CPPredicate/_CPAggregateExpression.j</string>
<key>_CPSelfExpression.j</key>
<string>CPPredicate/_CPSelfExpression.j</string>
<key>_CPSubqueryExpression.j</key>
<string>CPPredicate/_CPSubqueryExpression.j</string>
<key>_CPConstantValueExpression.j</key>
<string>CPPredicate/_CPConstantValueExpression.j</string>
<key>CPCompoundPredicate_Constants.j</key>
<string>CPPredicate/CPCompoundPredicate_Constants.j</string>
<key>_CPSetExpression.j</key>
<string>CPPredicate/_CPSetExpression.j</string>
<key>CPCompoundPredicate.j</key>
<string>CPPredicate/CPCompoundPredicate.j</string>
<key>_CPKeyPathExpression.j</key>
<string>CPPredicate/_CPKeyPathExpression.j</string>
<key>CPComparisonPredicate.j</key>
<string>CPPredicate/CPComparisonPredicate.j</string>
<key>_CPPredicate.j</key>
<string>CPPredicate/_CPPredicate.j</string>
<key>_CPFunctionExpression.j</key>
<string>CPPredicate/_CPFunctionExpression.j</string>
<key>_CPExpression.j</key>
<string>CPPredicate/_CPExpression.j</string>
<key>CPExpression.j</key>
<string>CPPredicate/CPExpression.j</string>
<key>_CPBlockExpression.j</key>
<string>CPPredicate/_CPBlockExpression.j</string>
<key>_CPConditionalExpression.j</key>
<string>CPPredicate/_CPConditionalExpression.j</string>
<key>CPComparisonPredicate_Constants.j</key>
<string>CPPredicate/CPComparisonPredicate_Constants.j</string>
<key>CPPredicate.j</key>
<string>CPPredicate/CPPredicate.j</string>
<key>_CPVariableExpression.j</key>
<string>CPPredicate/_CPVariableExpression.j</string>
<key>_CPConcreteMutableSet.j</key>
<string>CPSet/_CPConcreteMutableSet.j</string>
<key>_CPSet.j</key>
<string>CPSet/_CPSet.j</string>
<key>CPSet.j</key>
<string>CPSet/CPSet.j</string>
<key>CPMutableSet.j</key>
<string>CPSet/CPMutableSet.j</string>
<key>_CPArray.j</key>
<string>CPArray/_CPArray.j</string>
<key>_CPJavaScriptArray.j</key>
<string>CPArray/_CPJavaScriptArray.j</string>
<key>CPArray.j</key>
<string>CPArray/CPArray.j</string>
<key>CPMutableArray.j</key>
<string>CPArray/CPMutableArray.j</string>
</dict>
</dict>
</plist>
+16 -2
View File
@@ -52,7 +52,9 @@ if (typeof OBJJ_COMPILER_FLAGS !== 'undefined')
var flags = {};
for (var i = 0; i < OBJJ_COMPILER_FLAGS.length; i++)
{
switch (OBJJ_COMPILER_FLAGS[i])
var aFlag = OBJJ_COMPILER_FLAGS[i];
switch (aFlag)
{
case "IncludeDebugSymbols":
flags.includeMethodFunctionNames = true;
@@ -70,9 +72,21 @@ if (typeof OBJJ_COMPILER_FLAGS !== 'undefined')
case "SourceMap":
flags.sourceMap = true;
break;
case "SourceMapIncludeSource":
flags.sourceMapIncludeSource = true;
break;
default:
if (aFlag.indexOf("-D") === 0) {
var macroDefinition = aFlag.substring(2);
(flags.macros || (flags.macros = [])).push(macroDefinition);
}
break;
}
}
FileExecutable.setCurrentCompilerFlags(flags);
StaticResource.setCurrentCompilerFlags(flags);
}
// Turn the main file into a URL.
+4
View File
@@ -828,7 +828,11 @@ function decompileStaticFile(/*Bundle*/ aBundle, /*String*/ aString, /*String*/
}
else if (marker === MARKER_TEXT)
{
file.write(text);
if (text.match(/^@STATIC;/))
file.decompile();
}
}
}
+19
View File
@@ -152,6 +152,25 @@ CFDictionary.prototype.toString = function()
DISPLAY_NAME(CFDictionary.prototype.toString);
CFDictionary.prototype.toJSObject = function()
{
var jsObject = new Object(),
keys = this._keys,
index = 0,
count = this._count;
for (; index < count; ++index)
{
var key = keys[index];
jsObject[key] = this.valueForKey(key);
}
return jsObject;
};
DISPLAY_NAME(CFDictionary.prototype.toJSObject);
GLOBAL(CFMutableDictionary) = function(/*CFDictionary*/ aDictionary)
{
CFDictionary.apply(this, []);
+12 -12
View File
@@ -129,51 +129,51 @@ exports.run = function(args)
case "-g":
case "--include-debug-symbols":
argv.shift();
var flags = ObjectiveJ.FileExecutable.currentCompilerFlags();
var flags = ObjectiveJ.StaticResource.currentCompilerFlags();
flags.includeMethodFunctionNames = true;
ObjectiveJ.FileExecutable.setCurrentCompilerFlags(flags);
ObjectiveJ.StaticResource.setCurrentCompilerFlags(flags);
break;
case "-T":
case "--dont-include-type-signatures":
argv.shift();
var flags = ObjectiveJ.FileExecutable.currentCompilerFlags();
var flags = ObjectiveJ.StaticResource.currentCompilerFlags();
flags.includeIvarTypeSignatures = true;
flags.includeMethodArgumentTypeSignatures = true;
ObjectiveJ.FileExecutable.setCurrentCompilerFlags(flags);
ObjectiveJ.StaticResource.setCurrentCompilerFlags(flags);
break;
case "-O2":
case "--inline-msg-send":
argv.shift();
var flags = ObjectiveJ.FileExecutable.currentCompilerFlags();
var flags = ObjectiveJ.StaticResource.currentCompilerFlags();
flags.inlineMsgSendFunctions = true;
ObjectiveJ.FileExecutable.setCurrentCompilerFlags(flags);
ObjectiveJ.StaticResource.setCurrentCompilerFlags(flags);
break;
case "-g":
case "--include-debug-symbols":
argv.shift();
var flags = ObjectiveJ.FileExecutable.currentCompilerFlags();
var flags = ObjectiveJ.StaticResource.currentCompilerFlags();
flags.includeMethodFunctionNames = true;
ObjectiveJ.FileExecutable.setCurrentCompilerFlags(flags);
ObjectiveJ.StaticResource.setCurrentCompilerFlags(flags);
break;
case "-T":
case "--dont-include-type-signatures":
argv.shift();
var flags = ObjectiveJ.FileExecutable.currentCompilerFlags();
var flags = ObjectiveJ.StaticResource.currentCompilerFlags();
flags.includeIvarTypeSignatures = true;
flags.includeMethodArgumentTypeSignatures = true;
ObjectiveJ.FileExecutable.setCurrentCompilerFlags(flags);
ObjectiveJ.StaticResource.setCurrentCompilerFlags(flags);
break;
case "-O2":
case "--inline-msg-send":
argv.shift();
var flags = ObjectiveJ.FileExecutable.currentCompilerFlags();
var flags = ObjectiveJ.StaticResource.currentCompilerFlags();
flags.inlineMsgSendFunctions = true;
ObjectiveJ.FileExecutable.setCurrentCompilerFlags(flags);
ObjectiveJ.StaticResource.setCurrentCompilerFlags(flags);
break;
default:
@@ -113,7 +113,7 @@ function compileWithResolvedFlags(aFilePath, objjcFlags, gccFlags, asPlainJavasc
}
}
ObjectiveJ.FileExecutable.setCurrentCompilerFlags(objjcFlags);
ObjectiveJ.StaticResource.setCurrentCompilerFlags(objjcFlags);
ObjectiveJ.make_narwhal_factory(absolutePath, basePath, translateFilenameToPath)(require, {}, module, system, print);
executable = new ObjectiveJ.FileExecutable(FILE.basename(aFilePath));
@@ -907,7 +907,7 @@ BundleTask.prototype.defineSourceTasks = function()
basePath = absolutePath.substring(0, absolutePath.length - theTranslatedFilename.length);
// Here we set the current compiler flags so the load system will know what compiler flags to use
ObjectiveJ.FileExecutable.setCurrentGccCompilerFlags(environmentCompilerFlags);
ObjectiveJ.StaticResource.setCurrentGccCompilerFlags(environmentCompilerFlags);
// Here we tell the CFBundle to load frameworks for the current build enviroment and not the enviroment that is running
CFBundle.environments = function() {return [anEnvironment.name(), "ObjJ"]};
ObjectiveJ.make_narwhal_factory(absolutePath, basePath, translateFilenameToPath)(require, e, module, system, print);
+61 -36
View File
@@ -24,8 +24,7 @@
var ExecutableUnloadedFileDependencies = 0,
ExecutableLoadingFileDependencies = 1,
ExecutableLoadedFileDependencies = 2,
ExecutableCantStartLoadYetFileDependencies = 3,
AnonymousExecutableCount = 0;
AnonymousExecutableCount = 0;
function Executable(/*String*/ aCode, /*Array*/ fileDependencies, /*CFURL|String*/ aURL, /*Function*/ aFunction, /*ObjJCompiler*/aCompiler, /*Dictionary*/ aFilenameTranslateDictionary, /* Base64 String */ sourceMap)
{
@@ -44,13 +43,7 @@ function Executable(/*String*/ aCode, /*Array*/ fileDependencies, /*CFURL|String
if (sourceMap)
this._base64EncodedSourceMap = sourceMap;
// This is a little hacky but if fileDependencies is null we can start loading file dependencies yet
if (!fileDependencies)
{
this._fileDependencyStatus = ExecutableCantStartLoadYetFileDependencies;
this._fileDependencyCallbacks = [];
}
else if (fileDependencies.length)
if (fileDependencies.length)
{
this._fileDependencyStatus = ExecutableUnloadedFileDependencies;
this._fileDependencyCallbacks = [];
@@ -188,9 +181,10 @@ Executable.prototype.execute = function()
this.setCode(this._compiler.compilePass2(), this._compiler.map());
if (FileExecutable.printWarningsAndErrors(this._compiler, exports.messageOutputFormatInXML))
if (Executable.printWarningsAndErrors(this._compiler, exports.messageOutputFormatInXML))
throw "Compilation error";
// We don't need to save the AST tree and the source code. It will take up a lot of memory.
this._compiler = null;
}
@@ -314,8 +308,9 @@ Executable.prototype.loadFileDependencies = function(aCallback)
if (status === ExecutableUnloadedFileDependencies)
{
if (fileDependencyLoadCount)
throw "Can't load";
if (fileDependencyLoadCount) {
throw "Can't load: " + this.URL().absoluteURL();
}
loadFileDependenciesForExecutable(this);
}
@@ -323,20 +318,12 @@ Executable.prototype.loadFileDependencies = function(aCallback)
DISPLAY_NAME(Executable.prototype.loadFileDependencies);
Executable.prototype.setExecutableUnloadedFileDependencies = function()
Executable.prototype.hasExecutableUnloadedFileDependencies = function()
{
if (this._fileDependencyStatus === ExecutableCantStartLoadYetFileDependencies)
this._fileDependencyStatus = ExecutableUnloadedFileDependencies;
return this._fileDependencyStatus === ExecutableUnloadedFileDependencies;
}
DISPLAY_NAME(Executable.prototype.setExecutableUnloadedFileDependencies);
Executable.prototype.isExecutableCantStartLoadYetFileDependencies = function()
{
return this._fileDependencyStatus === ExecutableCantStartLoadYetFileDependencies;
}
DISPLAY_NAME(Executable.prototype.setExecutableUnloadedFileDependencies);
DISPLAY_NAME(Executable.prototype.hasExecutableUnloadedFileDependencies);
function loadFileDependenciesForExecutable(/*Executable*/ anExecutable)
{
@@ -442,6 +429,7 @@ DISPLAY_NAME(Executable.prototype.fileExecutableSearcher);
var cachedFileExecuters = { };
// All the file dependences must be loaded and executed before this can be executed.
Executable.fileExecuterForURL = function(/*CFURL|String*/ aURL)
{
var referenceURL = makeAbsoluteURL(aURL),
@@ -490,13 +478,13 @@ Executable.fileImporterForURL = function(/*CFURL|String*/ aURL)
{
aFileExecutable.loadFileDependencies(function()
{
aFileExecutable.execute();
var result = aFileExecutable.execute();
// No more need to cache these.
disableCFURLCaching();
if (aCallback)
aCallback();
aCallback(result);
});
});
}
@@ -512,16 +500,6 @@ DISPLAY_NAME(Executable.fileImporterForURL);
var cachedFileExecutableSearchers = { },
cachedFileExecutableSearchResults = { };
function countProp(x) {
var count = 0;
for (var k in x) {
if (x.hasOwnProperty(k)) {
++count;
}
}
return count;
}
Executable.resetCachedFileExecutableSearchers = function()
{
cachedFileExecutableSearchers = { };
@@ -583,6 +561,53 @@ Executable.fileExecutableSearcherForURL = function(/*CFURL*/ referenceURL)
DISPLAY_NAME(Executable.fileExecutableSearcherForURL);
/*!
This funtion prints all errors and warnings for the provided compiler. It returns true if there
are any errors in the list. it will print it in xml format if printXML is 'true'
*/
Executable.printWarningsAndErrors = function(/*ObjJCompiler*/ compiler, /*BOOL*/ printXML)
{
var warnings = [],
anyErrors = false;
for (var i = 0; i < compiler.warningsAndErrors.length; i++)
{
var warning = compiler.warningsAndErrors[i],
message = compiler.prettifyMessage(warning);
// Set anyErrors to 'true' if there are any errors in the list
anyErrors = anyErrors || warning.messageType === "ERROR";
#ifdef BROWSER
console.log(message);
#else
if (printXML)
{
var dict = new CFMutableDictionary();
if (warning.messageOnLine != null) dict.addValueForKey('line', warning.messageOnLine)
if (warning.path != null) dict.addValueForKey('sourcePath', new CFURL(warning.path).path())
if (message != null) dict.addValueForKey('message', message)
warnings.push(dict);
}
else
{
print(message);
}
#endif
}
#ifndef BROWSER
if (warnings.length && printXML)
try {
print(CFPropertyListCreateXMLData(warnings, kCFPropertyListXMLFormat_v1_0).rawString());
} catch (e) {
print ("XML encode error: " + e);
}
#endif
return anyErrors;
}
/*
* Adaption to javascript by Malte Tancred 2012 from ConvertUTF.[ch] by Unicode, Inc.
* Speed improvements by Martin Carlberg 2016
+7 -294
View File
@@ -22,10 +22,7 @@
var FileExecutablesForURLStrings = { };
var currentCompilerFlags = {};
var currentGccCompilerFlags = "";
function FileExecutable(/*CFURL|String*/ aURL, /*Dictionary*/ aFilenameTranslateDictionary)
function FileExecutable(/*CFURL|String*/ aURL, /*Dictionary*/ aFilenameTranslateDictionary, success)
{
aURL = makeAbsoluteURL(aURL);
@@ -37,25 +34,14 @@ function FileExecutable(/*CFURL|String*/ aURL, /*Dictionary*/ aFilenameTranslate
FileExecutablesForURLStrings[URLString] = this;
var fileContents = StaticResource.resourceAtURL(aURL).contents(),
executable = NULL,
extension = aURL.pathExtension().toLowerCase();
var aResource = StaticResource.resourceAtURL(aURL),
fileContents = aResource.contents(),
executable = NULL;
this._hasExecuted = NO;
if (fileContents.match(/^@STATIC;/))
executable = decompile(fileContents, aURL);
else if ((extension === "j" || !extension) && !fileContents.match(/^{/))
{
var compilerOptions = currentCompilerFlags || {};
this.cachedIncludeFileSearchResultsContent = {};
this.cachedIncludeFileSearchResultsURL = {};
compile(this, fileContents, aURL, compilerOptions, aFilenameTranslateDictionary);
return;
}
else
executable = new Executable(fileContents, [], aURL);
// Use code if resource contains code. If not use the content of the resource
executable = new Executable(fileContents, aResource._fileDependencies || [], aURL, aResource._function, aResource._compiler, aResource._compiler ? aFilenameTranslateDictionary : null, aResource._sourceMap);
Executable.apply(this, [executable.code(), executable.fileDependencies(), aURL, executable._function, executable._compiler, aFilenameTranslateDictionary]);
}
@@ -64,143 +50,6 @@ exports.FileExecutable = FileExecutable;
FileExecutable.prototype = new Executable();
var compile = function(self, fileContents, aURL, compilerOptions, aFilenameTranslateDictionary)
{
var acornOptions = compilerOptions.acornOptions || (compilerOptions.acornOptions = {});
acornOptions.preprocessGetIncludeFile = function(filePath, isQuoted) {
var referenceURL = new CFURL(".", aURL), // Remove the filename from the url
includeURL = new CFURL(filePath);
var cacheUID = (isQuoted && referenceURL || "") + includeURL,
cachedResult = self.cachedIncludeFileSearchResultsContent[cacheUID];
if (!cachedResult) {
var isAbsoluteURL = (includeURL instanceof CFURL) && includeURL.scheme(),
compileWhenCompleted = NO;
function completed(/*StaticResource*/ aStaticResource) {
var includeString = aStaticResource && aStaticResource.contents(),
lastCharacter = includeString && includeString.charCodeAt(includeString.length - 1);
if (includeString == null) throw new Error("Can't load file " + includeURL);
// Add a new line if the last character is not. If the last thing is a '#define' of other preprocess
// token it will not be handled correctly if we don't have a end of line at the end.
if (lastCharacter !== 10 && lastCharacter !== 13 && lastCharacter !== 8232 && lastCharacter !== 8233) {
includeString += '\n';
}
self.cachedIncludeFileSearchResultsContent[cacheUID] = includeString;
self.cachedIncludeFileSearchResultsURL[cacheUID] = aStaticResource.URL();
if (compileWhenCompleted)
compile(self, fileContents, aURL, compilerOptions, aFilenameTranslateDictionary);
}
if (isQuoted || isAbsoluteURL)
{
if (!isAbsoluteURL)
includeURL = new CFURL(includeURL, new CFURL((aFilenameTranslateDictionary[aURL.lastPathComponent()] || "."), referenceURL));
StaticResource.resolveResourceAtURL(includeURL, NO, completed);
}
else
StaticResource.resolveResourceAtURLSearchingIncludeURLs(includeURL, completed);
// Now we try to get the cached result again. If we get it then the completed function has already
// executed and we can return the include dictionary.
cachedResult = self.cachedIncludeFileSearchResultsContent[cacheUID];
}
if (cachedResult) {
return {include: cachedResult, sourceFile: self.cachedIncludeFileSearchResultsURL[cacheUID]};
} else {
// When the file is not available (resolved) return null to tell the parser to throw an exception to exit
// Also tell the completed function to compile when finished.
compileWhenCompleted = YES
return null;
}
};
var includeFiles = currentCompilerFlags && currentCompilerFlags.includeFiles,
allPreIncludesResolved = true;
acornOptions.preIncludeFiles = [];
if (includeFiles) for (var i = 0, size = includeFiles.length; i < size; i++)
{
var includeFileUrl = makeAbsoluteURL(includeFiles[i]);
try
{
// try to get all pre include files that acorn will parse before the file from 'aURL'
var aResource = StaticResource.resourceAtURL(makeAbsoluteURL(includeFileUrl));
}
catch (e)
{
// Ok, the file is not available (resolved). Resolve all of the files and try again when available.
StaticResource.resolveResourcesAtURLs(includeFiles.map(function(u) {return makeAbsoluteURL(u)}), function() {
compile(self, fileContents, aURL, compilerOptions, aFilenameTranslateDictionary);
});
allPreIncludesResolved = false;
break;
}
if (aResource)
{
if (aResource.isNotFound()) {
throw new Error("--include file not found " + includeUrl);
}
var includeString = aResource.contents();
var lastCharacter = includeString.charCodeAt(includeString.length - 1);
// Add a new line if the last character is not. If the last thing is a '#define' of other preprocess
// token it will not be handled correctly if we don't have a end of line at the end.
if (lastCharacter !== 10 && lastCharacter !== 13 && lastCharacter !== 8232 && lastCharacter !== 8233)
includeString += '\n';
acornOptions.preIncludeFiles.push({include: includeString, sourceFile: includeFileUrl.toString()});
}
}
if (allPreIncludesResolved)
{
// '(exports.ObjJCompiler || ObjJCompiler)' is a temporary fix so it can work both in the Narwhal (exports.ObjJCompiler) and Node (ObjJCompiler) world
var compiler = (exports.ObjJCompiler || ObjJCompiler).compileFileDependencies(fileContents, aURL, compilerOptions);
var warningsAndErrors = compiler.warningsAndErrors;
// Kind of a hack but if we get a file not found error on a #include the get include function above should have asked for the resource
// so we should be able to just bail out and wait for the the next call to compile when the include file is loaded (resolved)
if (warningsAndErrors && warningsAndErrors.length === 1 && warningsAndErrors[0].message.indexOf("file not found") > -1)
return;
if (FileExecutable.printWarningsAndErrors(compiler, exports.messageOutputFormatInXML))
throw "Compilation error";
var fileDependencies = compiler.dependencies.map(function (aFileDep) {
return new FileDependency(new CFURL(aFileDep.url), aFileDep.isLocal);
});
}
if (self.isExecutableCantStartLoadYetFileDependencies())
{
// Include files that was not loaded has cancelled the compiler so we are already an initialized Executable.
// Just set the status so we can start loading the file dependencies.
self.setFileDependencies(fileDependencies);
self.setExecutableUnloadedFileDependencies();
self.loadFileDependencies();
}
else if (self._fileDependencyStatus == null)
{
// Are we still a FileExecutable. Call 'super' init method to make us a initilized subclass of an Executable.
executable = new Executable(compiler && compiler.jsBuffer ? compiler.jsBuffer.toString() : null, fileDependencies, aURL, null, compiler);
Executable.apply(self, [executable.code(), executable.fileDependencies(), aURL, executable._function, executable._compiler, aFilenameTranslateDictionary]);
}
}
DISPLAY_NAME(compile);
#ifdef COMMONJS
FileExecutable.allFileExecutables = function()
{
@@ -218,7 +67,6 @@ FileExecutable.allFileExecutables = function()
FileExecutable.resetFileExecutables = function()
{
FileExecutablesForURLStrings = { };
FunctionCache = { };
}
FileExecutable.prototype.execute = function(/*BOOL*/ shouldForce)
@@ -228,7 +76,7 @@ FileExecutable.prototype.execute = function(/*BOOL*/ shouldForce)
this._hasExecuted = YES;
Executable.prototype.execute.call(this);
return Executable.prototype.execute.call(this);
}
DISPLAY_NAME(FileExecutable.prototype.execute);
@@ -240,138 +88,3 @@ FileExecutable.prototype.hasExecuted = function()
DISPLAY_NAME(FileExecutable.prototype.hasExecuted);
function decompile(/*String*/ aString, /*CFURL*/ aURL)
{
var stream = new MarkedStream(aString);
/*
if (stream.version !== "1.0")
return;
*/
var marker = NULL,
code = "",
dependencies = [],
sourceMap;
while (marker = stream.getMarker())
{
var text = stream.getString();
if (marker === MARKER_TEXT)
code += text;
else if (marker === MARKER_IMPORT_STD)
dependencies.push(new FileDependency(new CFURL(text), NO));
else if (marker === MARKER_IMPORT_LOCAL)
dependencies.push(new FileDependency(new CFURL(text), YES));
else if (marker === MARKER_SOURCE_MAP)
sourceMap = text;
}
var fn = FileExecutable._lookupCachedFunction(aURL);
if (fn)
return new Executable(code, dependencies, aURL, fn, null, null, sourceMap);
return new Executable(code, dependencies, aURL, null, null, null, sourceMap);
}
var FunctionCache = { };
FileExecutable._cacheFunction = function(/*CFURL|String*/ aURL, /*Function*/ fn)
{
aURL = typeof aURL === "string" ? aURL : aURL.absoluteString();
FunctionCache[aURL] = fn;
}
FileExecutable._lookupCachedFunction = function(/*CFURL|String*/ aURL)
{
aURL = typeof aURL === "string" ? aURL : aURL.absoluteString();
return FunctionCache[aURL];
}
FileExecutable.setCurrentGccCompilerFlags = function(/*String*/ compilerFlags)
{
if (currentGccCompilerFlags === compilerFlags) return;
currentGccCompilerFlags = compilerFlags;
// '(exports.ObjJCompiler || ObjJCompiler)' is a temporary fix so it can work both in the Narwhal (exports.ObjJCompiler) and Node (ObjJCompiler) world
var objjcFlags = (exports.ObjJCompiler || ObjJCompiler).parseGccCompilerFlags(compilerFlags);
FileExecutable.setCurrentCompilerFlags(objjcFlags);
}
FileExecutable.currentGccCompilerFlags = function(/*String*/ compilerFlags)
{
return currentGccCompilerFlags;
}
FileExecutable.setCurrentCompilerFlags = function(/*JSObject*/ compilerFlags)
{
currentCompilerFlags = compilerFlags;
// Here we set the default flags if they are not included. We do this as the default values
// in the compiler might not be what we want.
if (currentCompilerFlags.transformNamedFunctionDeclarationToAssignment == null)
currentCompilerFlags.transformNamedFunctionDeclarationToAssignment = true;
if (currentCompilerFlags.sourceMap == null)
currentCompilerFlags.sourceMap = false;
if (currentCompilerFlags.inlineMsgSendFunctions == null)
currentCompilerFlags.inlineMsgSendFunctions = false;
}
FileExecutable.currentCompilerFlags = function(/*JSObject*/ compilerFlags)
{
return currentCompilerFlags;
}
/*!
This funtion prints all errors and warnings for the provieded compiler. It returns true if there
are any errors in the list. it will print it in xml format if printXML is 'true'
*/
FileExecutable.printWarningsAndErrors = function(/*ObjJCompiler*/ compiler, /*BOOL*/ printXML)
{
var warnings = [],
anyErrors = false;
for (var i = 0; i < compiler.warningsAndErrors.length; i++)
{
var warning = compiler.warningsAndErrors[i],
message = compiler.prettifyMessage(warning);
// Set anyErrors to 'true' if there are any errors in the list
anyErrors = anyErrors || warning.messageType === "ERROR";
#ifdef BROWSER
console.log(message);
#else
if (printXML)
{
var dict = new CFMutableDictionary();
if (warning.messageOnLine != null) dict.addValueForKey('line', warning.messageOnLine)
if (warning.path != null) dict.addValueForKey('sourcePath', new CFURL(warning.path).path())
if (message != null) dict.addValueForKey('message', message)
warnings.push(dict);
}
else
{
print(message);
}
#endif
}
#ifndef BROWSER
if (warnings.length && printXML)
try {
print(CFPropertyListCreateXMLData(warnings, kCFPropertyListXMLFormat_v1_0).rawString());
} catch (e) {
print ("XML encode error: " + e);
}
#endif
return anyErrors;
}
// Set the compiler flags to empty dictionary so the default values are correct.
FileExecutable.setCurrentCompilerFlags({});
+31
View File
@@ -280,3 +280,34 @@ if (!Array.prototype.find) {
writable: true
});
}
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/assign
if (typeof Object.assign !== 'function') {
// Must be writable: true, enumerable: false, configurable: true
Object.defineProperty(Object, "assign", {
value: function assign(target, varArgs) { // .length of function is 2
'use strict';
if (target === null || target === undefined) {
throw new TypeError('Cannot convert undefined or null to object');
}
var to = Object(target);
for (var index = 1; index < arguments.length; index++) {
var nextSource = arguments[index];
if (nextSource !== null && nextSource !== undefined) {
for (var nextKey in nextSource) {
// Avoid bugs when hasOwnProperty is shadowed
if (Object.prototype.hasOwnProperty.call(nextSource, nextKey)) {
to[nextKey] = nextSource[nextKey];
}
}
}
}
return to;
},
writable: true,
configurable: true
});
}
+287 -19
View File
@@ -1,6 +1,9 @@
var rootResources = { };
var currentCompilerFlags = {};
var currentGccCompilerFlags = "";
function StaticResource(/*CFURL*/ aURL, /*StaticResource*/ aParent, /*BOOL*/ isDirectory, /*BOOL*/ isResolved, /*Dictionary*/ aFilenameTranslateDictionary)
{
this._parent = aParent;
@@ -37,19 +40,10 @@ StaticResource.rootResources = function()
return rootResources;
};
function countProp(x) {
var count = 0;
for (var k in x) {
if (x.hasOwnProperty(k)) {
++count;
}
}
return count;
}
StaticResource.resetRootResources = function()
{
rootResources = {};
FunctionCache = {};
};
StaticResource.prototype.filenameTranslateDictionary = function()
@@ -69,7 +63,7 @@ function resolveStaticResource(/*StaticResource*/ aResource)
});
}
StaticResource.prototype.resolve = function()
StaticResource.prototype.resolve = function(/*BOOL*/ dontCompile, /*Array*/ compileIncludeFileArray)
{
if (this.isDirectory())
{
@@ -87,8 +81,41 @@ StaticResource.prototype.resolve = function()
function onsuccess(/*anEvent*/ anEvent)
{
self._contents = anEvent.request.responseText();
resolveStaticResource(self);
var fileContents = anEvent.request.responseText(),
aURL = self.URL(),
extension = aURL.pathExtension().toLowerCase();
self._contents = fileContents;
if (fileContents.match(/^@STATIC;/))
{
self.decompile();
resolveStaticResource(self);
}
else if (!dontCompile && (extension === "j" || !extension) && !fileContents.match(/^{/))
{
// Copy compiler options as this can be recursive and/or asynchronous.
// Specially acornOptions.preprocessGetIncludeFile that has a variable 'self' that needs to be referencing the resource.
var compilerOptions = Object.assign({}, currentCompilerFlags || {}),
acornOptions = compilerOptions.acornOptions;
if (acornOptions)
compilerOptions.acornOptions = Object.asign({}, acornOptions);
// If no include files are set use the include files from the bundle, if any.
if (!compilerOptions.includeFiles)
compilerOptions.includeFiles = compileIncludeFileArray;
self.cachedIncludeFileSearchResultsContent = {};
self.cachedIncludeFileSearchResultsURL = {};
compile(self, fileContents, aURL, compilerOptions, aFilenameTranslateDictionary, function(aResource) {
resolveStaticResource(aResource);
});
}
else
{
resolveStaticResource(self);
}
}
function onfailure()
@@ -114,6 +141,221 @@ StaticResource.prototype.resolve = function()
}
};
var compile = function(self, fileContents, aURL, compilerOptions, aFilenameTranslateDictionary, success)
{
var acornOptions = compilerOptions.acornOptions || (compilerOptions.acornOptions = {});
acornOptions.preprocessGetIncludeFile = function(filePath, isQuoted) {
var referenceURL = new CFURL(".", aURL), // Remove the filename from the url
includeURL = new CFURL(filePath);
var cacheUID = (isQuoted && referenceURL || "") + includeURL,
cachedResult = self.cachedIncludeFileSearchResultsContent[cacheUID];
if (!cachedResult) {
var isAbsoluteURL = (includeURL instanceof CFURL) && includeURL.scheme(),
compileWhenCompleted = NO;
function completed(/*StaticResource*/ aStaticResource) {
var includeString = aStaticResource && aStaticResource.contents(),
lastCharacter = includeString && includeString.charCodeAt(includeString.length - 1);
if (includeString == null) throw new Error("Can't load file " + includeURL);
// Add a new line if the last character is not. If the last thing is a '#define' of other preprocess
// token it will not be handled correctly if we don't have a end of line at the end.
if (lastCharacter !== 10 && lastCharacter !== 13 && lastCharacter !== 8232 && lastCharacter !== 8233) {
includeString += '\n';
}
self.cachedIncludeFileSearchResultsContent[cacheUID] = includeString;
self.cachedIncludeFileSearchResultsURL[cacheUID] = aStaticResource.URL();
if (compileWhenCompleted)
compile(self, fileContents, aURL, compilerOptions, aFilenameTranslateDictionary, success);
}
if (isQuoted || isAbsoluteURL)
{
var translateDictionary;
if (!isAbsoluteURL) {
includeURL = new CFURL(includeURL, new CFURL(((aFilenameTranslateDictionary && aFilenameTranslateDictionary[aURL.lastPathComponent()]) || "."), referenceURL));
}
StaticResource.resolveResourceAtURL(includeURL, NO, completed, null, true); // true = don't compile any loaded resource
}
else
StaticResource.resolveResourceAtURLSearchingIncludeURLs(includeURL, completed);
// Now we try to get the cached result again. If we get it then the completed function has already
// executed and we can return the include dictionary.
cachedResult = self.cachedIncludeFileSearchResultsContent[cacheUID];
}
if (cachedResult) {
return {include: cachedResult, sourceFile: self.cachedIncludeFileSearchResultsURL[cacheUID]};
} else {
// When the file is not available (resolved) return null to tell the parser to throw an exception to exit
// Also tell the completed function to compile when finished as it has not yet done so.
// If fetching the resources are synchronous the result will be found above and the completion function
// should not compile again.
compileWhenCompleted = YES;
return null;
}
};
var includeFiles = compilerOptions && compilerOptions.includeFiles,
allPreIncludesResolved = true;
acornOptions.preIncludeFiles = [];
if (includeFiles) for (var i = 0, size = includeFiles.length; i < size; i++)
{
var includeFileUrl = makeAbsoluteURL(includeFiles[i]);
try
{
// try to get all pre include files that acorn will parse before the file from 'aURL'
var aResource = StaticResource.resourceAtURL(makeAbsoluteURL(includeFileUrl));
}
catch (e)
{
// Ok, the file is not available (resolved). Resolve all of the files and try again when available.
StaticResource.resolveResourcesAtURLs(includeFiles.map(function(u) {return makeAbsoluteURL(u)}), function() {
compile(self, fileContents, aURL, compilerOptions, aFilenameTranslateDictionary, success);
});
// Now we need to bail out as the compile completion function has already been
// called (synchronous) or will be called in the future (asynchronous)
return;
}
if (aResource)
{
if (aResource.isNotFound()) {
throw new Error("--include file not found " + includeUrl);
}
var includeString = aResource.contents();
var lastCharacter = includeString.charCodeAt(includeString.length - 1);
// Add a new line if the last character is not. If the last thing is a '#define' of other preprocess
// token it will not be handled correctly if we don't have a end of line at the end.
if (lastCharacter !== 10 && lastCharacter !== 13 && lastCharacter !== 8232 && lastCharacter !== 8233)
includeString += '\n';
acornOptions.preIncludeFiles.push({include: includeString, sourceFile: includeFileUrl.toString()});
}
}
// '(exports.ObjJCompiler || ObjJCompiler)' is a temporary fix so it can work both in the Narwhal (exports.ObjJCompiler) and Node (ObjJCompiler) world
var compiler = (exports.ObjJCompiler || ObjJCompiler).compileFileDependencies(fileContents, aURL, compilerOptions);
var warningsAndErrors = compiler.warningsAndErrors;
// Kind of a hack but if we get a file not found error on a #include the get include function above should have asked for the resource
// so we should be able to just bail out and wait for the the next call to compile when the include file is loaded (resolved)
if (warningsAndErrors && warningsAndErrors.length === 1 && warningsAndErrors[0].message.indexOf("file not found") > -1)
return;
if (Executable.printWarningsAndErrors(compiler, exports.messageOutputFormatInXML)) {
throw "Compilation error";
}
var fileDependencies = compiler.dependencies.map(function (aFileDep) {
return new FileDependency(new CFURL(aFileDep.url), aFileDep.isLocal);
});
self._fileDependencies = fileDependencies;
self._compiler = compiler;
success(self);
}
StaticResource.prototype.decompile = function()
{
var content = this.contents(),
aURL = this.URL(),
stream = new MarkedStream(content);
/*
if (stream.version !== "1.0")
return;
*/
var marker = NULL,
code = "",
dependencies = [],
sourceMap;
while (marker = stream.getMarker())
{
var text = stream.getString();
if (marker === MARKER_TEXT)
code += text;
else if (marker === MARKER_IMPORT_STD)
dependencies.push(new FileDependency(new CFURL(text), NO));
else if (marker === MARKER_IMPORT_LOCAL)
dependencies.push(new FileDependency(new CFURL(text), YES));
else if (marker === MARKER_SOURCE_MAP)
sourceMap = text;
}
this._fileDependencies = dependencies;
this._function = StaticResource._lookupCachedFunction(aURL);
this._sourceMap = sourceMap;
this._contents = code;
}
StaticResource.setCurrentGccCompilerFlags = function(/*String*/ compilerFlags)
{
if (currentGccCompilerFlags === compilerFlags) return;
currentGccCompilerFlags = compilerFlags;
// '(exports.ObjJCompiler || ObjJCompiler)' is a temporary fix so it can work both in the Narwhal (exports.ObjJCompiler) and Node (ObjJCompiler) world
var objjcFlags = (exports.ObjJCompiler || ObjJCompiler).parseGccCompilerFlags(compilerFlags);
StaticResource.setCurrentCompilerFlags(objjcFlags);
}
StaticResource.currentGccCompilerFlags = function(/*String*/ compilerFlags)
{
return currentGccCompilerFlags;
}
StaticResource.setCurrentCompilerFlags = function(/*JSObject*/ compilerFlags)
{
currentCompilerFlags = compilerFlags;
// Here we set the default flags if they are not included. We do this as the default values
// in the compiler might not be what we want.
if (currentCompilerFlags.transformNamedFunctionDeclarationToAssignment == null)
currentCompilerFlags.transformNamedFunctionDeclarationToAssignment = true;
if (currentCompilerFlags.sourceMap == null)
currentCompilerFlags.sourceMap = false;
if (currentCompilerFlags.inlineMsgSendFunctions == null)
currentCompilerFlags.inlineMsgSendFunctions = false;
}
StaticResource.currentCompilerFlags = function(/*JSObject*/ compilerFlags)
{
return currentCompilerFlags;
}
var FunctionCache = { };
StaticResource._cacheFunction = function(/*CFURL|String*/ aURL, /*Function*/ fn)
{
aURL = typeof aURL === "string" ? aURL : aURL.absoluteString();
FunctionCache[aURL] = fn;
}
StaticResource._lookupCachedFunction = function(/*CFURL|String*/ aURL)
{
aURL = typeof aURL === "string" ? aURL : aURL.absoluteString();
return FunctionCache[aURL];
}
StaticResource.prototype.name = function()
{
return this._name;
@@ -218,11 +460,11 @@ StaticResource.resolveResourcesAtURLs = function(/*Array of CFURL|String*/ URLs,
}
}
StaticResource.resolveResourceAtURL = function(/*CFURL|String*/ aURL, /*BOOL*/ isDirectory, /*Function*/ aCallback, /*Dictionary*/ aFilenameTranslateDictionary)
StaticResource.resolveResourceAtURL = function(/*CFURL|String*/ aURL, /*BOOL*/ isDirectory, /*Function*/ aCallback, /*Dictionary*/ aFilenameTranslateDictionary, /*BOOL*/ dontCompile)
{
aURL = makeAbsoluteURL(aURL).absoluteURL();
resolveResourceComponents(rootResourceForAbsoluteURL(aURL), isDirectory, aURL.pathComponents(), 0, aCallback, aFilenameTranslateDictionary);
resolveResourceComponents(rootResourceForAbsoluteURL(aURL), isDirectory, aURL.pathComponents(), 0, aCallback, aFilenameTranslateDictionary, null, dontCompile);
};
StaticResource.prototype.resolveResourceAtURL = function(/*CFURL|String*/ aURL, /*BOOL*/ isDirectory, /*Function*/ aCallback)
@@ -230,7 +472,7 @@ StaticResource.prototype.resolveResourceAtURL = function(/*CFURL|String*/ aURL,
StaticResource.resolveResourceAtURL(new CFURL(aURL, this.URL()).absoluteURL(), isDirectory, aCallback);
};
function resolveResourceComponents(/*StaticResource*/ aResource, /*BOOL*/ isDirectory, /*Array*/ components, /*Integer*/ index, /*Function*/ aCallback, /*Dictionry*/ aFilenameTranslateDictionary)
function resolveResourceComponents(/*StaticResource*/ aResource, /*BOOL*/ isDirectory, /*Array*/ components, /*Integer*/ index, /*Function*/ aCallback, /*Dictionary*/ aFilenameTranslateDictionary, /*Array*/ compileIncludeFileArray, /*BOOL*/ dontCompile)
{
var count = components.length;
@@ -242,8 +484,31 @@ function resolveResourceComponents(/*StaticResource*/ aResource, /*BOOL*/ isDire
// If the child doesn't exist, create and resolve it.
if (!child)
{
child = new StaticResource(new CFURL(name, aResource.URL()), aResource, index + 1 < count || isDirectory , NO, aFilenameTranslateDictionary);
child.resolve();
var translationDictionary = nil;
if (aFilenameTranslateDictionary == null) {
var bundle = new CFBundle(aResource.URL());
if (bundle != null) {
var bundleTranslationDictionary = bundle.valueForInfoDictionaryKey("CPFileTranslationDictionary");
if (bundleTranslationDictionary != null) {
translationDictionary = bundleTranslationDictionary.toJSObject();
}
var bundleIncludeFileArray = bundle.valueForInfoDictionaryKey("CPCompileIncludeFileArray");
if (bundleIncludeFileArray != null) {
compileIncludeFileArray = bundleIncludeFileArray.map(function(includeFilePath) {
return new CFURL(includeFilePath, aResource.URL());
});
}
}
}
var u = new CFURL(name, aResource.URL());
child = new StaticResource(u, aResource, index + 1 < count || isDirectory , NO, translationDictionary || aFilenameTranslateDictionary);
child.resolve(dontCompile, compileIncludeFileArray);
}
// If this resource is still being resolved, just wait and rerun this same method when it's ready.
@@ -251,7 +516,7 @@ function resolveResourceComponents(/*StaticResource*/ aResource, /*BOOL*/ isDire
return child.addEventListener("resolve", function()
{
// Continue resolving once this is done.
resolveResourceComponents(aResource, isDirectory, components, index, aCallback, aFilenameTranslateDictionary);
resolveResourceComponents(aResource, isDirectory, components, index, aCallback, aFilenameTranslateDictionary, compileIncludeFileArray, dontCompile);
});
// If we've already determined that this file doesn't exist...
@@ -364,3 +629,6 @@ StaticResource.includeURLs = function()
return includeURLs;
};
// Set the compiler flags to empty dictionary so the default values are correct.
StaticResource.setCurrentCompilerFlags({});