From 24f9ae42b8ae0617ec2b67cece61556bd752c7cd Mon Sep 17 00:00:00 2001 From: Muhsin Abdul-Musawwir Date: Sat, 22 Apr 2017 12:27:42 -0700 Subject: [PATCH 1/3] test: refactored context type err message to regex --- test/parallel/test-vm-context.js | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/test/parallel/test-vm-context.js b/test/parallel/test-vm-context.js index 6f676034c3ff3a..234a66396302b0 100644 --- a/test/parallel/test-vm-context.js +++ b/test/parallel/test-vm-context.js @@ -62,9 +62,27 @@ assert.ok(gh1140Exception, 'expected exception from runInContext signature test'); // GH-558, non-context argument segfaults / raises assertion -[undefined, null, 0, 0.0, '', {}, []].forEach(function(e) { - assert.throws(function() { script.runInContext(e); }, TypeError); - assert.throws(function() { vm.runInContext('', e); }, TypeError); +const nonContextualSandboxErrorMsg = + /^TypeError: contextifiedSandbox argument must be an object\.$/; + +[undefined, null, 0, 0.0, ''].forEach(function(e) { + + assert.throws(function() { script.runInContext(e); }, + nonContextualSandboxErrorMsg); + assert.throws(function() { vm.runInContext('', e); }, + nonContextualSandboxErrorMsg); +}); + +// GH-558, non-context argument segfaults / raises assertion +const contextifiedSandboxErrorMsg = + /^TypeError: sandbox argument must have been converted to a context\.$/; + +[{}, []].forEach(function(e) { + + assert.throws(function() { script.runInContext(e); }, + contextifiedSandboxErrorMsg); + assert.throws(function() { vm.runInContext('', e); }, + contextifiedSandboxErrorMsg); }); // Issue GH-693: From 1c7c87f59c5519f9ac510305cf82629515083615 Mon Sep 17 00:00:00 2001 From: Muhsin Abdul-Musawwir Date: Sat, 22 Apr 2017 13:11:47 -0700 Subject: [PATCH 2/3] test: changed throw for runInNewContext to regex --- test/parallel/test-vm-context.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/parallel/test-vm-context.js b/test/parallel/test-vm-context.js index 234a66396302b0..683a11a7914506 100644 --- a/test/parallel/test-vm-context.js +++ b/test/parallel/test-vm-context.js @@ -46,7 +46,7 @@ assert.strictEqual('lala', context.thing); // Issue GH-227: assert.throws(function() { vm.runInNewContext('', null, 'some.js'); -}, TypeError); +}, /^TypeError: sandbox must be an object$/); // Issue GH-1140: console.error('test runInContext signature'); From c33fac3ea1891d5da14fc6365f990936b7bea145 Mon Sep 17 00:00:00 2001 From: Muhsin Abdul-Musawwir Date: Sat, 22 Apr 2017 13:32:59 -0700 Subject: [PATCH 3/3] test: changed type error throws to regex --- test/parallel/test-vm-context.js | 27 +++++++++------------------ 1 file changed, 9 insertions(+), 18 deletions(-) diff --git a/test/parallel/test-vm-context.js b/test/parallel/test-vm-context.js index 683a11a7914506..1cf2d5f90aaf54 100644 --- a/test/parallel/test-vm-context.js +++ b/test/parallel/test-vm-context.js @@ -64,25 +64,16 @@ assert.ok(gh1140Exception, // GH-558, non-context argument segfaults / raises assertion const nonContextualSandboxErrorMsg = /^TypeError: contextifiedSandbox argument must be an object\.$/; - -[undefined, null, 0, 0.0, ''].forEach(function(e) { - - assert.throws(function() { script.runInContext(e); }, - nonContextualSandboxErrorMsg); - assert.throws(function() { vm.runInContext('', e); }, - nonContextualSandboxErrorMsg); -}); - -// GH-558, non-context argument segfaults / raises assertion const contextifiedSandboxErrorMsg = - /^TypeError: sandbox argument must have been converted to a context\.$/; - -[{}, []].forEach(function(e) { - - assert.throws(function() { script.runInContext(e); }, - contextifiedSandboxErrorMsg); - assert.throws(function() { vm.runInContext('', e); }, - contextifiedSandboxErrorMsg); + /^TypeError: sandbox argument must have been converted to a context\.$/; +[ + [undefined, nonContextualSandboxErrorMsg], + [null, nonContextualSandboxErrorMsg], [0, nonContextualSandboxErrorMsg], + [0.0, nonContextualSandboxErrorMsg], ['', nonContextualSandboxErrorMsg], + [{}, contextifiedSandboxErrorMsg], [[], contextifiedSandboxErrorMsg] +].forEach((e) => { + assert.throws(() => { script.runInContext(e[0]); }, e[1]); + assert.throws(() => { vm.runInContext('', e[0]); }, e[1]); }); // Issue GH-693: