mirror of
				https://github.com/tc39/test262.git
				synced 2025-10-31 19:53:50 +01:00 
			
		
		
		
	* Rename & improve "length" test * Use verifyProperty in "name" test * Rename & improve property descriptor test * Remove duplicated test https://github.com/tc39/test262/blob/master/test/built-ins/Object/prototype/toString/proxy-array.js * Rename proxy value test * Rename & improve String object unwrapping test * Rename & improve Number object unwrapping test * Rename & improve Boolean object unwrapping test * Rename & merge replacer returns undefined tests * Rename & merge replacer function tests * Rename replacer array revoked proxy test * Add cross-realm replacer array revoked proxy test * Add array proxy replacer test * Add replacer array keys order test * Add empty replacer array test * Add non-finite numbers serialization test * Add replacer array abrupt completion test * Add replacer array with duplicates test * Add replacer array ignores undefined test * Add replacer array unwraps strings test * Add replacer array unwraps numbers test * Rename & merge circular object tests * Add circular array test * Rename & merge top-level primitives tests * Rename string escape tests * Rename BigInt tests * Rename & improve function value test * Add replacer function abrupt test * Rename & merge wrong space type tests * Rename float number space test * Rename & improve Number object space test * Rename & improve String object space test * Rename basic numeric space test * Rename string space slice test * Add replacer array numbers test * Add toJSON abrupt completions test * Add not callable toJSON test * Add toJSON call arguments test * Add replacer array wrong types test * Rename & improve string space test * Rename & improve replacer wrong type test * Add built-in object requirements test * Add basic toJSON result test * Add abrupt array value test * Add abrupt object value test * Rename & merge space number clamp tests * Add replacer function wrapper test * Add symbol value test * Add negative zero value test * Add replacer function & toJSON test * Add circular object from toJSON test * Add circular array from toJSON test * Add circular object from replacer test * Add circular array from replacer test * Add replacer function arguments test * Split & improve proxy value test * Split & improve revoked proxy value test
		
			
				
	
	
		
			54 lines
		
	
	
		
			1.3 KiB
		
	
	
	
		
			JavaScript
		
	
	
	
	
	
			
		
		
	
	
			54 lines
		
	
	
		
			1.3 KiB
		
	
	
	
		
			JavaScript
		
	
	
	
	
	
| // Copyright (C) 2019 Aleksey Shvayka. All rights reserved.
 | |
| // This code is governed by the BSD license found in the LICENSE file.
 | |
| /*---
 | |
| esid: sec-serializejsonproperty
 | |
| description: >
 | |
|   Replacer function is called with correct context and arguments.
 | |
| info: |
 | |
|   JSON.stringify ( value [ , replacer [ , space ] ] )
 | |
| 
 | |
|   [...]
 | |
|   12. Return ? SerializeJSONProperty(the empty String, wrapper).
 | |
| 
 | |
|   SerializeJSONProperty ( key, holder )
 | |
| 
 | |
|   1. Let value be ? Get(holder, key).
 | |
|   [...]
 | |
|   3. If ReplacerFunction is not undefined, then
 | |
|     a. Set value to ? Call(ReplacerFunction, holder, « key, value »).
 | |
| includes: [compareArray.js]
 | |
| ---*/
 | |
| 
 | |
| var calls = [];
 | |
| var replacer = function(key, value) {
 | |
|   if (key !== '') {
 | |
|     calls.push([this, key, value]);
 | |
|   }
 | |
| 
 | |
|   return value;
 | |
| };
 | |
| 
 | |
| var b1 = [1, 2];
 | |
| var b2 = {c1: true, c2: false};
 | |
| var a1 = {
 | |
|   b1: b1,
 | |
|   b2: {
 | |
|     toJSON: function() { return b2; },
 | |
|   },
 | |
| };
 | |
| var obj = {a1: a1, a2: 'a2'};
 | |
| 
 | |
| assert.sameValue(
 | |
|   JSON.stringify(obj, replacer),
 | |
|   JSON.stringify(obj)
 | |
| );
 | |
| 
 | |
| assert.compareArray(calls[0], [obj, 'a1', a1]);
 | |
| assert.compareArray(calls[1], [a1, 'b1', b1]);
 | |
| assert.compareArray(calls[2], [b1, '0', 1]);
 | |
| assert.compareArray(calls[3], [b1, '1', 2]);
 | |
| assert.compareArray(calls[4], [a1, 'b2', b2]);
 | |
| assert.compareArray(calls[5], [b2, 'c1', true]);
 | |
| assert.compareArray(calls[6], [b2, 'c2', false]);
 | |
| assert.compareArray(calls[7], [obj, 'a2', 'a2']);
 |