Skip to content

Commit

Permalink
🐛 Object.prototype.isPrototypeOf returns false for object literals #96
Browse files Browse the repository at this point in the history
  • Loading branch information
princejwesley committed Feb 6, 2016
1 parent 0dc638f commit 87adfc0
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 51 deletions.
2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -41,7 +41,7 @@
"babel-jest": "^6.0.1",
"del": "^2.0.2",
"electron-packager": "5.1.0",
"electron-prebuilt": "0.36.6",
"electron-prebuilt": "0.36.7",
"electron-rebuild": "^1.0.2",
"gulp": "^3.9.0",
"gulp-babel": "^6.1.1",
Expand Down
107 changes: 57 additions & 50 deletions src/common/ReplContext.js
Expand Up @@ -35,29 +35,13 @@ let createContext = () => {
'__filename',
'__dirname'
];
// polyfills
let polyfills = [
"Array",
"Object",
"Math",
"Symbol",
"String",
"Number",
"Reflect",
"System",
"Error",
];

let circulars = [ '_', 'global', 'GLOBAL', 'root'];
let circulars = ['global', 'GLOBAL', 'root'];

_.each(defaults, (g) => {
context[g] = global[g];
});

_.each(polyfills, (g) => {
context[g] = global[g];
});

_.each(circulars, (g) => {
context[g] = context;
});
Expand All @@ -78,27 +62,18 @@ let createContext = () => {
console.error(err);
});

let {createScript} = vm;
vm.createScript = (code, options) => {
try {
let {timeout} = getPreferences();
let cxt = createScript(code, options);
let runInContext = cxt.runInContext.bind(cxt);
cxt.runInContext = (contextifiedSandbox, options) => {
return runInContext(contextifiedSandbox, {
displayErrors: false,
timeout: timeout
});
};
global.Mancy.REPLError = null;
return cxt;
} catch(e) {
if(e instanceof SyntaxError) {
global.Mancy.REPLError = e;
}
throw e;
}
};
// load builtIns
let builtins = require('repl')._builtinLibs;
_.each(builtins, (name) => {
Object.defineProperty(context, name, {
get: () => (context[name] = require(name)),
set: (val) => {
delete context[name];
context[name] = val;
},
configurable: true
});
});

let _load = module._load;
module._load = (request, parent, isMain) => {
Expand All @@ -116,7 +91,6 @@ let createContext = () => {
}
};


let debuglog = util.debuglog;
util.debuglog = (name) => {
if(name === 'repl') {
Expand All @@ -140,18 +114,51 @@ let createContext = () => {
context.process.env.PATH += ':/usr/local/bin';
}

// load builtIns
let builtins = require('repl')._builtinLibs;
_.each(builtins, (name) => {
Object.defineProperty(context, name, {
get: () => (context[name] = require(name)),
set: (val) => {
delete context[name];
context[name] = val;
},
configurable: true
try {
let code =`
(() => {
'use strict';
let poly = require('core-js/shim');
Object.getOwnPropertyNames(poly).forEach(obj => {
if(!this[obj]) { this[obj] = poly[obj]; }
else {
Object.getOwnPropertyNames(poly[obj]).forEach(p => {
if(!this[obj][p]) { this[obj][p] = poly[obj][p]; }
});
}
});
})();
`
let script = vm.createScript(code, {
filename: 'mancy-repl',
displayErrors: false,
});
});
script.runInContext(context, { displayErrors: false });
} catch(e) {
console.log(e);
}

let {createScript} = vm;
vm.createScript = (code, options) => {
try {
let {timeout} = getPreferences();
let cxt = createScript(code, options);
let runInContext = cxt.runInContext.bind(cxt);
cxt.runInContext = (contextifiedSandbox, options) => {
return runInContext(contextifiedSandbox, {
displayErrors: false,
timeout: timeout
});
};
global.Mancy.REPLError = null;
return cxt;
} catch(e) {
if(e instanceof SyntaxError) {
global.Mancy.REPLError = e;
}
throw e;
}
};

return (cxt = context);
};
Expand Down

0 comments on commit 87adfc0

Please sign in to comment.