Skip to content


Subversion checkout URL

You can clone with
Download ZIP


Assert in new context #706

wants to merge 2 commits into from

6 participants


This is patch that helps make assert.throws work properly within new contexts.



Just checking in here to see if you'll be able to pull this, or if I should provide some other updates?




Any particular reason this hasn’t been pulled yet? I am in need of this functionality too.


This pull request now has a few conflicts in test/simple/test-script-context.js. Will need to be resolved.


I don't mind landing this but it needs to be rebased against master.

@trevnorris trevnorris referenced this pull request

Assert in new context #4370


@bnoordhuis I've taken the branch and rebased it against master in #4370.


Can one of the admins verify this patch?


Hey, this can be closed. It got moved over to #4370 and closed there. /cc @isaacs @bnoordhuis

@bnoordhuis bnoordhuis closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Feb 20, 2011
  1. @lukebayes
Commits on Mar 4, 2011
  1. @lukebayes

    Updated expectation to check for RegExp in a more compliant and confi…

    lukebayes authored
    …dent manner, based on feedback from tobie
This page is out of date. Refresh to see the latest.
Showing with 9 additions and 3 deletions.
  1. +1 −1  lib/assert.js
  2. +8 −2 test/simple/test-script-context.js
2  lib/assert.js
@@ -245,7 +245,7 @@ function expectedException(actual, expected) {
return false;
- if (expected instanceof RegExp) {
+ if ( == '[object RegExp]') {
return expected.test(actual);
} else if (actual instanceof expected) {
return true;
10 test/simple/test-script-context.js
@@ -1,7 +1,8 @@
var common = require('../common');
var assert = require('assert');
-var Script = require('vm').Script;
+var vm = require('vm');
+var Script = vm.Script;
var script = new Script('"passed";');
common.debug('run in a new empty context');
@@ -20,6 +21,11 @@ result = script.runInContext(context);
assert.equal('lala', context.thing);
// Issue GH-227:
Script.runInNewContext('', null, 'some.js');
+// 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 });
Something went wrong with that request. Please try again.