Projekt

Obecné

Profil

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

    
3
var assign = require('../');
4
assign.shim();
5

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

    
11
var runTests = require('./tests');
12

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

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

    
25
	var supportsStrictMode = (function () { return typeof this === 'undefined'; }());
26

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

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

    
44
		st.end();
45
	});
46

    
47
	runTests(Object.assign, t);
48

    
49
	t.end();
50
});
(4-4/5)