Skip to content
This repository has been archived by the owner. It is now read-only.
Permalink
Browse files
bullet-proof'd modjewel
bug: https://issues.apache.org/jira/browse/CB-293

`require()` and `define()` are no longer globally defined
in modjewel, only the object `modjewel` is globally defined.

Changed references of `define()` to `modjewel.define()`, and
change the initial launching `require()`s in the client and target
to `modjewel.require()`.  There were also a couple of 'scripts'
which needed changes to the `modjewel` specific version of `require()`.

Drive-by fix to upgrade modjewel version to 2.0, and found an
old 512x512 weinre icon (from the old mac app's .icns file) to
add in case we need bigger than 128x128
  • Loading branch information
pmuellr committed Mar 2, 2012
1 parent 3a34438 commit d0a4694a19690ae2c3ce9f0e83c926ed9acd97e3
Showing 10 changed files with 45 additions and 34 deletions.
@@ -0,0 +1,18 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
@@ -65,7 +65,7 @@ def createIndexFile(iFileName, oFileName, moduleDir):
'<script type="text/javascript" src="weinre/check-for-webkit.js"></script>\n',
'<script type="text/javascript" src="weinre/hacks.js"></script>\n',
'<script type="text/javascript" src="../modjewel.js"></script>\n',
'<script type="text/javascript">require("modjewel").warnOnRecursiveRequire(true)</script>\n',
'<script type="text/javascript">modjewel.require("modjewel").warnOnRecursiveRequire(true)</script>\n',
])

for module in getModules(moduleDir):
@@ -78,7 +78,7 @@ def createIndexFile(iFileName, oFileName, moduleDir):
newLines.append("<!-- ========== weinre additions: starting ========== -->\n")
newLines.append('<link rel="stylesheet" type="text/css" href="weinre/client.css">\n')
newLines.append('<script type="text/javascript" src="../interfaces/all-json-idls-min.js"></script>\n')
newLines.append('<script type="text/javascript">require("weinre/client/Client").main()</script>\n')
newLines.append('<script type="text/javascript">modjewel.require("weinre/client/Client").main()</script>\n')
newLines.append("<!-- ========== weinre additions: done ========== -->\n")
newLines.append(line)

@@ -86,6 +86,12 @@ def main():
#--------------------------------------------------------------------
def writeMergedFile(oFileName, scripts, scriptNames, srcs, useEval):
lines = []

licenseFile = os.path.join(os.path.dirname(__file__), "..", "LICENSE-header.js")

with open(licenseFile, "r") as iFile:
lines.append(iFile.read())

lines.append(";(function(){")

for script in scripts:
@@ -101,12 +107,12 @@ def writeMergedFile(oFileName, scripts, scriptNames, srcs, useEval):
lines.append(";eval(%s)" % json.dumps(src))

if srcName == "modjewel.js":
lines.append("require('modjewel').warnOnRecursiveRequire(true);")
lines.append("modjewel.require('modjewel').warnOnRecursiveRequire(true);")
if not useEval:
lines.append("")

lines.append("// require('weinre/common/Weinre').showNotImplemented();")
lines.append("require('weinre/target/Target').main()")
lines.append("// modjewel.require('weinre/common/Weinre').showNotImplemented();")
lines.append("modjewel.require('weinre/target/Target').main()")
lines.append("})();")
targetScript = "\n".join(lines)

@@ -64,7 +64,7 @@ def main():
else:
jsonString = json.dumps(result, indent=4)

jsString = "require('weinre/common/Weinre').addIDLs(%s)" % jsonString
jsString = "modjewel.require('weinre/common/Weinre').addIDLs(%s)" % jsonString

oFile = open(oFileName, "w")
oFile.write(jsString)
@@ -157,7 +157,7 @@ def processDir(dir, path=None, modules=None):

modules.append(moduleName)

header = ';define("%s", function(require, exports, module) {' % moduleName
header = ';modjewel.define("%s", function(require, exports, module) {' % moduleName
trailer = '});'

newContents = "%s %s\n%s\n" % (header, contents, trailer)
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@@ -18,6 +18,6 @@
*/

(function() {
var ExtensionRegistryImpl = require("weinre/client/ExtensionRegistryImpl")
var ExtensionRegistryImpl = modjewel.require("weinre/client/ExtensionRegistryImpl")
window.InspectorExtensionRegistry = new ExtensionRegistryImpl()
})()
@@ -18,6 +18,6 @@
*/

(function() {
var InspectorBackendImpl = require("weinre/client/InspectorBackendImpl")
var InspectorBackendImpl = modjewel.require("weinre/client/InspectorBackendImpl")
window.InspectorBackend = new InspectorBackendImpl()
})()
@@ -18,6 +18,6 @@
*/

(function() {
var InspectorFrontEndHostImpl = require("weinre/client/InspectorFrontendHostImpl")
var InspectorFrontEndHostImpl = modjewel.require("weinre/client/InspectorFrontendHostImpl")
window.InspectorFrontendHost = new InspectorFrontEndHostImpl()
})()
@@ -42,7 +42,7 @@
// some constants
//----------------------------------------------------------------------------
var PROGRAM = "modjewel"
var VERSION = "1.2.0"
var VERSION = "2.0.0"
var global = this

//----------------------------------------------------------------------------
@@ -55,10 +55,6 @@ if (global.modjewel) {

global.modjewel = null

var OriginalRequire = global.require
var OriginalDefine = global.define
var NoConflict = false

//----------------------------------------------------------------------------
// "globals" (local to this function scope though)
//----------------------------------------------------------------------------
@@ -174,12 +170,15 @@ function require_reset() {
ModulePreloadStore = {}
MainModule = create_module(null)

require_define("modjewel", modjewel_module)
var require = get_require(MainModule)
var define = require_define

define("modjewel", modjewel_module)

global.require = get_require(MainModule)
global.define = require_define
global.define.amd = true
global.modjewel = require("modjewel")
global.modjewel = require("modjewel")
global.modjewel.require = require
global.modjewel.define = define
global.modjewel.define.amd = {implementation: PROGRAM, version: VERSION}
}

//----------------------------------------------------------------------------
@@ -332,30 +331,18 @@ function modjewel_warnOnRecursiveRequire(value) {
WarnOnRecursiveRequire = !!value
}

//----------------------------------------------------------------------------
// relinquish modjewel's control of the require variable
// - like jQuery's version'
//----------------------------------------------------------------------------
function modjewel_noConflict() {
NoConflict = true

global.require = OriginalRequire
global.define = OriginalDefine
}

//----------------------------------------------------------------------------
// the modjewel module
//----------------------------------------------------------------------------
function modjewel_module(require, exports, module) {
exports.VERSION = VERSION
exports.require = require
exports.define = require.define
exports.require = null // filled in later
exports.define = null // filled in later
exports.getLoadedModuleIds = modjewel_getLoadedModuleIds
exports.getPreloadedModuleIds = modjewel_getPreloadedModuleIds
exports.getModule = modjewel_getModule
exports.getModuleIdsRequired = modjewel_getModuleIdsRequired
exports.warnOnRecursiveRequire = modjewel_warnOnRecursiveRequire
exports.noConflict = modjewel_noConflict
}

//----------------------------------------------------------------------------

0 comments on commit d0a4694

Please sign in to comment.