New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: add vm module edge cases #11265

Closed
wants to merge 1 commit into
from

Conversation

Projects
None yet
5 participants
@fhinkel
Member

fhinkel commented Feb 9, 2017

This PR adds two, admittedly contrived, examples that test edge cases of the vm module.

They demonstrate that the if statements if (maybe_rv.IsEmpty()) and
if (maybe_prop_attr.IsNothing()) in the GetterCallback
and the QueryCallback in src/node_contextify.cc
are observable. So far we have no tests that break when these
statements are removed (neither does Jest).

Both GetterCallback and QueryCallback
explicitly check the global_proxy() if a property is
not found on the sandbox. In these tests, the explicit check
inside the callback yields different results than deferring the
check until after the callback. The check is deferred, if the
callbacks do not intercept, i.e., if args.GetReturnValue().Set() is
not called.

Since we're working on fixing several of the vm issues, I'd like to have these
tests so we're at least aware if we cause any breaking changes.

Checklist
  • make -j4 test (UNIX), or vcbuild test (Windows) passes
  • tests and/or benchmarks are included
  • commit message follows commit guidelines
Affected core subsystem(s)

test

@fhinkel fhinkel added the vm label Feb 9, 2017

Show outdated Hide outdated test/parallel/test-vm-property-not-on-sandbox.js
let sandbox = {console};
sandbox.document = { defaultView: sandbox };
vm.createContext(sandbox);
const code1 = 'Object.defineProperty(' +

This comment has been minimized.

@cjihrig

cjihrig Feb 9, 2017

Contributor

We've been moving toward using block scopes in tests to avoid things like code1, code2, etc.

@cjihrig

cjihrig Feb 9, 2017

Contributor

We've been moving toward using block scopes in tests to avoid things like code1, code2, etc.

This comment has been minimized.

@fhinkel

fhinkel Feb 9, 2017

Member

The joy of let and const 👍 . Fixed.

@fhinkel

fhinkel Feb 9, 2017

Member

The joy of let and const 👍 . Fixed.

@cjihrig

cjihrig approved these changes Feb 9, 2017

@jasnell

jasnell approved these changes Feb 9, 2017

@bnoordhuis

LGTM with style suggestions and if you can clarify the desc.value thing.

Show outdated Hide outdated test/parallel/test-vm-property-not-on-sandbox.js
// explicitly check the global_proxy() if a property is
// not found on the sandbox. In the following tests, the explicit check
// inside the callback yields different results than deferring the
// check until after the callback. The check is deferred, if the

This comment has been minimized.

@bnoordhuis

bnoordhuis Feb 10, 2017

Member

Treacherous comma? It reads as if the "if the callbacks do not intercept" part is its own sentence.

@bnoordhuis

bnoordhuis Feb 10, 2017

Member

Treacherous comma? It reads as if the "if the callbacks do not intercept" part is its own sentence.

This comment has been minimized.

@fhinkel

fhinkel Feb 10, 2017

Member

Comma deleted.

@fhinkel

fhinkel Feb 10, 2017

Member

Comma deleted.

// the global_proxy to keep the correct identities.
//
// This test case is partially inspired by
// https://github.com/nodejs/node/issues/855

This comment has been minimized.

@bnoordhuis

bnoordhuis Feb 10, 2017

Member

I'd either indent the comment or put the brace after the comment.

@bnoordhuis

bnoordhuis Feb 10, 2017

Member

I'd either indent the comment or put the brace after the comment.

This comment has been minimized.

@fhinkel

fhinkel Feb 10, 2017

Member

Not in block-scope anymore because split over different files.

@fhinkel

fhinkel Feb 10, 2017

Member

Not in block-scope anymore because split over different files.

Show outdated Hide outdated test/parallel/test-vm-property-not-on-sandbox.js
' "foo", ' +
' { get: function() {return document.defaultView} }' +
');' +
'var result = foo === this;';

This comment has been minimized.

@bnoordhuis

bnoordhuis Feb 10, 2017

Member

You can use a backticks string if you want, probably easier to read.

@bnoordhuis

bnoordhuis Feb 10, 2017

