summaryrefslogtreecommitdiffstats
path: root/js/src/tests/test262/built-ins/JSON/stringify/value-boolean-object.js
blob: 21fddf5eec5fae0ba1fe418d39fe24265e5a2aed (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
// Copyright (C) 2012 Ecma International. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-serializejsonproperty
description: >
  Boolean objects are converted to primitives using [[BooleanData]].
info: |
  JSON.stringify ( value [ , replacer [ , space ] ] )

  [...]
  12. Return ? SerializeJSONProperty(the empty String, wrapper).

  SerializeJSONProperty ( key, holder )

  [...]
  4. If Type(value) is Object, then
    [...]
    c. Else if value has a [[BooleanData]] internal slot, then
      i. Set value to value.[[BooleanData]].
  [...]
  6. If value is true, return "true".
  7. If value is false, return "false".
---*/

assert.sameValue(JSON.stringify(new Boolean(true)), 'true');

assert.sameValue(
  JSON.stringify({
    toJSON: function() {
      return {key: new Boolean(false)};
    },
  }),
  '{"key":false}'
);

assert.sameValue(JSON.stringify([1], function(_k, v) {
  return v === 1 ? new Boolean(true) : v;
}), '[true]');

reportCompare(0, 0);