Projekt

Obecné

Profil

Stáhnout (1.81 KB) Statistiky
| Větev: | Revize:
1
'use strict';
2

    
3
var test = require('tape');
4
var defineProperties = require('define-properties');
5
var isEnumerable = Object.prototype.propertyIsEnumerable;
6
var functionsHaveNames = function f() {}.name === 'f';
7

    
8
var runTests = require('./tests');
9

    
10
test('native', function (t) {
11
	t.equal(Object.assign.length, 2, 'Object.assign has a length of 2');
12
	t.test('Function name', { skip: !functionsHaveNames }, function (st) {
13
		st.equal(Object.assign.name, 'assign', 'Object.assign has name "assign"');
14
		st.end();
15
	});
16

    
17
	t.test('enumerability', { skip: !defineProperties.supportsDescriptors }, function (et) {
18
		et.equal(false, isEnumerable.call(Object, 'assign'), 'Object.assign is not enumerable');
19
		et.end();
20
	});
21

    
22
	var supportsStrictMode = (function () { return typeof this === 'undefined'; }());
23

    
24
	t.test('bad object value', { skip: !supportsStrictMode }, function (st) {
25
		st['throws'](function () { return Object.assign(undefined); }, TypeError, 'undefined is not an object');
26
		st['throws'](function () { return Object.assign(null); }, TypeError, 'null is not an object');
27
		st.end();
28
	});
29

    
30
	// v8 in node 0.8 and 0.10 have non-enumerable string properties
31
	var stringCharsAreEnumerable = isEnumerable.call('xy', 0);
32
	t.test('when Object.assign is present and has pending exceptions', { skip: !stringCharsAreEnumerable || !Object.preventExtensions }, function (st) {
33
		// Firefox 37 still has "pending exception" logic in its Object.assign implementation,
34
		// which is 72% slower than our shim, and Firefox 40's native implementation.
35
		var thrower = Object.preventExtensions({ 1: '2' });
36
		var error;
37
		try { Object.assign(thrower, 'xy'); } catch (e) { error = e; }
38
		st.equal(error instanceof TypeError, true, 'error is TypeError');
39
		st.equal(thrower[1], '2', 'thrower[1] === "2"');
40

    
41
		st.end();
42
	});
43

    
44
	runTests(Object.assign, t);
45

    
46
	t.end();
47
});
(3-3/5)