Skip to content
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

Fix issue for running under node-webkit. #258

Closed
wants to merge 1 commit into from
Closed

Fix issue for running under node-webkit. #258

wants to merge 1 commit into from

Conversation

tavwizard
Copy link

Under node-webkit we have both contexts 'window' and 'global'.
'window' is default context then we should check for window first.

Under node-webkit we have both contexts 'window' and 'global'.
'window' is default context then we should check for window first.
@ljharb
Copy link
Collaborator

ljharb commented Jun 10, 2014

This was changed from window to self for web workers in 4e4dc69.

We may need all three.

Also, please include a test that fails without your change, or, indicate in the PR which tests failed.

@tavwizard
Copy link
Author

I think we can use self.
I don't know exactly how to test it in mocha.

Under node-webkit we have global and window context. Scripts running under window.
Result: es6-shim will patch global instead of window.

@ljharb
Copy link
Collaborator

ljharb commented Jun 10, 2014

@david-risney, can you weigh in on your change in 4e4dc69 versus this PR?

@david-risney
Copy link
Contributor

I changed window to self for web workers as you note because in the browser window window.self === window and in the browser worker the global object is named self. So self works for both browser window and browser worker. Neither global nor window exist in a browser worker so changing this back to window will break workers again.

@ljharb
Copy link
Collaborator

ljharb commented Jun 10, 2014

In other words, we may need a more reliable way to get to the global object than just checking for "global", "self", or "window". Thanks for confirming!

@david-risney
Copy link
Contributor

A common pattern I see elsewhere obtains the global object generically like in es5 via checking this in the global context:

function(global) {
    // ... Everything goes here
})(this);

Afaik this is a feature of JavaScript regardless of use strict or the execution environment (browser, worker, node etc)

@ljharb
Copy link
Collaborator

ljharb commented Jun 11, 2014

In strict mode, "this" when not assigned is undefined, and does not refer to the global object.

@david-risney
Copy link
Contributor

IIRC that's true generally but not for global code. In global code this is still the global object. http://stackoverflow.com/a/6483866

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants