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

Safari: Error#column is read only #1290

Closed
ariya opened this issue Aug 19, 2015 · 8 comments
Closed

Safari: Error#column is read only #1290

ariya opened this issue Aug 19, 2015 · 8 comments
Labels
Milestone

Comments

@ariya
Copy link
Contributor

ariya commented Aug 19, 2015

This is related to #1284. See also: https://bugs.webkit.org/show_bug.cgi?id=146047

Some unit tests (that check for invalid syntax) fail on Safari. This is because column property of an Error object is read only.

Run this on Safari (or check this snippet: http://jsbin.com/pexocaruce/edit?js,console):

function createError(msg) {
  var error = new Error(msg);
  error.column = 42;
  console.log('error.column', error.column);
 return error;
}

function throwError(msg) {
  throw createError(msg);
}

try {
  throwError('Hello Universe');
} catch (e) {
  console.log('e.column', e.column);
}

It should say that column is 25, despite the fact that its value is set to 42. Chrome and Firefox behave as expected, showing 42.

@ariya
Copy link
Contributor Author

ariya commented Aug 19, 2015

With this situation, any Error object that Esprima is throwing is going to have a wrong value for column on Safari >= 8. While we need a long term solution for this, for now we need to workaround it by having the test suite excludes column when comparing expected vs actual, if this situation is detected.

@ariya ariya added the defect label Aug 19, 2015
@gibson042
Copy link
Member

Why not use the Object.create + Object.defineProperty solution from #1284 (comment) in strict-mode Safari so the property is correct there too?

@ariya
Copy link
Contributor Author

ariya commented Aug 19, 2015

@gibson042 Because that doesn't change the value of column property. In other word, the result for the above example is still 25, not the expected 42.

@michaelficarra
Copy link
Contributor

@ariya It should because you're adding an own-property to the freshly created object that has the Error object as its prototype. The problem with leaving it this way for now is that, in strict mode, the write throws an error instead of just silently failing. I think the best thing to do for now would be either use Object.defineProperty on an object that has the error as its prototype as @gibson042 suggests or testing whether it is writable using Object.getOwnPropertyDescriptor. If we can't depend on ES5+ stdlib functions, we'll just have to wrap the assignment with a try-catch.

@gibson042
Copy link
Member

@ariya http://jsbin.com/zihasukaku/edit?js,console

function createError(msg) {
  var error = Object.create(new Error(msg));
  Object.defineProperty(error, 'column', { value: 42 });
  return error;
}

@ariya
Copy link
Contributor Author

ariya commented Aug 19, 2015

@gibson042 With Safari 8, your JSBin snippet produces:

"e.column"
33

With Chrome and Firefox, the output is

"e.column"
"Corinthian"

@gibson042
Copy link
Member

Ah, I didn't see the problem introduced by throwing the error in Safari 8 (Safari 9 was fine). But it too can be resolved: http://jsbin.com/tecusujowu/edit?js,console

And note that even though the above works on other browsers, it is only needed for Safari.

@ariya
Copy link
Contributor Author

ariya commented Aug 19, 2015

The problem with leaving it this way for now is that, in strict mode, the write throws an error instead of just silently failing.

That's the difference between Safari 8 and 9:

  • Safari 8: no TypeError is thrown, but column has the wrong value
  • Safari 9: "TypeError: Attempted to assign to readonly property."

ariya added a commit to ariya/esprima that referenced this issue Aug 20, 2015
@ariya ariya closed this as completed in 807fc45 Aug 22, 2015
@ariya ariya added this to the 2.6 milestone Aug 26, 2015
kpdecker added a commit to handlebars-lang/handlebars.js that referenced this issue Dec 12, 2015
lawnsea pushed a commit to lawnsea/handlebars.js that referenced this issue Nov 9, 2016
lawnsea pushed a commit to handlebars-lang/handlebars.js that referenced this issue Nov 11, 2016
nknapp pushed a commit to handlebars-lang/handlebars.js that referenced this issue Mar 9, 2017
nknapp added a commit to handlebars-lang/handlebars.js that referenced this issue Jan 1, 2019
- bump to mocha 1.21.5 in order to remove "*" version-range on the
  "debug"-dependency
- explicit use of "dot"-reporter for mocha 1.21.5, fixes failing tests
  of console.log output
- fix tests running in the browser: assign variable "global" with
  global "this", backport from master-branch
- update saucelab config:
  - Remove Safari 6 and 7 that are not supported by saucelabs anymore
    and cause timeouts when running the saucelabs tests.
  - Add Safari 8
  - Note: The tests fail with Safari 9 and 10 because in these versions
    the "column"-property of "Error" is read-only
    (see jquery/esprima#1290)
  - firefox needs explicit platform and version specifier
nknapp added a commit to handlebars-lang/handlebars.js that referenced this issue Jan 1, 2019
- bump to mocha 1.21.5 in order to remove "*" version-range on the
  "debug"-dependency
- explicit use of "dot"-reporter for mocha 1.21.5, fixes failing tests
  of console.log output
- fix tests running in the browser: assign variable "global" with
  global "this", backport from master-branch
- sync saucelab config with master branch:
  - Remove Safari 6 and 7 that are not supported by saucelabs anymore
    and cause timeouts when running the saucelabs tests.
  - Add Safari 8 and Safari 9
  - Note: The tests fail with Safari 9 and 10 because in these versions
    the "column"-property of "Error" is read-only
    (see jquery/esprima#1290)
  - Firefox needs explicit platform specifier
nknapp added a commit to handlebars-lang/handlebars.js that referenced this issue Jan 1, 2019
- bump to mocha 1.21.5 in order to remove "*" version-range on the
  "debug"-dependency
- explicit use of "dot"-reporter for mocha 1.21.5, fixes failing tests
  of console.log output
- fix tests running in the browser: assign variable "global" with
  global "this", backport from master-branch
- sync saucelab config with master branch:
  - Remove Safari 6 and 7 that are not supported by saucelabs anymore
    and cause timeouts when running the saucelabs tests.
  - Add Safari 8 and Safari 9
  - Note: The tests fail with Safari 9 and 10 because in these versions
    the "column"-property of "Error" is read-only
    (see jquery/esprima#1290)
  - Firefox needs explicit platform specifier
nknapp added a commit to handlebars-lang/handlebars.js that referenced this issue Jan 2, 2019
- bump to mocha 1.21.5 in order to remove "*" version-range on the
  "debug"-dependency
- explicit use of "dot"-reporter for mocha 1.21.5, fixes failing tests
  of console.log output
- fix tests running in the browser: assign variable "global" with
  global "this", backport from master-branch
- sync saucelab config with master branch:
  - Remove Safari 6 and 7 that are not supported by saucelabs anymore
    and cause timeouts when running the saucelabs tests.
  - Add Safari 8 and Safari 9
  - Note: The tests fail with Safari 9 and 10 because in these versions
    the "column"-property of "Error" is read-only
    (see jquery/esprima#1290)
  - Firefox needs explicit platform specifier
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

No branches or pull requests

3 participants