summaryrefslogtreecommitdiff
path: root/deps/v8/test/mjsunit/json2.js
diff options
context:
space:
mode:
authorBen Noordhuis <info@bnoordhuis.nl>2013-04-08 20:25:29 +0200
committerBen Noordhuis <info@bnoordhuis.nl>2013-04-08 20:35:27 +0200
commit587e83c6d6fa9bba14f5b629fa2ee905dc6881e8 (patch)
tree49ef341f730dbecbd8a8ea354be0ac35317a30fb /deps/v8/test/mjsunit/json2.js
parent1fd95b57bf51b548651ef7868ce2dd8e65e7cf6f (diff)
downloadandroid-node-v8-587e83c6d6fa9bba14f5b629fa2ee905dc6881e8.tar.gz
android-node-v8-587e83c6d6fa9bba14f5b629fa2ee905dc6881e8.tar.bz2
android-node-v8-587e83c6d6fa9bba14f5b629fa2ee905dc6881e8.zip
v8: upgrade to 3.17.16
Diffstat (limited to 'deps/v8/test/mjsunit/json2.js')
-rw-r--r--deps/v8/test/mjsunit/json2.js65
1 files changed, 46 insertions, 19 deletions
diff --git a/deps/v8/test/mjsunit/json2.js b/deps/v8/test/mjsunit/json2.js
index 4c0b8f58c8..cf20b909b4 100644
--- a/deps/v8/test/mjsunit/json2.js
+++ b/deps/v8/test/mjsunit/json2.js
@@ -25,13 +25,19 @@
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-// Flags: --allow-natives-syntax
+// Flags: --allow-natives-syntax --expose-externalize-string
// Test JSON.stringify on the global object.
var a = 12345;
assertTrue(JSON.stringify(this).indexOf('"a":12345') > 0);
+assertTrue(JSON.stringify(this, null, 0).indexOf('"a":12345') > 0);
// Test JSON.stringify of array in dictionary mode.
+function TestStringify(expected, input) {
+ assertEquals(expected, JSON.stringify(input));
+ assertEquals(expected, JSON.stringify(input, null, 0));
+}
+
var array_1 = [];
var array_2 = [];
array_1[100000] = 1;
@@ -42,25 +48,25 @@ for (var i = 0; i < 100000; i++) {
}
expected_1 = '[' + nulls + '1]';
expected_2 = '[' + nulls + 'null]';
-assertEquals(expected_1, JSON.stringify(array_1));
-assertEquals(expected_2, JSON.stringify(array_2));
+TestStringify(expected_1, array_1);
+TestStringify(expected_2, array_2);
// Test JSValue with custom prototype.
var num_wrapper = Object(42);
num_wrapper.__proto__ = { __proto__: null,
toString: function() { return true; } };
-assertEquals('1', JSON.stringify(num_wrapper));
+TestStringify('1', num_wrapper);
var str_wrapper = Object('2');
str_wrapper.__proto__ = { __proto__: null,
toString: function() { return true; } };
-assertEquals('"true"', JSON.stringify(str_wrapper));
+TestStringify('"true"', str_wrapper);
var bool_wrapper = Object(false);
bool_wrapper.__proto__ = { __proto__: null,
toString: function() { return true; } };
// Note that toString function is not evaluated here!
-assertEquals('false', JSON.stringify(bool_wrapper));
+TestStringify('false', bool_wrapper);
// Test getters.
var counter = 0;
@@ -68,8 +74,8 @@ var getter_obj = { get getter() {
counter++;
return 123;
} };
-assertEquals('{"getter":123}', JSON.stringify(getter_obj));
-assertEquals(1, counter);
+TestStringify('{"getter":123}', getter_obj);
+assertEquals(2, counter);
// Test toJSON function.
var tojson_obj = { toJSON: function() {
@@ -77,8 +83,8 @@ var tojson_obj = { toJSON: function() {
return [1, 2];
},
a: 1};
-assertEquals('[1,2]', JSON.stringify(tojson_obj));
-assertEquals(2, counter);
+TestStringify('[1,2]', tojson_obj);
+assertEquals(4, counter);
// Test that we don't recursively look for the toJSON function.
var tojson_proto_obj = { a: 'fail' };
@@ -86,7 +92,7 @@ tojson_proto_obj.__proto__ = { toJSON: function() {
counter++;
return tojson_obj;
} };
-assertEquals('{"a":1}', JSON.stringify(tojson_proto_obj));
+TestStringify('{"a":1}', tojson_proto_obj);
// Test toJSON produced by a getter.
var tojson_via_getter = { get toJSON() {
@@ -96,43 +102,44 @@ var tojson_via_getter = { get toJSON() {
};
},
a: 1 };
-assertEquals('321', JSON.stringify(tojson_via_getter));
+TestStringify('321', tojson_via_getter);
// Test toJSON with key.
tojson_obj = { toJSON: function(key) { return key + key; } };
var tojson_with_key_1 = { a: tojson_obj, b: tojson_obj };
-assertEquals('{"a":"aa","b":"bb"}', JSON.stringify(tojson_with_key_1));
+TestStringify('{"a":"aa","b":"bb"}', tojson_with_key_1);
var tojson_with_key_2 = [ tojson_obj, tojson_obj ];
-assertEquals('["00","11"]', JSON.stringify(tojson_with_key_2));
+TestStringify('["00","11"]', tojson_with_key_2);
// Test toJSON with exception.
var tojson_ex = { toJSON: function(key) { throw "123" } };
assertThrows(function() { JSON.stringify(tojson_ex); });
+assertThrows(function() { JSON.stringify(tojson_ex, null, 0); });
// Test toJSON with access to this.
var obj = { toJSON: function(key) { return this.a + key; }, a: "x" };
-assertEquals('{"y":"xy"}', JSON.stringify({y: obj}));
+TestStringify('{"y":"xy"}', {y: obj});
// Test holes in arrays.
var fast_smi = [1, 2, 3, 4];
fast_smi.__proto__ = [7, 7, 7, 7];
delete fast_smi[2];
assertTrue(%HasFastSmiElements(fast_smi));
-assertEquals("[1,2,7,4]", JSON.stringify(fast_smi));
+TestStringify("[1,2,7,4]", fast_smi);
var fast_double = [1.1, 2, 3, 4];
fast_double.__proto__ = [7, 7, 7, 7];
delete fast_double[2];
assertTrue(%HasFastDoubleElements(fast_double));
-assertEquals("[1.1,2,7,4]", JSON.stringify(fast_double));
+TestStringify("[1.1,2,7,4]", fast_double);
var fast_obj = [1, 2, {}, {}];
fast_obj.__proto__ = [7, 7, 7, 7];
delete fast_obj[2];
assertTrue(%HasFastObjectElements(fast_obj));
-assertEquals("[1,2,7,{}]", JSON.stringify(fast_obj));
+TestStringify("[1,2,7,{}]", fast_obj);
var getter_side_effect = { a: 1,
get b() {
@@ -146,8 +153,28 @@ var getter_side_effect = { a: 1,
assertEquals('{"a":1,"b":2,"d":4}', JSON.stringify(getter_side_effect));
assertEquals('{"b":2,"d":4,"e":5}', JSON.stringify(getter_side_effect));
+getter_side_effect = { a: 1,
+ get b() {
+ delete this.a;
+ delete this.c;
+ this.e = 5;
+ return 2;
+ },
+ c: 3,
+ d: 4 };
+assertEquals('{"a":1,"b":2,"d":4}',
+ JSON.stringify(getter_side_effect, null, 0));
+assertEquals('{"b":2,"d":4,"e":5}',
+ JSON.stringify(getter_side_effect, null, 0));
+
var non_enum = {};
non_enum.a = 1;
Object.defineProperty(non_enum, "b", { value: 2, enumerable: false });
non_enum.c = 3;
-assertEquals('{"a":1,"c":3}', JSON.stringify(non_enum));
+TestStringify('{"a":1,"c":3}', non_enum);
+
+var str = "external";
+try {
+ externalizeString(str, true);
+} catch (e) { }
+TestStringify("\"external\"", str, null, 0);