1
0
mirror of https://github.com/kkapsner/CanvasBlocker synced 2024-06-13 08:29:52 +02:00

Secured getWrapped from weird errors (Unexpected object).

Fixes #133
This commit is contained in:
kkapsner 2017-10-10 21:11:05 +02:00
parent c5872ef5a1
commit 68fb7730b9

View File

@ -2,16 +2,29 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
window.scope = {};
function require(module){
const require = function(){
"use strict";
window.scope = {};
const scope = window.scope;
function require(module){
if (module.startsWith("./")){
var scopeName = module.substr(2).replace(/\..+/, "");
return window.scope[scopeName];
return scope[scopeName];
}
else if (module === "sdk/getWrapped"){
return function getWrapped(obj){
return obj.wrappedJSObject || obj;
if (!obj){
return obj;
}
var wrapped;
try {
wrapped = obj.wrappedJSObject || obj;
}
catch (e){
require("./logging").error("getWrapped failed for", obj, ":", e);
wrapped = obj;
}
return wrapped;
};
}
else if (module === "sdk/simple-prefs"){
@ -29,6 +42,7 @@ function require(module){
};
}
throw new ReferenceError("Unable to get non relative module " + module + "!");
}
}
window.scope.require = require;
return require;
}();