Member

You can use a backticks string if you want, probably easier to read.

This comment has been minimized.

@fhinkel

fhinkel Feb 10, 2017

Member

Done.

@fhinkel

fhinkel Feb 10, 2017

Member

Done.

Show outdated Hide outdated test/parallel/test-vm-property-not-on-sandbox.js
' { get: function() {return 17} }' +
');' +
'var desc = Object.getOwnPropertyDescriptor(this, "foo");' +
'var result = typeof desc.value === "number";';

This comment has been minimized.

@bnoordhuis

bnoordhuis Feb 10, 2017

Member

I don't follow why this would be the expected result instead of typeof desc.value === 'undefined' (and typeof desc.get === 'function'.) Is this a test that better belongs in test/known_issues?

@bnoordhuis

bnoordhuis Feb 10, 2017

Member

I don't follow why this would be the expected result instead of typeof desc.value === 'undefined' (and typeof desc.get === 'function'.) Is this a test that better belongs in test/known_issues?

This comment has been minimized.

@fhinkel

fhinkel Feb 10, 2017

Member

Expected because it is the current behavior - not necessarily correct behavior. I wanted to make sure we have a test that breaks if somebody touches these 5 lines of code. But I'm getting more and more convinced, that these lines shouldn't be there. Moving this to known issues.

@fhinkel

fhinkel Feb 10, 2017

Member

Expected because it is the current behavior - not necessarily correct behavior. I wanted to make sure we have a test that breaks if somebody touches these 5 lines of code. But I'm getting more and more convinced, that these lines shouldn't be there. Moving this to known issues.

test: add vm module edge cases
Add two, admittedly contrived, examples that test
edge cases of the vm module.
They demonstrate that the if statements `if (maybe_rv.IsEmpty())` and
`if (maybe_prop_attr.IsNothing())` in the GetterCallback
and the QueryCallback are observable.

Both GetterCallback and QueryCallback
explicitly check the global_proxy() if a property is
not found on the sandbox. In these tests, the explicit check
inside the callback yields different results than deferring the
check until after the callback. The check is deferred, if the
callbacks do not intercept, i.e., if args.GetReturnValue().Set() is
not called.

jasnell added a commit that referenced this pull request Feb 11, 2017

test: add vm module edge cases
Add two, admittedly contrived, examples that test
edge cases of the vm module.
They demonstrate that the if statements `if (maybe_rv.IsEmpty())` and
`if (maybe_prop_attr.IsNothing())` in the GetterCallback
and the QueryCallback are observable.

Both GetterCallback and QueryCallback
explicitly check the global_proxy() if a property is
not found on the sandbox. In these tests, the explicit check
inside the callback yields different results than deferring the
check until after the callback. The check is deferred, if the
callbacks do not intercept, i.e., if args.GetReturnValue().Set() is
not called.

PR-URL: #11265
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
@jasnell

This comment has been minimized.

Show comment
Hide comment
@jasnell

jasnell Feb 11, 2017

Member

Landed in 5cd9d76

Member

jasnell commented Feb 11, 2017

Landed in 5cd9d76

@jasnell jasnell closed this Feb 11, 2017

italoacasas added a commit that referenced this pull request Feb 13, 2017

test: add vm module edge cases
Add two, admittedly contrived, examples that test
edge cases of the vm module.
They demonstrate that the if statements `if (maybe_rv.IsEmpty())` and
`if (maybe_prop_attr.IsNothing())` in the GetterCallback
and the QueryCallback are observable.

Both GetterCallback and QueryCallback
explicitly check the global_proxy() if a property is
not found on the sandbox. In these tests, the explicit check
inside the callback yields different results than deferring the
check until after the callback. The check is deferred, if the
callbacks do not intercept, i.e., if args.GetReturnValue().Set() is
not called.

PR-URL: #11265
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>

italoacasas added a commit to italoacasas/node that referenced this pull request Feb 14, 2017

test: add vm module edge cases
Add two, admittedly contrived, examples that test
edge cases of the vm module.
They demonstrate that the if statements `if (maybe_rv.IsEmpty())` and
`if (maybe_prop_attr.IsNothing())` in the GetterCallback
and the QueryCallback are observable.

