forked from svaarala/duktape
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Testcase to demonstrate Proxy preincr behavior
- Loading branch information
Showing
1 changed file
with
37 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
/* | ||
* Preincrement applied to a Proxy (GH-309). | ||
*/ | ||
|
||
/*=== | ||
get | ||
set | ||
4500.5 | ||
get | ||
9001 | ||
===*/ | ||
|
||
function test() { | ||
p = new Proxy({ val: 4499.5 }, { | ||
get: function(t, prop) { print('get'); return t[prop]; }, | ||
set: function(t, prop, value) { print('set'); t[prop] = value * 2; } | ||
}); | ||
|
||
// Preincrement is evaluated as: | ||
// (1) read p.val -> 4499.5 | ||
// (2) increment 4499.5 -> 4500.5 (this becomes the expression value) | ||
// (3) write 4500.5 to p.val -> 'set' trap writes 9001 to target | ||
// | ||
// In this case the result may not be intuitive as one might | ||
// expect 9001 as a result (i.e. step 4: read p.val back). | ||
// The required behavior is described in: | ||
// http://www.ecma-international.org/ecma-262/6.0/index.html#sec-prefix-increment-operator | ||
|
||
print(++p.val); // 4500.5 (from step 2) | ||
print(p.val); // 9001 | ||
} | ||
|
||
try { | ||
test(); | ||
} catch (e) { | ||
print(e.stack || e); | ||
} |