| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent fa939f0 commit 5856c83
2 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -346,14 +346,21 @@ class ContextifyContext { | |||
| 346 | 346 | return; | |
| 347 | 347 | ||
| 348 | 348 | auto attributes = PropertyAttribute::None; | |
| 349 | - bool is_declared = ctx->global_proxy() | ||
| 349 | + bool is_declared_on_global_proxy = ctx->global_proxy() | ||
| 350 | 350 | ->GetRealNamedPropertyAttributes(ctx->context(), property) | |
| 351 | 351 | .To(&attributes); | |
| 352 | 352 | bool read_only = | |
| 353 | 353 | static_cast<int>(attributes) & | |
| 354 | 354 | static_cast<int>(PropertyAttribute::ReadOnly); | |
| 355 | 355 | ||
| 356 | - if (is_declared && read_only) | ||
| 356 | + bool is_declared_on_sandbox = ctx->sandbox() | ||
| 357 | + ->GetRealNamedPropertyAttributes(ctx->context(), property) | ||
| 358 | + .To(&attributes); | ||
| 359 | + read_only = read_only || | ||
| 360 | + (static_cast<int>(attributes) & | ||
| 361 | + static_cast<int>(PropertyAttribute::ReadOnly)); | ||
| 362 | + | ||
| 363 | + if (read_only) | ||
| 357 | 364 | return; | |
| 358 | 365 | ||
| 359 | 366 | // true for x = 5 | |
@@ -371,10 +378,20 @@ class ContextifyContext { | |||
| 371 | 378 | // this.f = function() {}, is_contextual_store = false. | |
| 372 | 379 | bool is_function = value->IsFunction(); | |
| 373 | 380 | ||
| 381 | + bool is_declared = is_declared_on_global_proxy || is_declared_on_sandbox; | ||
| 374 | 382 | if (!is_declared && args.ShouldThrowOnError() && is_contextual_store && | |
| 375 | 383 | !is_function) | |
| 376 | 384 | return; | |
| 377 | 385 | ||
| 386 | + if (!is_declared_on_global_proxy && is_declared_on_sandbox && | ||
| 387 | + args.ShouldThrowOnError() && is_contextual_store && !is_function) { | ||
| 388 | + // The property exists on the sandbox but not on the global | ||
| 389 | + // proxy. Setting it would throw because we are in strict mode. | ||
| 390 | + // Don't attempt to set it by signaling that the call was | ||
| 391 | + // intercepted. Only change the value on the sandbox. | ||
| 392 | + args.GetReturnValue().Set(false); | ||
| 393 | + } | ||
| 394 | + | ||
| 378 | 395 | ctx->sandbox()->Set(property, value); | |
| 379 | 396 | } | |
| 380 | 397 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -7,11 +7,8 @@ const vm = require('vm'); | |||
| 7 | 7 | ||
| 8 | 8 | const ctx = vm.createContext({ x: 42 }); | |
| 9 | 9 | ||
| 10 | - // The following line wrongly throws an | ||
| 11 | - // error because GlobalPropertySetterCallback() | ||
| 12 | - // does not check if the property exists | ||
| 13 | - // on the sandbox. It should just set x to 1 | ||
| 14 | - // instead of throwing an error. | ||
| 10 | + // This might look as if x has not been declared, but x is defined on the | ||
| 11 | + // sandbox and the assignment should not throw. | ||
| 15 | 12 | vm.runInContext('"use strict"; x = 1', ctx); | |
| 16 | 13 | ||
| 17 | 14 | assert.strictEqual(ctx.x, 1); | |
| Back | FazBrowse Home | New Git URL |
0 commit comments