From ae1b0ca7a598438330854ccd83bae13db3e7d2b0 Mon Sep 17 00:00:00 2001 From: lukebayes Date: Sun, 20 Feb 2011 15:09:23 -0800 Subject: [PATCH] assert: improve support for new execution contexts More detailed information in GH-693 --- lib/assert.js | 2 +- test/simple/test-script-context.js | 8 +++++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/lib/assert.js b/lib/assert.js index f81c203491..a2afdcfb0b 100644 --- a/lib/assert.js +++ b/lib/assert.js @@ -277,7 +277,7 @@ function expectedException(actual, expected) { return false; } - if (expected instanceof RegExp) { + if (Object.prototype.toString.call(expected) == '[object RegExp]') { return expected.test(actual); } else if (actual instanceof expected) { return true; diff --git a/test/simple/test-script-context.js b/test/simple/test-script-context.js index f29af2303f..8095a713e9 100644 --- a/test/simple/test-script-context.js +++ b/test/simple/test-script-context.js @@ -42,7 +42,6 @@ result = script.runInContext(context); assert.equal(3, context.foo); assert.equal('lala', context.thing); - // Issue GH-227: Script.runInNewContext('', null, 'some.js'); @@ -69,3 +68,10 @@ function isTypeError(o) { assert.throws(function() { script.runInContext(e); }, isTypeError); assert.throws(function() { vm.runInContext('', e); }, isTypeError); })); + +// Issue GH-693: +common.debug('test RegExp as argument to assert.throws'); +script = vm.createScript('var assert = require(\'assert\'); assert.throws(' + + 'function() { throw "hello world"; }, /hello/);', + 'some.js'); +script.runInNewContext({ require : require });