Skip to content

Commit 0836402

Browse files
committed
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.
1 parent d13bd4a commit 0836402

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

src/node_contextify.cc

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -432,7 +432,17 @@ class ContextifyContext {
432432
// false for vmResult.x = 5 where vmResult = vm.runInContext();
433433
bool is_contextual_store = ctx->global_proxy() != args.This();
434434

435-
if (!is_declared && args.ShouldThrowOnError() && is_contextual_store)
435+
// Indicator to not return before setting (undeclared) function declarations
436+
// on the sandbox in strict mode, i.e. args.ShouldThrowOnError() = true.
437+
// True for 'function f() {}', 'this.f = function() {}',
438+
// 'var f = function()'.
439+
// In effect only for 'function f() {}' because
440+
// var f = function(), is_declared = true
441+
// this.f = function() {}, is_contextual_store = false.
442+
bool is_function = value->IsFunction();
443+
444+
if (!is_declared && args.ShouldThrowOnError() && is_contextual_store &&
445+
!is_function)
436446
return;
437447

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

0 commit comments

Comments
 (0)