forked from olov/jsshaper
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
327 additions
and
27 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 @@ | ||
"use strict"; "use restrict"; | ||
|
||
var require = require || function(f) { load(f); }; | ||
var Watch = Watch || require("./plugins/watcher/watch.js") || Watch; | ||
var Log = Log || require("./log.js") || Log; | ||
|
||
// watch o for invalid age [1] | ||
var o = {name: "marvin", age: 100000}; | ||
Watch(o, "age", function() { | ||
if (o.age < 0) { | ||
Log.verb("plugins/watcher/tests/pre-example.js", 11, "<anonymous>", "invalid age ({0})", o.age); | ||
} | ||
}); | ||
|
||
// watch arr for non-string assignments [2] | ||
var arr = ["asdf", "zxcv"]; | ||
Watch(arr, null, function(arr, name, op) { | ||
var v = arr[name]; | ||
if (typeof v !== "string") { | ||
Log.verb("plugins/watcher/tests/pre-example.js", 20, "<anonymous>", "arr[{0}] assigned with {1} of type {2}", name, v, typeof v); | ||
} | ||
}); | ||
|
||
// watch Array.prototype for patches [3] | ||
Watch(Array.prototype, null, function(obj, name, op) { | ||
Log.verb("plugins/watcher/tests/pre-example.js", 26, "<anonymous>", "patched Array.prototype.{0}", name); | ||
}); | ||
|
||
// modify push so that pushes are watched, too. triggers [3] | ||
Watch.set("=", Array.prototype, "push", function(v) { | ||
return Watch.set("=", this, String(this.length), v); | ||
}); | ||
|
||
Watch.set("+=", o, "age", 1); | ||
Watch.set("/=", o, "age", -1); // triggers [1] | ||
Watch.set("=", arr, String(2), "ok"); | ||
arr.push(0); // triggers [2] |
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 @@ | ||
"use strict"; "use restrict"; | ||
|
||
var require = require || function(f) { load(f); }; | ||
var Watch = Watch || require("./plugins/watcher/watch.js") || Watch; | ||
var Log = Log || require("./log.js") || Log; | ||
|
||
// watch o for invalid age [1] | ||
var o = {name: "marvin", age: 100000}; | ||
Watch(o, "age", function() { | ||
if (o.age < 0) { | ||
Log("invalid age ({0})", o.age); | ||
} | ||
}); | ||
|
||
// watch arr for non-string assignments [2] | ||
var arr = ["asdf", "zxcv"]; | ||
Watch(arr, null, function(arr, name, op) { | ||
var v = arr[name]; | ||
if (typeof v !== "string") { | ||
Log("arr[{0}] assigned with {1} of type {2}", name, v, typeof v); | ||
} | ||
}); | ||
|
||
// watch Array.prototype for patches [3] | ||
Watch(Array.prototype, null, function(obj, name, op) { | ||
Log("patched Array.prototype.{0}", name); | ||
}); | ||
|
||
// modify push so that pushes are watched, too. triggers [3] | ||
Array.prototype.push = function(v) { | ||
return this[this.length] = v; | ||
}; | ||
|
||
o.age += 1; | ||
o["age"] /= -1; // triggers [1] | ||
arr[2] = "ok"; | ||
arr.push(0); // triggers [2] |
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,122 @@ | ||
"use strict"; "use restrict"; | ||
|
||
var require = require || function(f) { load(f); }; | ||
var Assert = Assert || require("./assert.js") || Assert; | ||
var Watch = Watch || require("./plugins/watcher/watch.js") || Watch; | ||
var v = 123; | ||
var o = {id: v}; | ||
var strid = "id"; | ||
|
||
// o.id | ||
Watch.set("++v", o, "id"); | ||
Watch.set("v++", o, "id"); | ||
Watch.set("--v", o, "id"); | ||
Watch.set("v--", o, "id"); | ||
Watch.set("=", o, "id", null || v); | ||
Watch.set("+=", o, "id", null || v); | ||
Watch.set("-=", o, "id", null || v); | ||
Watch.set("*=", o, "id", null || v); | ||
Watch.set("/=", o, "id", null || v); | ||
Watch.set("%=", o, "id", null || 2); | ||
Watch.set("&=", o, "id", null || v); | ||
Watch.set("|=", o, "id", null || v); | ||
Watch.set("^=", o, "id", null || -1); | ||
Watch.set("<<=", o, "id", null || v); | ||
Watch.set(">>=", o, "id", null || v); | ||
Watch.set(">>>=", o, "id", null || 2); | ||
Assert(o.id === 1, "o.id === 1, function <script>, file plugins/watcher/tests/pre-forms.js, line 27"); | ||
|
||
// expr.id | ||
Watch.set("++v", (null || o), "id"); | ||
Watch.set("v++", (null || o), "id"); | ||
Watch.set("--v", (null || o), "id"); | ||
Watch.set("v--", (null || o), "id"); | ||
Watch.set("=", (null || o), "id", null || v); | ||
Watch.set("+=", (null || o), "id", null || v); | ||
Watch.set("-=", (null || o), "id", null || v); | ||
Watch.set("*=", (null || o), "id", null || v); | ||
Watch.set("/=", (null || o), "id", null || v); | ||
Watch.set("%=", (null || o), "id", null || 2); | ||
Watch.set("&=", (null || o), "id", null || v); | ||
Watch.set("|=", (null || o), "id", null || v); | ||
Watch.set("^=", (null || o), "id", null || -1); | ||
Watch.set("<<=", (null || o), "id", null || v); | ||
Watch.set(">>=", (null || o), "id", null || v); | ||
Watch.set(">>>=", (null || o), "id", null || 2); | ||
Assert(o.id === 1, "o.id === 1, function <script>, file plugins/watcher/tests/pre-forms.js, line 46"); | ||
|
||
// o["str"] | ||
Watch.set("++v", o, "id"); | ||
Watch.set("v++", o, "id"); | ||
Watch.set("--v", o, "id"); | ||
Watch.set("v--", o, "id"); | ||
Watch.set("=", o, "id", null || v); | ||
Watch.set("+=", o, "id", null || v); | ||
Watch.set("-=", o, "id", null || v); | ||
Watch.set("*=", o, "id", null || v); | ||
Watch.set("/=", o, "id", null || v); | ||
Watch.set("%=", o, "id", null || 2); | ||
Watch.set("&=", o, "id", null || v); | ||
Watch.set("|=", o, "id", null || v); | ||
Watch.set("^=", o, "id", null || -1); | ||
Watch.set("<<=", o, "id", null || v); | ||
Watch.set(">>=", o, "id", null || v); | ||
Watch.set(">>>=", o, "id", null || 2); | ||
Assert(o.id === 1, "o.id === 1, function <script>, file plugins/watcher/tests/pre-forms.js, line 65"); | ||
|
||
// expr["str"] | ||
Watch.set("++v", (null || o), "id"); | ||
Watch.set("v++", (null || o), "id"); | ||
Watch.set("--v", (null || o), "id"); | ||
Watch.set("v--", (null || o), "id"); | ||
Watch.set("=", (null || o), "id", null || v); | ||
Watch.set("+=", (null || o), "id", null || v); | ||
Watch.set("-=", (null || o), "id", null || v); | ||
Watch.set("*=", (null || o), "id", null || v); | ||
Watch.set("/=", (null || o), "id", null || v); | ||
Watch.set("%=", (null || o), "id", null || 2); | ||
Watch.set("&=", (null || o), "id", null || v); | ||
Watch.set("|=", (null || o), "id", null || v); | ||
Watch.set("^=", (null || o), "id", null || -1); | ||
Watch.set("<<=", (null || o), "id", null || v); | ||
Watch.set(">>=", (null || o), "id", null || v); | ||
Watch.set(">>>=", (null || o), "id", null || 2); | ||
Assert(o.id === 1, "o.id === 1, function <script>, file plugins/watcher/tests/pre-forms.js, line 84"); | ||
|
||
// o[expr] | ||
Watch.set("++v", o, String(null || strid)); | ||
Watch.set("v++", o, String(null || strid)); | ||
Watch.set("--v", o, String(null || strid)); | ||
Watch.set("v--", o, String(null || strid)); | ||
Watch.set("=", o, String(null || strid), null || v); | ||
Watch.set("+=", o, String(null || strid), null || v); | ||
Watch.set("-=", o, String(null || strid), null || v); | ||
Watch.set("*=", o, String(null || strid), null || v); | ||
Watch.set("/=", o, String(null || strid), null || v); | ||
Watch.set("%=", o, String(null || strid), null || 2); | ||
Watch.set("&=", o, String(null || strid), null || v); | ||
Watch.set("|=", o, String(null || strid), null || v); | ||
Watch.set("^=", o, String(null || strid), null || -1); | ||
Watch.set("<<=", o, String(null || strid), null || v); | ||
Watch.set(">>=", o, String(null || strid), null || v); | ||
Watch.set(">>>=", o, String(null || strid), null || 2); | ||
Assert(o.id === 1, "o.id === 1, function <script>, file plugins/watcher/tests/pre-forms.js, line 103"); | ||
|
||
// expr1[expr2] | ||
Watch.set("++v", (null || o), String(null || strid)); | ||
Watch.set("v++", (null || o), String(null || strid)); | ||
Watch.set("--v", (null || o), String(null || strid)); | ||
Watch.set("v--", (null || o), String(null || strid)); | ||
Watch.set("=", (null || o), String(null || strid), null || v); | ||
Watch.set("+=", (null || o), String(null || strid), null || v); | ||
Watch.set("-=", (null || o), String(null || strid), null || v); | ||
Watch.set("*=", (null || o), String(null || strid), null || v); | ||
Watch.set("/=", (null || o), String(null || strid), null || v); | ||
Watch.set("%=", (null || o), String(null || strid), null || 2); | ||
Watch.set("&=", (null || o), String(null || strid), null || v); | ||
Watch.set("|=", (null || o), String(null || strid), null || v); | ||
Watch.set("^=", (null || o), String(null || strid), null || -1); | ||
Watch.set("<<=", (null || o), String(null || strid), null || v); | ||
Watch.set(">>=", (null || o), String(null || strid), null || v); | ||
Watch.set(">>>=", (null || o), String(null || strid), null || 2); | ||
Assert(o.id === 1, "o.id === 1, function <script>, file plugins/watcher/tests/pre-forms.js, line 122"); |
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,122 @@ | ||
"use strict"; "use restrict"; | ||
|
||
var require = require || function(f) { load(f); }; | ||
var Assert = Assert || require("./assert.js") || Assert; | ||
var Watch = Watch || require("./plugins/watcher/watch.js") || Watch; | ||
var v = 123; | ||
var o = {id: v}; | ||
var strid = "id"; | ||
|
||
// o.id | ||
++o.id; | ||
o.id++; | ||
--o.id; | ||
o.id--; | ||
o.id = null || v; | ||
o.id += null || v; | ||
o.id -= null || v; | ||
o.id *= null || v; | ||
o.id /= null || v; | ||
o.id %= null || 2; | ||
o.id &= null || v; | ||
o.id |= null || v; | ||
o.id ^= null || -1; | ||
o.id <<= null || v; | ||
o.id >>= null || v; | ||
o.id >>>= null || 2; | ||
Assert(o.id === 1); | ||
|
||
// expr.id | ||
++(null || o).id; | ||
(null || o).id++; | ||
--(null || o).id; | ||
(null || o).id--; | ||
(null || o).id = null || v; | ||
(null || o).id += null || v; | ||
(null || o).id -= null || v; | ||
(null || o).id *= null || v; | ||
(null || o).id /= null || v; | ||
(null || o).id %= null || 2; | ||
(null || o).id &= null || v; | ||
(null || o).id |= null || v; | ||
(null || o).id ^= null || -1; | ||
(null || o).id <<= null || v; | ||
(null || o).id >>= null || v; | ||
(null || o).id >>>= null || 2; | ||
Assert(o.id === 1); | ||
|
||
// o["str"] | ||
++o["id"]; | ||
o["id"]++; | ||
--o["id"]; | ||
o["id"]--; | ||
o["id"] = null || v; | ||
o["id"] += null || v; | ||
o["id"] -= null || v; | ||
o["id"] *= null || v; | ||
o["id"] /= null || v; | ||
o["id"] %= null || 2; | ||
o["id"] &= null || v; | ||
o["id"] |= null || v; | ||
o["id"] ^= null || -1; | ||
o["id"] <<= null || v; | ||
o["id"] >>= null || v; | ||
o["id"] >>>= null || 2; | ||
Assert(o.id === 1); | ||
|
||
// expr["str"] | ||
++(null || o)["id"]; | ||
(null || o)["id"]++; | ||
--(null || o)["id"]; | ||
(null || o)["id"]--; | ||
(null || o)["id"] = null || v; | ||
(null || o)["id"] += null || v; | ||
(null || o)["id"] -= null || v; | ||
(null || o)["id"] *= null || v; | ||
(null || o)["id"] /= null || v; | ||
(null || o)["id"] %= null || 2; | ||
(null || o)["id"] &= null || v; | ||
(null || o)["id"] |= null || v; | ||
(null || o)["id"] ^= null || -1; | ||
(null || o)["id"] <<= null || v; | ||
(null || o)["id"] >>= null || v; | ||
(null || o)["id"] >>>= null || 2; | ||
Assert(o.id === 1); | ||
|
||
// o[expr] | ||
++o[null || strid]; | ||
o[null || strid]++; | ||
--o[null || strid]; | ||
o[null || strid]--; | ||
o[null || strid] = null || v; | ||
o[null || strid] += null || v; | ||
o[null || strid] -= null || v; | ||
o[null || strid] *= null || v; | ||
o[null || strid] /= null || v; | ||
o[null || strid] %= null || 2; | ||
o[null || strid] &= null || v; | ||
o[null || strid] |= null || v; | ||
o[null || strid] ^= null || -1; | ||
o[null || strid] <<= null || v; | ||
o[null || strid] >>= null || v; | ||
o[null || strid] >>>= null || 2; | ||
Assert(o.id === 1); | ||
|
||
// expr1[expr2] | ||
++(null || o)[null || strid]; | ||
(null || o)[null || strid]++; | ||
--(null || o)[null || strid]; | ||
(null || o)[null || strid]--; | ||
(null || o)[null || strid] = null || v; | ||
(null || o)[null || strid] += null || v; | ||
(null || o)[null || strid] -= null || v; | ||
(null || o)[null || strid] *= null || v; | ||
(null || o)[null || strid] /= null || v; | ||
(null || o)[null || strid] %= null || 2; | ||
(null || o)[null || strid] &= null || v; | ||
(null || o)[null || strid] |= null || v; | ||
(null || o)[null || strid] ^= null || -1; | ||
(null || o)[null || strid] <<= null || v; | ||
(null || o)[null || strid] >>= null || v; | ||
(null || o)[null || strid] >>>= null || 2; | ||
Assert(o.id === 1); |
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
This file was deleted.
Oops, something went wrong.