mirror of https://github.com/svaarala/duktape.git
Browse Source
- One polyfill to ensure Duktape 1.3.0 behavior - One polyfill to ensure Duktape 1.4.0 behavior If the write behavior change is an issue, you can use the first polyfill to bring back Duktape 1.3.0 behavior.pull/390/head
Sami Vaarala
9 years ago
3 changed files with 41 additions and 0 deletions
@ -0,0 +1,20 @@ |
|||
/* |
|||
* Ensure Error .fileName, .lineNumber, and .stack are not directly writable, |
|||
* but can be written using Object.defineProperty(). This matches Duktape |
|||
* 1.3.0 and prior. |
|||
* |
|||
* See: https://github.com/svaarala/duktape/pull/390.
|
|||
*/ |
|||
|
|||
(function () { |
|||
var err = new Error('test'); |
|||
err.fileName = 999; |
|||
if (err.fileName !== 999) { return; } // already non-writable
|
|||
|
|||
var fn = new Function(''); // nop
|
|||
Object.defineProperties(Error.prototype, { |
|||
fileName: { set: fn }, |
|||
lineNumber: { set: fn }, |
|||
stack: { set: fn } |
|||
}); |
|||
})(); |
@ -0,0 +1,19 @@ |
|||
/* |
|||
* Ensure Error .fileName, .lineNumber, and .stack are directly writable |
|||
* without having to use Object.defineProperty(). This matches Duktape |
|||
* 1.4.0 behavior. |
|||
* |
|||
* See: https://github.com/svaarala/duktape/pull/390.
|
|||
*/ |
|||
|
|||
(function () { |
|||
var err = new Error('test'); |
|||
err.fileName = 999; |
|||
if (err.fileName === 999) { return; } // already writable
|
|||
|
|||
Object.defineProperties(Error.prototype, { |
|||
fileName: { set: new Function('v', 'Object.defineProperty(this, "fileName", { value: v, writable: true, enumerable: false, configurable: true });') }, |
|||
lineNumber: { set: new Function('v', 'Object.defineProperty(this, "lineNumber", { value: v, writable: true, enumerable: false, configurable: true });') }, |
|||
stack: { set: new Function('v', 'Object.defineProperty(this, "stack", { value: v, writable: true, enumerable: false, configurable: true });') }, |
|||
}); |
|||
})(); |
Loading…
Reference in new issue