From fef22f25e870913b79bc082c3bb0ebd56edcd3f7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=BCrg=20Lehni?= Date: Mon, 27 May 2013 14:10:38 -0700 Subject: [PATCH] Remove node.js specific version of Base.isPlainObject(), since straps.js can handle it now. --- lib/straps.js | 10 ++++++---- src/node/index.js | 17 ++--------------- 2 files changed, 8 insertions(+), 19 deletions(-) diff --git a/lib/straps.js b/lib/straps.js index 9c99f303..30bc0fed 100755 --- a/lib/straps.js +++ b/lib/straps.js @@ -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) { diff --git a/src/node/index.js b/src/node/index.js index c9838a65..e1659886 100644 --- a/src/node/index.js +++ b/src/node/index.js @@ -32,8 +32,8 @@ var options = { var doc = jsdom.jsdom(""), 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,