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().
*/
isPlainObject: function(obj) {
var proto = obj !== null && typeof obj === 'object'
&& Object.getPrototypeOf(obj);
return proto && (proto === Object.prototype
|| proto === Base.prototype);
var ctor = obj != null && obj.constructor;
// We also need to check for ctor.name === 'Object', in case
// this is an object from another global scope (e.g. an iframe,
// or another vm context in node.js).
return ctor && (ctor === Object || ctor === Base
|| ctor.name === 'Object');
},
check: function(obj) {

View file

@ -32,8 +32,8 @@ var options = {
var doc = jsdom.jsdom("<html><body></body></html>"),
win = doc.createWindow();
// Define XMLSerializer.
// TODO: Put this into a simple node module, with dependency on jsdom
// Define XMLSerializer and DOMParser shims, to emulate browser behavior.
// TODO: Put this into a simple node module, with dependency on jsdom?
function XMLSerializer() {
}
@ -89,19 +89,6 @@ var context = vm.createContext({
// Load Paper.js library files:
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({
// Expose the Canvas, XMLSerializer & DOMParser to PaperScope:
Canvas: Canvas,