diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..6627afb --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "vendor/JSON-js"] + path = vendor/JSON-js + url = https://github.com/douglascrockford/JSON-js.git diff --git a/Rakefile b/Rakefile index 628d3cf..ba69c8c 100644 --- a/Rakefile +++ b/Rakefile @@ -1,5 +1,7 @@ require "rake/testtask" require "bundler/gem_tasks" +require 'fileutils' +require 'shellwords' task :default => :test @@ -65,3 +67,15 @@ task :test do raise "test failures" if failed.any? raise "all tests skipped" if !passed.any? end + +desc "Rebuild lib/execjs/support/json2.js" +task :js do + src = File.join('vendor', 'JSON-js', 'json2.js') + dest = File.join('lib', 'execjs', 'support', 'json2.js') + FileUtils.cp(src, dest) + patches = `#{['git', 'ls-files', 'patches', 'JSON-js'].shelljoin}`.split("\n") + patches.each do |patch| + `#{['patch', '-p1', '-i', patch].shelljoin}` + end + FileUtils.chmod(0644, dest) +end diff --git a/patches/JSON-js/.gitkeep b/patches/JSON-js/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/patches/JSON-js/0001-Ensure-JSON-var-isn-t-shadowed-in-JSC-and-Spidermonk.patch b/patches/JSON-js/0001-Ensure-JSON-var-isn-t-shadowed-in-JSC-and-Spidermonk.patch new file mode 100644 index 0000000..79b42ba --- /dev/null +++ b/patches/JSON-js/0001-Ensure-JSON-var-isn-t-shadowed-in-JSC-and-Spidermonk.patch @@ -0,0 +1,41 @@ +From f47c02c8536ce7cf0850b6a511fcecad6539eeaf Mon Sep 17 00:00:00 2001 +From: Joshua Peek +Date: Thu, 12 May 2011 10:24:07 -0500 +Subject: [PATCH] Ensure JSON var isn't shadowed in JSC and Spidermonkey + +--- + lib/execjs/support/json2.js | 13 +++++++------ + 1 file changed, 7 insertions(+), 6 deletions(-) + +diff --git a/lib/execjs/support/json2.js b/lib/execjs/support/json2.js +index 36d3dc3..fb8fe0a 100644 +--- a/lib/execjs/support/json2.js ++++ b/lib/execjs/support/json2.js +@@ -159,12 +159,13 @@ + // Create a JSON object only if one does not already exist. We create the + // methods in a closure to avoid creating global variables. + +-var JSON; +-if (!JSON) { +- JSON = {}; +-} ++(function (global) { ++ if (!global.JSON) { ++ global.JSON = {}; ++ } ++ ++ var JSON = global.JSON; + +-(function () { + "use strict"; + + function f(n) { +@@ -477,4 +478,4 @@ if (!JSON) { + throw new SyntaxError('JSON.parse'); + }; + } +-}()); ++}(this)); +-- +2.5.5 + diff --git a/vendor/JSON-js b/vendor/JSON-js new file mode 160000 index 0000000..633fe5a --- /dev/null +++ b/vendor/JSON-js @@ -0,0 +1 @@ +Subproject commit 633fe5ae4bd69985254a68ae111505ec3d3e74ab