Both GetterCallback and QueryCallback
explicitly check the global_proxy() if a property is
not found on the sandbox. In these tests, the explicit check
inside the callback yields different results than deferring the
check until after the callback. The check is deferred, if the
callbacks do not intercept, i.e., if args.GetReturnValue().Set() is
not called.

PR-URL: nodejs#11265
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>

KryDos added a commit to KryDos/node that referenced this pull request Feb 25, 2017

test: add vm module edge cases
Add two, admittedly contrived, examples that test
edge cases of the vm module.
They demonstrate that the if statements `if (maybe_rv.IsEmpty())` and
`if (maybe_prop_attr.IsNothing())` in the GetterCallback
and the QueryCallback are observable.

Both GetterCallback and QueryCallback
explicitly check the global_proxy() if a property is
not found on the sandbox. In these tests, the explicit check
inside the callback yields different results than deferring the
check until after the callback. The check is deferred, if the
callbacks do not intercept, i.e., if args.GetReturnValue().Set() is
not called.

PR-URL: nodejs#11265
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>

jasnell added a commit that referenced this pull request Mar 7, 2017

test: add vm module edge cases
Add two, admittedly contrived, examples that test
edge cases of the vm module.
They demonstrate that the if statements `if (maybe_rv.IsEmpty())` and
`if (maybe_prop_attr.IsNothing())` in the GetterCallback
and the QueryCallback are observable.

Both GetterCallback and QueryCallback
explicitly check the global_proxy() if a property is
not found on the sandbox. In these tests, the explicit check
inside the callback yields different results than deferring the
check until after the callback. The check is deferred, if the
callbacks do not intercept, i.e., if args.GetReturnValue().Set() is
not called.

PR-URL: #11265
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>

jasnell added a commit that referenced this pull request Mar 7, 2017

test: add vm module edge cases
Add two, admittedly contrived, examples that test
edge cases of the vm module.
They demonstrate that the if statements `if (maybe_rv.IsEmpty())` and
`if (maybe_prop_attr.IsNothing())` in the GetterCallback
and the QueryCallback are observable.

Both GetterCallback and QueryCallback
explicitly check the global_proxy() if a property is
not found on the sandbox. In these tests, the explicit check
inside the callback yields different results than deferring the
check until after the callback. The check is deferred, if the
callbacks do not intercept, i.e., if args.GetReturnValue().Set() is
not called.

PR-URL: #11265
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>

MylesBorins added a commit that referenced this pull request Mar 9, 2017

test: add vm module edge cases
Add two, admittedly contrived, examples that test
edge cases of the vm module.
They demonstrate that the if statements `if (maybe_rv.IsEmpty())` and
`if (maybe_prop_attr.IsNothing())` in the GetterCallback
and the QueryCallback are observable.

Both GetterCallback and QueryCallback
explicitly check the global_proxy() if a property is
not found on the sandbox. In these tests, the explicit check
inside the callback yields different results than deferring the
check until after the callback. The check is deferred, if the
callbacks do not intercept, i.e., if args.GetReturnValue().Set() is
not called.

PR-URL: #11265
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>

@MylesBorins MylesBorins referenced this pull request Mar 9, 2017

Merged

v6.10.1 proposal #11759

MylesBorins added a commit that referenced this pull request Mar 9, 2017

test: add vm module edge cases
Add two, admittedly contrived, examples that test
edge cases of the vm module.
They demonstrate that the if statements `if (maybe_rv.IsEmpty())` and
`if (maybe_prop_attr.IsNothing())` in the GetterCallback
and the QueryCallback are observable.

Both GetterCallback and QueryCallback
explicitly check the global_proxy() if a property is
not found on the sandbox. In these tests, the explicit check
inside the callback yields different results than deferring the
check until after the callback. The check is deferred, if the
callbacks do not intercept, i.e., if args.GetReturnValue().Set() is
not called.

PR-URL: #11265
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>

@MylesBorins MylesBorins referenced this pull request Mar 9, 2017

Merged

v4.8.1 proposal #11760

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment