mirror of https://github.com/svaarala/duktape.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
44 lines
917 B
44 lines
917 B
12 years ago
|
/* When encoding any value (val) using JSON.stringigy(), encoding begins
|
||
|
* with a dummy wrapper object:
|
||
|
*
|
||
|
* { "": val }
|
||
|
*
|
||
|
* This seems to be a purely internal matter but is not: the wrapper
|
||
|
* object is accessible to a replacement function.
|
||
|
*/
|
||
|
|
||
|
var val;
|
||
|
var t;
|
||
|
|
||
|
/*===
|
||
|
replacer
|
||
12 years ago
|
desc: true true true foo
|
||
12 years ago
|
object
|
||
|
foo
|
||
|
|
||
|
foo
|
||
|
===*/
|
||
|
|
||
|
// Here the wrapper object is: { "": "foo" }
|
||
|
|
||
|
try {
|
||
|
val = "foo";
|
||
|
t = JSON.stringify(val, function(k, v) {
|
||
|
// this binding: holder object, i.e. the wrapper
|
||
|
// k: key
|
||
|
// v: value
|
||
|
|
||
|
print("replacer");
|
||
12 years ago
|
|
||
|
var pd = Object.getOwnPropertyDescriptor(this, '');
|
||
|
print('desc:', pd.writable, pd.enumerable, pd.configurable, pd.value);
|
||
|
|
||
12 years ago
|
print(typeof this);
|
||
12 years ago
|
print(this['']); // access the empty string key of the wrapper
|
||
12 years ago
|
print(k); // empty string
|
||
|
print(v); // 'foo'
|
||
|
});
|
||
|
} catch (e) {
|
||
|
print(e.name);
|
||
|
}
|