From c248f68288894f152e7e6dc74a8a66375c4986bc Mon Sep 17 00:00:00 2001 From: Duncan Healy Date: Tue, 12 Nov 2019 16:54:35 +0000 Subject: [PATCH 1/2] doc: test-vm-function-declaration test add let declaration of function --- test/parallel/test-vm-function-declaration.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/test/parallel/test-vm-function-declaration.js b/test/parallel/test-vm-function-declaration.js index 6405babfa78148..23552e503dd985 100644 --- a/test/parallel/test-vm-function-declaration.js +++ b/test/parallel/test-vm-function-declaration.js @@ -28,17 +28,19 @@ const o = vm.createContext({ console }); // Function declaration and expression should both be copied to the // sandboxed context. -let code = 'var a = function() {};\n'; +let code = 'let a = function() {};\n'; code += 'function b(){}\n'; +code += 'var c = function() {};\n'; // Grab the global b function as the completion value, to ensure that // we are getting the global function, and not some other thing code += '(function(){return this})().b;\n'; const res = vm.runInContext(code, o, 'test'); - assert.strictEqual(typeof res, 'function'); assert.strictEqual(res.name, 'b'); assert.strictEqual(typeof o.a, 'function'); assert.strictEqual(typeof o.b, 'function'); +assert.strictEqual(typeof o.c, 'function'); + assert.strictEqual(res, o.b); From b05c0e694eab23a8b1e7af94aac667c26347a3bd Mon Sep 17 00:00:00 2001 From: Duncan Healy Date: Tue, 12 Nov 2019 19:20:22 +0000 Subject: [PATCH 2/2] test: add function declaration tests for fat arrow --- test/parallel/test-vm-function-declaration.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/test/parallel/test-vm-function-declaration.js b/test/parallel/test-vm-function-declaration.js index 23552e503dd985..766e5ec78b10ea 100644 --- a/test/parallel/test-vm-function-declaration.js +++ b/test/parallel/test-vm-function-declaration.js @@ -31,6 +31,8 @@ const o = vm.createContext({ console }); let code = 'let a = function() {};\n'; code += 'function b(){}\n'; code += 'var c = function() {};\n'; +code += 'var d = () => {};\n'; +code += 'let e = () => {};\n'; // Grab the global b function as the completion value, to ensure that // we are getting the global function, and not some other thing @@ -39,8 +41,9 @@ code += '(function(){return this})().b;\n'; const res = vm.runInContext(code, o, 'test'); assert.strictEqual(typeof res, 'function'); assert.strictEqual(res.name, 'b'); -assert.strictEqual(typeof o.a, 'function'); +assert.strictEqual(typeof o.a, 'undefined'); assert.strictEqual(typeof o.b, 'function'); assert.strictEqual(typeof o.c, 'function'); - +assert.strictEqual(typeof o.d, 'function'); +assert.strictEqual(typeof o.e, 'undefined'); assert.strictEqual(res, o.b);