Skip to content
This repository was archived by the owner on Oct 23, 2019. It is now read-only.

Commit 96cc5bb

Browse files
author
Andrea Giammarchi
committed
fixed replacer context
1 parent 727dbe4 commit 96cc5bb

File tree

8 files changed

+20
-7
lines changed

8 files changed

+20
-7
lines changed

build/circular-json.amd.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

build/circular-json.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

build/circular-json.max.amd.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ function generateReplacer(value, replacer, resolve) {
5757
// if a new object should be returned
5858
// or if there's some key to drop
5959
// let's call it here rather than "too late"
60-
if (replacer) value = replacer(key, value);
60+
if (replacer) value = replacer.call(this, key, value);
6161

6262
// did you know ? Safari passes keys as integers for arrays
6363
if (key !== '') {

build/circular-json.max.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ function generateReplacer(value, replacer, resolve) {
5757
// if a new object should be returned
5858
// or if there's some key to drop
5959
// let's call it here rather than "too late"
60-
if (replacer) value = replacer(key, value);
60+
if (replacer) value = replacer.call(this, key, value);
6161

6262
// did you know ? Safari passes keys as integers for arrays
6363
if (key !== '') {

build/circular-json.node.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ function generateReplacer(value, replacer, resolve) {
5656
// if a new object should be returned
5757
// or if there's some key to drop
5858
// let's call it here rather than "too late"
59-
if (replacer) value = replacer(key, value);
59+
if (replacer) value = replacer.call(this, key, value);
6060

6161
// did you know ? Safari passes keys as integers for arrays
6262
if (key !== '') {

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"version": "0.1.3",
2+
"version": "0.1.4",
33
"name": "circular-json",
44
"description": "JSON does not handle circular references. This version does",
55
"homepage": "https://github.com/WebReflection/circular-json",

src/circular-json.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ function generateReplacer(value, replacer, resolve) {
3434
// if a new object should be returned
3535
// or if there's some key to drop
3636
// let's call it here rather than "too late"
37-
if (replacer) value = replacer(key, value);
37+
if (replacer) value = replacer.call(this, key, value);
3838

3939
// did you know ? Safari passes keys as integers for arrays
4040
if (key !== '') {

test/circular-json.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,19 @@ wru.test([
124124
wru.assert('no way to retrieve the path', o.o === '[Circular]');
125125
wru.assert('same structure though', o.a[3] === '[Circular]');
126126
}
127+
},{
128+
name: 'should pass the right context',
129+
test: function () {
130+
var found = false, o = {};
131+
o.o = o;
132+
CircularJSON.stringify(o, function (key, value) {
133+
if (!found && this === o) {
134+
found = true;
135+
}
136+
return value;
137+
});
138+
wru.assert(found);
139+
}
127140
}/*
128141
,{
129142
name: 'reviver',

0 commit comments

Comments
 (0)