Skip to content

Commit 2f88de1

Browse files
AnnaMagitaloacasas
authored andcommitted
vm: use SetterCallback to set func declarations
Currently, when in strict mode, function declarations are copied on the sandbox by CopyProperties(), which is not necessary and will break when CP is removed. This change maintains current behavior, letting GlobalPropertySetterCallback copy functions on the sandbox instead of using CP to do the task. PR-URL: #12051 Reviewed-By: Franziska Hinkelmann <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Ben Noordhuis <[email protected]> Reviewed-By: Anna Henningsen <[email protected]>
1 parent ffbcfdf commit 2f88de1

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

src/node_contextify.cc

+11-1
Original file line numberDiff line numberDiff line change
@@ -411,7 +411,17 @@ class ContextifyContext {
411411
// false for vmResult.x = 5 where vmResult = vm.runInContext();
412412
bool is_contextual_store = ctx->global_proxy() != args.This();
413413

414-
if (!is_declared && args.ShouldThrowOnError() && is_contextual_store)
414+
// Indicator to not return before setting (undeclared) function declarations
415+
// on the sandbox in strict mode, i.e. args.ShouldThrowOnError() = true.
416+
// True for 'function f() {}', 'this.f = function() {}',
417+
// 'var f = function()'.
418+
// In effect only for 'function f() {}' because
419+
// var f = function(), is_declared = true
420+
// this.f = function() {}, is_contextual_store = false.
421+
bool is_function = value->IsFunction();
422+
423+
if (!is_declared && args.ShouldThrowOnError() && is_contextual_store &&
424+
!is_function)
415425
return;
416426

417427
ctx->sandbox()->Set(property, value);

0 commit comments

Comments
 (0)