NeilFraser / JS-Interpreter

A sandboxed JavaScript interpreter in JavaScript.
Apache License 2.0
2k stars 353 forks source link

Remove unneeded error class #169

Closed NeilFraser closed 4 years ago

NeilFraser commented 4 years ago

Chris, can you think of any reason why the 'Error' .class is needed in JS-Interpreter? We use .class for Array and Function, since one can build children of each that are not real arrays or functions. But I don't see the point of 'Error'.

cpcallen commented 4 years ago

For posterity, and from our conversation: the only purpose of the Error value for the [[Class]] attribute in ES5.1 (and the corresponding [[ErrorData]] internal slot in ES6 and onwards) is to allow Object.prototype.toString to distinguish Error objects so that Object.prototype.toString.apply(new Error) will return "[object Error]" rather than "[object Object]"—a distinction which is not relevant to JS Interpreter because it does not separate the implementation of Error.prototype.toString from Object.prototype.toString. (This is arguably a bug.)

From the spec:

The only specified uses of [[ErrorData]] is to identify Error and NativeError instances as Error objects within Object.prototype.toString.

NeilFraser commented 4 years ago

Reverted. See issue #177.