mirror of
https://github.com/cappuccino/cappuccino.git
synced 2026-11-21 22:19:26 +00:00
Add CFHTTPRequest and FileExecutable hooks for inlining files and module functions (for flatten). Removed hook used by flatten.
This commit is contained in:
1 parent
956ef29449
commit
60e2be5da9
2 files changed
+72
-7
No files matched your search
@@ -196,9 +196,14 @@ CFHTTPRequest.prototype.overrideMimeType = function(/*String*/ aMimeType)
|
||||
return this._nativeRequest.overrideMimeType(aMimeType);
|
||||
}
|
||||
|
||||
CFHTTPRequest.prototype.open = function(/*...*/)
|
||||
CFHTTPRequest.prototype.open = function(/*String*/ method, /*String*/ url, /*Boolean*/ async, /*String*/ user, /*String*/ password)
|
||||
{
|
||||
return this._nativeRequest.open(arguments[0], arguments[1], arguments[2], arguments[3], arguments[4]);
|
||||
var cachedRequest = CFHTTPRequest._lookupCachedRequest(url);
|
||||
if (cachedRequest) {
|
||||
cachedRequest.onreadystatechange = this._nativeRequest.onreadystatechange;
|
||||
this._nativeRequest = cachedRequest;
|
||||
}
|
||||
return this._nativeRequest.open(method, url, async, user, password);
|
||||
}
|
||||
|
||||
CFHTTPRequest.prototype.send = function(/*Object*/ aBody)
|
||||
@@ -279,3 +284,48 @@ FileRequest.async = YES;
|
||||
#else
|
||||
FileRequest.async = NO;
|
||||
#endif
|
||||
|
||||
|
||||
var URLCache = { };
|
||||
|
||||
CFHTTPRequest._cacheRequest = function(/*CFURL|String*/ aURL, /*Number*/ status, /*Object*/ headers, /*String*/ body)
|
||||
{
|
||||
aURL = typeof aURL === "string" ? aURL : aURL.absoluteString();
|
||||
URLCache[aURL] = new MockXMLHttpRequest(status, headers, body);
|
||||
}
|
||||
|
||||
CFHTTPRequest._lookupCachedRequest = function(/*CFURL|String*/ aURL)
|
||||
{
|
||||
aURL = typeof aURL === "string" ? aURL : aURL.absoluteString();
|
||||
return URLCache[aURL];
|
||||
}
|
||||
|
||||
function MockXMLHttpRequest(status, headers, body)
|
||||
{
|
||||
this.readyState = CFHTTPRequest.UninitializedState;
|
||||
this.status = status || 200;
|
||||
this.statusText = "";
|
||||
this.responseText = body || "";
|
||||
this._responseHeaders = headers || {};
|
||||
};
|
||||
MockXMLHttpRequest.prototype.open = function(method, url, async, user, password)
|
||||
{
|
||||
this.readyState = CFHTTPRequest.LoadingState;
|
||||
this.async = async;
|
||||
};
|
||||
MockXMLHttpRequest.prototype.send = function(body)
|
||||
{
|
||||
var self = this;
|
||||
self.responseText = self.responseText.toString();
|
||||
function complete() {
|
||||
for (self.readyState = CFHTTPRequest.LoadedState; self.readyState <= CFHTTPRequest.CompleteState; self.readyState++)
|
||||
self.onreadystatechange();
|
||||
}
|
||||
(self.async ? Asynchronous(complete) : complete)();
|
||||
};
|
||||
MockXMLHttpRequest.prototype.onreadystatechange = function() {};
|
||||
MockXMLHttpRequest.prototype.abort = function() {};
|
||||
MockXMLHttpRequest.prototype.setRequestHeader = function(header, value) {};
|
||||
MockXMLHttpRequest.prototype.getAllResponseHeaders = function() { return this._responseHeaders; };
|
||||
MockXMLHttpRequest.prototype.getResponseHeader = function(header) { return this._responseHeaders[header]; };
|
||||
MockXMLHttpRequest.prototype.overrideMimeType = function(mimetype) {};
|
||||
@@ -22,7 +22,7 @@
|
||||
|
||||
var FileExecutablesForURLStrings = { };
|
||||
|
||||
function FileExecutable(/*CFURL|String*/ aURL, /*Executable*/ anExecutable)
|
||||
function FileExecutable(/*CFURL|String*/ aURL)
|
||||
{
|
||||
aURL = makeAbsoluteURL(aURL);
|
||||
|
||||
@@ -38,10 +38,7 @@ function FileExecutable(/*CFURL|String*/ aURL, /*Executable*/ anExecutable)
|
||||
executable = NULL,
|
||||
extension = aURL.pathExtension();
|
||||
|
||||
if (anExecutable)
|
||||
executable = anExecutable;
|
||||
|
||||
else if (fileContents.match(/^@STATIC;/))
|
||||
if (fileContents.match(/^@STATIC;/))
|
||||
executable = decompile(fileContents, aURL);
|
||||
|
||||
else if (extension === "j" || !extension)
|
||||
@@ -117,5 +114,23 @@ function decompile(/*String*/ aString, /*CFURL*/ aURL)
|
||||
dependencies.push(new FileDependency(new CFURL(text), YES));
|
||||
}
|
||||
|
||||
var fn = FileExecutable._lookupCachedFunction(aURL)
|
||||
if (fn)
|
||||
return new Executable(code, dependencies, aURL, fn);
|
||||
|
||||
return new Executable(code, dependencies, aURL);
|
||||
}
|
||||
|
||||
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];
|
||||
}
|
||||
Reference in new issue
Block a user