Remove node.js specific version of Base.isPlainObject(), since straps.js can handle it now.

This commit is contained in:
Jürg Lehni 2013-05-27 14:10:38 -07:00
parent 8aec04702c
commit fef22f25e8
2 changed files with 8 additions and 19 deletions

View file

@ -309,10 +309,12 @@ var Base = new function() {
* plain Base object, as produced by Base.merge(). * plain Base object, as produced by Base.merge().
*/ */
isPlainObject: function(obj) { isPlainObject: function(obj) {
var proto = obj !== null && typeof obj === 'object' var ctor = obj != null && obj.constructor;
&& Object.getPrototypeOf(obj); // We also need to check for ctor.name === 'Object', in case
return proto && (proto === Object.prototype // this is an object from another global scope (e.g. an iframe,
|| proto === Base.prototype); // or another vm context in node.js).
return ctor && (ctor === Object || ctor === Base
|| ctor.name === 'Object');
}, },
check: function(obj) { check: function(obj) {

View file

@ -32,8 +32,8 @@ var options = {
var doc = jsdom.jsdom("<html><body></body></html>"), var doc = jsdom.jsdom("<html><body></body></html>"),
win = doc.createWindow(); win = doc.createWindow();
// Define XMLSerializer. // Define XMLSerializer and DOMParser shims, to emulate browser behavior.
// TODO: Put this into a simple node module, with dependency on jsdom // TODO: Put this into a simple node module, with dependency on jsdom?
function XMLSerializer() { function XMLSerializer() {
} }
@ -89,19 +89,6 @@ var context = vm.createContext({
// Load Paper.js library files: // Load Paper.js library files:
context.include('paper.js'); context.include('paper.js');
// Since the context used for Paper.js compilation, and the context in which
// Node.js scripts are executed do not share the definition of Object, we need
// to redefine Base.isPlainObject() here.
// So instead of checking for Object.prototype, we're checking
// proto.constructor.name for 'Object'
var Base = context.Base;
Base.isPlainObject = function(obj) {
var proto = obj !== null && typeof obj === 'object'
&& Object.getPrototypeOf(obj);
return proto && (proto.constructor.name === 'Object'
|| proto === Base.prototype);
};
context.PaperScope.inject({ context.PaperScope.inject({
// Expose the Canvas, XMLSerializer & DOMParser to PaperScope: // Expose the Canvas, XMLSerializer & DOMParser to PaperScope:
Canvas: Canvas, Canvas: Canvas,