source: imaps-frontend/node_modules/object.assign/test/native.js

main
Last change on this file was d565449, checked in by stefan toskovski <stefantoska84@…>, 4 weeks ago

Update repo after prototype presentation

  • Property mode set to 100644
File size: 1.8 KB
Line 
1'use strict';
2
3var test = require('tape');
4var defineProperties = require('define-properties');
5var isEnumerable = Object.prototype.propertyIsEnumerable;
6var functionsHaveNames = require('functions-have-names')();
7
8var runTests = require('./tests');
9
10test('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 /*
34 * Firefox 37 still has "pending exception" logic in its Object.assign implementation,
35 * which is 72% slower than our shim, and Firefox 40's native implementation.
36 */
37 var thrower = Object.preventExtensions({ 1: '2' });
38 var error;
39 try { Object.assign(thrower, 'xy'); } catch (e) { error = e; }
40 st.equal(error instanceof TypeError, true, 'error is TypeError');
41 st.equal(thrower[1], '2', 'thrower[1] === "2"');
42
43 st.end();
44 });
45
46 runTests(Object.assign, t);
47
48 t.end();
49});
Note: See TracBrowser for help on using the repository browser.