mirror of https://github.com/tc39/test262.git
Merge branch 'bocoup/symbol-cleanup'
This commit is contained in:
commit
562133f4ba
|
@ -1,17 +1,19 @@
|
||||||
// Copyright (C) 2013 the V8 project authors. All rights reserved.
|
// Copyright (C) 2016 the V8 project authors. All rights reserved.
|
||||||
// This code is governed by the BSD license found in the LICENSE file.
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
/*---
|
/*---
|
||||||
es6id: 19.4.3.2
|
esid: sec-string-constructor
|
||||||
description: >
|
es6id: 21.1.1
|
||||||
String coercion operations on Symbols
|
description: Symbol value may be coerced to a String
|
||||||
|
info: |
|
||||||
|
1. If no arguments were passed to this function invocation, let s be "".
|
||||||
|
2. Else,
|
||||||
|
a. If NewTarget is undefined and Type(value) is Symbol, return
|
||||||
|
SymbolDescriptiveString(value).
|
||||||
|
features: [Symbol]
|
||||||
---*/
|
---*/
|
||||||
|
|
||||||
assert.throws(TypeError, function() {
|
assert.sameValue(String(Symbol('66')), 'Symbol(66)');
|
||||||
new String(Symbol('66'));
|
assert.sameValue(String(Symbol()), 'Symbol()', 'implicit `undefined`');
|
||||||
});
|
assert.sameValue(
|
||||||
|
String(Symbol(undefined)), 'Symbol()', 'explicit `undefined`'
|
||||||
assert.throws(TypeError, function() {
|
);
|
||||||
Symbol('66') + '';
|
|
||||||
});
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,20 @@
|
||||||
|
// Copyright (C) 2013 the V8 project authors. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
/*---
|
||||||
|
esid: sec-string-constructor
|
||||||
|
es6id: 21.1.1
|
||||||
|
description: Symbol value may not be wrapped
|
||||||
|
info: |
|
||||||
|
1. If no arguments were passed to this function invocation, let s be "".
|
||||||
|
2. Else,
|
||||||
|
a. If NewTarget is undefined and Type(value) is Symbol, return
|
||||||
|
SymbolDescriptiveString(value).
|
||||||
|
b. Let s be ? ToString(value).
|
||||||
|
features: [Symbol]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
var s = Symbol('66');
|
||||||
|
|
||||||
|
assert.throws(TypeError, function() {
|
||||||
|
new String(s);
|
||||||
|
});
|
|
@ -0,0 +1,19 @@
|
||||||
|
// Copyright (C) 2016 the V8 project authors. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
/*---
|
||||||
|
esid: sec-symbol-constructor
|
||||||
|
es6id: 19.4.1
|
||||||
|
description: The first argument is coerced to a String value (from a Symbol)
|
||||||
|
info: |
|
||||||
|
1. If NewTarget is not undefined, throw a TypeError exception.
|
||||||
|
2. If description is undefined, let descString be undefined.
|
||||||
|
2. Else, let descString be ? ToString(description).
|
||||||
|
3. Return a new unique Symbol value whose [[Description]] value is
|
||||||
|
descString.
|
||||||
|
---*/
|
||||||
|
|
||||||
|
var s = Symbol('1');
|
||||||
|
|
||||||
|
assert.throws(TypeError, function() {
|
||||||
|
Symbol(s);
|
||||||
|
});
|
|
@ -0,0 +1,90 @@
|
||||||
|
// Copyright (C) 2016 the V8 project authors. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
/*---
|
||||||
|
esid: sec-symbol-constructor
|
||||||
|
es6id: 19.4.1
|
||||||
|
description: The first argument is coerced to a String value (from an object)
|
||||||
|
info: |
|
||||||
|
1. If NewTarget is not undefined, throw a TypeError exception.
|
||||||
|
2. If description is undefined, let descString be undefined.
|
||||||
|
2. Else, let descString be ? ToString(description).
|
||||||
|
3. Return a new unique Symbol value whose [[Description]] value is
|
||||||
|
descString.
|
||||||
|
---*/
|
||||||
|
|
||||||
|
var calls, val;
|
||||||
|
|
||||||
|
val = {
|
||||||
|
toString: function() {
|
||||||
|
calls += 'toString';
|
||||||
|
return {};
|
||||||
|
},
|
||||||
|
valueOf: function() {
|
||||||
|
calls += 'valueOf';
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
calls = '';
|
||||||
|
Symbol(val);
|
||||||
|
assert.sameValue(calls, 'toStringvalueOf');
|
||||||
|
|
||||||
|
val = {
|
||||||
|
toString: function() {
|
||||||
|
calls += 'toString';
|
||||||
|
},
|
||||||
|
valueOf: function() {
|
||||||
|
calls += 'valueOf';
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
calls = '';
|
||||||
|
Symbol(val);
|
||||||
|
assert.sameValue(calls, 'toString');
|
||||||
|
|
||||||
|
val = {
|
||||||
|
toString: null,
|
||||||
|
valueOf: function() {
|
||||||
|
calls += 'valueOf';
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
calls = '';
|
||||||
|
Symbol(val);
|
||||||
|
assert.sameValue(calls, 'valueOf');
|
||||||
|
|
||||||
|
val = {
|
||||||
|
toString: null,
|
||||||
|
valueOf: function() {
|
||||||
|
calls += 'valueOf';
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
calls = '';
|
||||||
|
assert.throws(TypeError, function() {
|
||||||
|
Symbol(val);
|
||||||
|
}, '`toString` is not callable, and `valueOf` returns a non-primitive value');
|
||||||
|
assert.sameValue(
|
||||||
|
calls, 'valueOf', 'invocation pattern for non-callable `toString`'
|
||||||
|
);
|
||||||
|
|
||||||
|
val = {
|
||||||
|
toString: function() {
|
||||||
|
calls += 'toString';
|
||||||
|
return {};
|
||||||
|
},
|
||||||
|
valueOf: function() {
|
||||||
|
calls += 'valueOf';
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
calls = '';
|
||||||
|
assert.throws(TypeError, function() {
|
||||||
|
Symbol(val);
|
||||||
|
}, '`toString` nor `valueOf` both return non-primitive values');
|
||||||
|
assert.sameValue(
|
||||||
|
calls,
|
||||||
|
'toStringvalueOf',
|
||||||
|
'invocation pattern for non-callable `toString` and `valueOf`'
|
||||||
|
);
|
|
@ -0,0 +1,17 @@
|
||||||
|
// Copyright (C) 2016 the V8 project authors. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
/*---
|
||||||
|
esid: sec-symbol-constructor
|
||||||
|
es6id: 19.4.1
|
||||||
|
description: The Symbol constructor may not be invoked with `new`
|
||||||
|
info: |
|
||||||
|
1. If NewTarget is not undefined, throw a TypeError exception.
|
||||||
|
---*/
|
||||||
|
|
||||||
|
assert.throws(TypeError, function() {
|
||||||
|
new Symbol();
|
||||||
|
});
|
||||||
|
|
||||||
|
assert.throws(TypeError, function() {
|
||||||
|
new Symbol('1');
|
||||||
|
});
|
|
@ -0,0 +1,24 @@
|
||||||
|
// Copyright (C) 2016 the V8 project authors. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
/*---
|
||||||
|
esid: sec-symbol-constructor
|
||||||
|
es6id: 19.4.1
|
||||||
|
description: The value "undefined" is reported as the empty string
|
||||||
|
info: |
|
||||||
|
1. If NewTarget is not undefined, throw a TypeError exception.
|
||||||
|
2. If description is undefined, let descString be undefined.
|
||||||
|
2. Else, let descString be ? ToString(description).
|
||||||
|
3. Return a new unique Symbol value whose [[Description]] value is
|
||||||
|
descString.
|
||||||
|
|
||||||
|
19.4.3.2.1 Runtime Semantics: SymbolDescriptiveString
|
||||||
|
|
||||||
|
1. Assert: Type(sym) is Symbol.
|
||||||
|
2. Let desc be sym's [[Description]] value.
|
||||||
|
3. If desc is undefined, let desc be the empty string.
|
||||||
|
4. Assert: Type(desc) is String.
|
||||||
|
5. Return the result of concatenating the strings "Symbol(", desc, and ")".
|
||||||
|
---*/
|
||||||
|
|
||||||
|
assert.sameValue(Symbol().toString(), 'Symbol()', 'implicit value');
|
||||||
|
assert.sameValue(Symbol(undefined).toString(), 'Symbol()', 'explicit value');
|
|
@ -0,0 +1,18 @@
|
||||||
|
// Copyright (C) 2016 the V8 project authors. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
/*---
|
||||||
|
esid: sec-symbol-constructor
|
||||||
|
es6id: 19.4.1
|
||||||
|
description: The Symbol constructor returns a unique value
|
||||||
|
info: |
|
||||||
|
1. If NewTarget is not undefined, throw a TypeError exception.
|
||||||
|
2. If description is undefined, let descString be undefined.
|
||||||
|
2. Else, let descString be ? ToString(description).
|
||||||
|
3. Return a new unique Symbol value whose [[Description]] value is
|
||||||
|
descString.
|
||||||
|
---*/
|
||||||
|
|
||||||
|
assert.notSameValue(Symbol(''), Symbol(''), 'empty string');
|
||||||
|
assert.notSameValue(Symbol(), Symbol(), 'undefined');
|
||||||
|
assert.notSameValue(Symbol(null), Symbol(null), 'null value');
|
||||||
|
assert.notSameValue(Symbol('x'), Symbol('x'), 'string "x"');
|
|
@ -0,0 +1,17 @@
|
||||||
|
// Copyright (C) 2013 the V8 project authors. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
/*---
|
||||||
|
esid: sec-addition-operator-plus
|
||||||
|
es6id: 12.7.3
|
||||||
|
description: Symbol value cannot be converted to a String
|
||||||
|
info: |
|
||||||
|
[...]
|
||||||
|
7. If Type(lprim) is String or Type(rprim) is String, then
|
||||||
|
a. Let lstr be ? ToString(lprim).
|
||||||
|
features: [Symbol]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
var s = Symbol('66');
|
||||||
|
assert.throws(TypeError, function() {
|
||||||
|
s + '';
|
||||||
|
});
|
Loading…
Reference in New Issue