Skip to content

Commit

Permalink
fix: JS used by Android avoids any single line comments // to it will…
Browse files Browse the repository at this point in the history
… be correctly parsed
  • Loading branch information
HBehrens committed Apr 28, 2014
1 parent b5b738b commit cbf8933
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 10 deletions.
4 changes: 2 additions & 2 deletions source/js/transit-prompt.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@
};

})(
// TRANSIT_GLOBAL_NAME
/* TRANSIT_GLOBAL_NAME */
"transit"
// TRANSIT_GLOBAL_NAME
/* TRANSIT_GLOBAL_NAME */
);
14 changes: 7 additions & 7 deletions source/js/transit.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@
throw "must be replaced by native runtime " + invocationDescription;
};

// should be replaced by native runtime to support more efficient solution
// this behavior is expected:
// 1. if one call throws an exception, all others must still be executed
// 2. result is ignored
// 3. order is not relevant
/* should be replaced by native runtime to support more efficient solution */
/* this behavior is expected: */
/* 1. if one call throws an exception, all others must still be executed */
/* 2. result is ignored */
/* 3. order is not relevant */
transit.doHandleInvocationQueue = function(invocationDescriptions){
for(var i=0; i<invocationDescriptions.length; i++) {
var description = invocationDescriptions[i];
Expand Down Expand Up @@ -80,7 +80,7 @@
if(elem === GLOBAL_OBJECT) {
return MARKER_MAGIC_OBJECT_GLOBAL;
}
// when called from native code, typeof ('string') might return 'object'
/* when called from native code, typeof ('string') might return 'object' */
if(elem != null && [Object, Array, String, Boolean, Number].indexOf(elem.constructor)<0) {
return transit.retainElement(elem);
}
Expand Down Expand Up @@ -169,6 +169,6 @@
delete transit.retained[retainId];
};

window[globalName] = transit;
window[globalName] = transit;

})("transit");
2 changes: 1 addition & 1 deletion source/objc/Transit.m
Original file line number Diff line number Diff line change
Expand Up @@ -1946,6 +1946,6 @@ - (void)webView:(WebView *)webView windowScriptObjectAvailable:(WebScriptObject
// NOTE: this value is automatically generated by grunt. DO NOT CHANGE ANYTHING BEHIND THIS LINE
NSString* _TRANSIT_JS_RUNTIME_CODE = @
// _TRANSIT_JS_RUNTIME_CODE_START
"(function(){/*global Document Element */\n\n(function(globalName){\n var transit = {\n retained:{},\n lastRetainId: 0,\n invocationQueue: [],\n invocationQueueMaxLen: 1000,\n handleInvocationQueueIsScheduled: false\n };\n\n var PREFIX_MAGIC_FUNCTION = \"__TRANSIT_JS_FUNCTION_\";\n var PREFIX_MAGIC_NATIVE_FUNCTION = \"__TRANSIT_NATIVE_FUNCTION_\";\n var PREFIX_MAGIC_OBJECT = \"__TRANSIT_OBJECT_PROXY_\";\n var MARKER_MAGIC_OBJECT_GLOBAL = \"__TRANSIT_OBJECT_GLOBAL\";\n var GLOBAL_OBJECT = window;\n\n transit.doInvokeNative = function(invocationDescription){\n throw \"must be replaced by native runtime \" + invocationDescription;\n };\n\n // should be replaced by native runtime to support more efficient solution\n // this behavior is expected:\n // 1. if one call throws an exception, all others must still be executed\n // 2. result is ignored\n // 3. order is not relevant\n transit.doHandleInvocationQueue = function(invocationDescriptions){\n for(var i=0; i<invocationDescriptions.length; i++) {\n var description = invocationDescriptions[i];\n try {\n transit.doInvokeNative(description);\n } catch(e) {\n }\n }\n };\n transit.doHandleInvocationQueue.isFallback = true;\n\n transit.nativeFunction = function(nativeId, options){\n var f;\n if(options && options.async) {\n f = function(){\n transit.queueNative(nativeId, this, arguments, f.transitNoThis);\n };\n } else {\n f = function(){\n return transit.invokeNative(nativeId, this, arguments, f.transitNoThis);\n };\n }\n f.transitNoThis = options && options.noThis;\n f.transitNativeId = PREFIX_MAGIC_NATIVE_FUNCTION + nativeId;\n\n return f;\n };\n\n transit.recursivelyProxifyMissingFunctionProperties = function(missing, existing) {\n for(var key in existing) {\n if(existing.hasOwnProperty(key)) {\n var existingValue = existing[key];\n\n if(typeof existingValue === \"function\") {\n missing[key] = transit.proxify(existingValue);\n }\n if(typeof existingValue === \"object\" && typeof missing[key] === \"object\" && missing[key] !== null) {\n transit.recursivelyProxifyMissingFunctionProperties(missing[key], existingValue);\n }\n }\n }\n };\n\n transit.proxify = function(elem) {\n if(typeof elem === \"function\") {\n if(typeof elem.transitNativeId !== \"undefined\") {\n return elem.transitNativeId;\n } else {\n return transit.retainElement(elem);\n }\n }\n\n if(typeof elem === \"object\") {\n if(elem === GLOBAL_OBJECT) {\n return MARKER_MAGIC_OBJECT_GLOBAL;\n }\n // when called from native code, typeof ('string') might return 'object'\n if(elem != null && [Object, Array, String, Boolean, Number].indexOf(elem.constructor)<0) {\n return transit.retainElement(elem);\n }\n\n var copy;\n try {\n copy = JSON.parse(JSON.stringify(elem));\n } catch (e) {\n return transit.retainElement(elem);\n }\n transit.recursivelyProxifyMissingFunctionProperties(copy, elem);\n return copy;\n }\n\n return elem;\n };\n\n transit.createInvocationDescription = function(nativeId, thisArg, args, noThis) {\n var invocationDescription = {\n nativeId: nativeId,\n thisArg: noThis ? null : ((thisArg === GLOBAL_OBJECT) ? null : transit.proxify(thisArg)),\n args: []\n };\n\n for(var i = 0;i<args.length; i++) {\n invocationDescription.args.push(transit.proxify(args[i]));\n }\n\n return invocationDescription;\n };\n\n transit.invokeNative = function(nativeId, thisArg, args, noThis) {\n var invocationDescription = transit.createInvocationDescription(nativeId, thisArg, args, noThis);\n return transit.doInvokeNative(invocationDescription);\n };\n\n transit.handleInvocationQueue = function() {\n if(transit.handleInvocationQueueIsScheduled) {\n clearTimeout(transit.handleInvocationQueueIsScheduled);\n transit.handleInvocationQueueIsScheduled = false;\n }\n\n var copy = transit.invocationQueue;\n transit.invocationQueue = [];\n transit.doHandleInvocationQueue(copy);\n };\n\n transit.queueNative = function(nativeId, thisArg, args) {\n var invocationDescription = transit.createInvocationDescription(nativeId, thisArg, args);\n transit.invocationQueue.push(invocationDescription);\n if(transit.invocationQueue.length >= transit.invocationQueueMaxLen) {\n transit.handleInvocationQueue();\n } else {\n if(!transit.handleInvocationQueueIsScheduled) {\n transit.handleInvocationQueueIsScheduled = setTimeout(function(){\n transit.handleInvocationQueueIsScheduled = false;\n transit.handleInvocationQueue();\n }, 0);\n }\n }\n };\n\n transit.retainElement = function(element){\n transit.lastRetainId++;\n var id = \"\" + transit.lastRetainId;\n if(typeof element === \"object\") {\n id = PREFIX_MAGIC_OBJECT + id;\n }\n if(typeof element === \"function\") {\n id = PREFIX_MAGIC_FUNCTION + id;\n }\n\n transit.retained[id] = element;\n return id;\n };\n\n transit.r = function(retainId) {\n return transit.retained[retainId];\n };\n\n transit.releaseElementWithId = function(retainId) {\n if(typeof transit.retained[retainId] === \"undefined\") {\n throw \"no retained element with Id \" + retainId;\n }\n\n delete transit.retained[retainId];\n };\n\n window[globalName] = transit;\n\n})(\"transit\");(function(globalName){\n var transit = window[globalName];\n\n var callCount = 0;\n transit.doInvokeNative = function(invocationDescription){\n invocationDescription.callNumber = ++callCount;\n transit.nativeInvokeTransferObject = invocationDescription;\n\n var iFrame = document.createElement('iframe');\n iFrame.setAttribute('src', 'transit:/doInvokeNative?c='+callCount);\n\n /* this call blocks until native code returns */\n /* native ccde reads from and writes to transit.nativeInvokeTransferObject */\n document.documentElement.appendChild(iFrame);\n\n /* free resources */\n iFrame.parentNode.removeChild(iFrame);\n iFrame = null;\n\n if(transit.nativeInvokeTransferObject === invocationDescription) {\n throw new Error(\"internal error with transit: invocation transfer object not filled.\");\n }\n var result = transit.nativeInvokeTransferObject;\n if(result instanceof Error) {\n throw result;\n } else {\n return result;\n }\n };\n\n transit.doHandleInvocationQueue = function(invocationDescriptions) {\n callCount++;\n transit.nativeInvokeTransferObject = invocationDescriptions;\n var iFrame = document.createElement('iframe');\n iFrame.setAttribute('src', 'transit:/doHandleInvocationQueue?c='+callCount);\n\n document.documentElement.appendChild(iFrame);\n\n iFrame.parentNode.removeChild(iFrame);\n iFrame = null;\n transit.nativeInvokeTransferObject = null;\n };\n\n})(\"transit\");})()"
"(function(){/*global Document Element */\n\n(function(globalName){\n var transit = {\n retained:{},\n lastRetainId: 0,\n invocationQueue: [],\n invocationQueueMaxLen: 1000,\n handleInvocationQueueIsScheduled: false\n };\n\n var PREFIX_MAGIC_FUNCTION = \"__TRANSIT_JS_FUNCTION_\";\n var PREFIX_MAGIC_NATIVE_FUNCTION = \"__TRANSIT_NATIVE_FUNCTION_\";\n var PREFIX_MAGIC_OBJECT = \"__TRANSIT_OBJECT_PROXY_\";\n var MARKER_MAGIC_OBJECT_GLOBAL = \"__TRANSIT_OBJECT_GLOBAL\";\n var GLOBAL_OBJECT = window;\n\n transit.doInvokeNative = function(invocationDescription){\n throw \"must be replaced by native runtime \" + invocationDescription;\n };\n\n /* should be replaced by native runtime to support more efficient solution */\n /* this behavior is expected: */\n /* 1. if one call throws an exception, all others must still be executed */\n /* 2. result is ignored */\n /* 3. order is not relevant */\n transit.doHandleInvocationQueue = function(invocationDescriptions){\n for(var i=0; i<invocationDescriptions.length; i++) {\n var description = invocationDescriptions[i];\n try {\n transit.doInvokeNative(description);\n } catch(e) {\n }\n }\n };\n transit.doHandleInvocationQueue.isFallback = true;\n\n transit.nativeFunction = function(nativeId, options){\n var f;\n if(options && options.async) {\n f = function(){\n transit.queueNative(nativeId, this, arguments, f.transitNoThis);\n };\n } else {\n f = function(){\n return transit.invokeNative(nativeId, this, arguments, f.transitNoThis);\n };\n }\n f.transitNoThis = options && options.noThis;\n f.transitNativeId = PREFIX_MAGIC_NATIVE_FUNCTION + nativeId;\n\n return f;\n };\n\n transit.recursivelyProxifyMissingFunctionProperties = function(missing, existing) {\n for(var key in existing) {\n if(existing.hasOwnProperty(key)) {\n var existingValue = existing[key];\n\n if(typeof existingValue === \"function\") {\n missing[key] = transit.proxify(existingValue);\n }\n if(typeof existingValue === \"object\" && typeof missing[key] === \"object\" && missing[key] !== null) {\n transit.recursivelyProxifyMissingFunctionProperties(missing[key], existingValue);\n }\n }\n }\n };\n\n transit.proxify = function(elem) {\n if(typeof elem === \"function\") {\n if(typeof elem.transitNativeId !== \"undefined\") {\n return elem.transitNativeId;\n } else {\n return transit.retainElement(elem);\n }\n }\n\n if(typeof elem === \"object\") {\n if(elem === GLOBAL_OBJECT) {\n return MARKER_MAGIC_OBJECT_GLOBAL;\n }\n /* when called from native code, typeof ('string') might return 'object' */\n if(elem != null && [Object, Array, String, Boolean, Number].indexOf(elem.constructor)<0) {\n return transit.retainElement(elem);\n }\n\n var copy;\n try {\n copy = JSON.parse(JSON.stringify(elem));\n } catch (e) {\n return transit.retainElement(elem);\n }\n transit.recursivelyProxifyMissingFunctionProperties(copy, elem);\n return copy;\n }\n\n return elem;\n };\n\n transit.createInvocationDescription = function(nativeId, thisArg, args, noThis) {\n var invocationDescription = {\n nativeId: nativeId,\n thisArg: noThis ? null : ((thisArg === GLOBAL_OBJECT) ? null : transit.proxify(thisArg)),\n args: []\n };\n\n for(var i = 0;i<args.length; i++) {\n invocationDescription.args.push(transit.proxify(args[i]));\n }\n\n return invocationDescription;\n };\n\n transit.invokeNative = function(nativeId, thisArg, args, noThis) {\n var invocationDescription = transit.createInvocationDescription(nativeId, thisArg, args, noThis);\n return transit.doInvokeNative(invocationDescription);\n };\n\n transit.handleInvocationQueue = function() {\n if(transit.handleInvocationQueueIsScheduled) {\n clearTimeout(transit.handleInvocationQueueIsScheduled);\n transit.handleInvocationQueueIsScheduled = false;\n }\n\n var copy = transit.invocationQueue;\n transit.invocationQueue = [];\n transit.doHandleInvocationQueue(copy);\n };\n\n transit.queueNative = function(nativeId, thisArg, args) {\n var invocationDescription = transit.createInvocationDescription(nativeId, thisArg, args);\n transit.invocationQueue.push(invocationDescription);\n if(transit.invocationQueue.length >= transit.invocationQueueMaxLen) {\n transit.handleInvocationQueue();\n } else {\n if(!transit.handleInvocationQueueIsScheduled) {\n transit.handleInvocationQueueIsScheduled = setTimeout(function(){\n transit.handleInvocationQueueIsScheduled = false;\n transit.handleInvocationQueue();\n }, 0);\n }\n }\n };\n\n transit.retainElement = function(element){\n transit.lastRetainId++;\n var id = \"\" + transit.lastRetainId;\n if(typeof element === \"object\") {\n id = PREFIX_MAGIC_OBJECT + id;\n }\n if(typeof element === \"function\") {\n id = PREFIX_MAGIC_FUNCTION + id;\n }\n\n transit.retained[id] = element;\n return id;\n };\n\n transit.r = function(retainId) {\n return transit.retained[retainId];\n };\n\n transit.releaseElementWithId = function(retainId) {\n if(typeof transit.retained[retainId] === \"undefined\") {\n throw \"no retained element with Id \" + retainId;\n }\n\n delete transit.retained[retainId];\n };\n\n window[globalName] = transit; \n\n})(\"transit\");(function(globalName){\n var transit = window[globalName];\n\n var callCount = 0;\n transit.doInvokeNative = function(invocationDescription){\n invocationDescription.callNumber = ++callCount;\n transit.nativeInvokeTransferObject = invocationDescription;\n\n var iFrame = document.createElement('iframe');\n iFrame.setAttribute('src', 'transit:/doInvokeNative?c='+callCount);\n\n /* this call blocks until native code returns */\n /* native ccde reads from and writes to transit.nativeInvokeTransferObject */\n document.documentElement.appendChild(iFrame);\n\n /* free resources */\n iFrame.parentNode.removeChild(iFrame);\n iFrame = null;\n\n if(transit.nativeInvokeTransferObject === invocationDescription) {\n throw new Error(\"internal error with transit: invocation transfer object not filled.\");\n }\n var result = transit.nativeInvokeTransferObject;\n if(result instanceof Error) {\n throw result;\n } else {\n return result;\n }\n };\n\n transit.doHandleInvocationQueue = function(invocationDescriptions) {\n callCount++;\n transit.nativeInvokeTransferObject = invocationDescriptions;\n var iFrame = document.createElement('iframe');\n iFrame.setAttribute('src', 'transit:/doHandleInvocationQueue?c='+callCount);\n\n document.documentElement.appendChild(iFrame);\n\n iFrame.parentNode.removeChild(iFrame);\n iFrame = null;\n transit.nativeInvokeTransferObject = null;\n };\n\n})(\"transit\");})()"
// _TRANSIT_JS_RUNTIME_CODE_END
;

0 comments on commit cbf8933

Please sign in to comment.