summaryrefslogtreecommitdiff
path: root/tools/eslint/node_modules/escope/node_modules/es6-weak-map/node_modules/d/test/lazy.js
blob: 8266deb240fda3fb27d4940fd07ca280812a7bb1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
'use strict';

var d = require('../')

  , getOwnPropertyDescriptor = Object.getOwnPropertyDescriptor;

module.exports = function (t, a) {
	var Foo = function () {}, i = 1, o, o2, desc;
	Object.defineProperties(Foo.prototype, t({
		bar: d(function () { return ++i; }),
		bar2: d(function () { return this.bar + 23; }),
		bar3: d(function () { return this.bar2 + 34; }, { desc: 'ew' }),
		bar4: d(function () { return this.bar3 + 12; }, { cacheName: '_bar4_' }),
		bar5: d(function () { return this.bar4 + 3; },
			{ cacheName: '_bar5_', desc: 'e' })
	}));

	desc = getOwnPropertyDescriptor(Foo.prototype, 'bar');
	a(desc.configurable, true, "Configurable: default");
	a(desc.enumerable, false, "Enumerable: default");

	o = new Foo();
	a.deep([o.bar, o.bar2, o.bar3, o.bar4, o.bar5], [2, 25, 59, 71, 74],
		"Values");

	a.deep(getOwnPropertyDescriptor(o, 'bar3'), { configurable: false,
		enumerable: true, writable: true, value: 59 }, "Desc");
	a(o.hasOwnProperty('bar4'), false, "Cache not exposed");
	desc = getOwnPropertyDescriptor(o, 'bar5');
	a.deep(desc, { configurable: false,
		enumerable: true, get: desc.get, set: desc.set }, "Cache & Desc: desc");

	o2 = Object.create(o);
	o2.bar = 30;
	o2.bar3 = 100;

	a.deep([o2.bar, o2.bar2, o2.bar3, o2.bar4, o2.bar5], [30, 25, 100, 112, 115],
		"Extension Values");

	Foo = function () {};
	Object.defineProperties(Foo.prototype, t({
		test: d('w', function () { return 'raz'; }),
		test2: d('', function () { return 'raz'; }, { desc: 'w' }),
		test3: d('', function () { return 'raz'; },
			{ cacheName: '__test3__', desc: 'w' }),
		test4: d('w', 'bar')
	}));

	o = new Foo();
	o.test = 'marko';
	a.deep(getOwnPropertyDescriptor(o, 'test'),
		{ configurable: false, enumerable: false, writable: true, value: 'marko' },
		"Set before get");
	o.test2 = 'marko2';
	a.deep(getOwnPropertyDescriptor(o, 'test2'),
		{ configurable: false, enumerable: false, writable: true, value: 'marko2' },
		"Set before get: Custom desc");
	o.test3 = 'marko3';
	a.deep(getOwnPropertyDescriptor(o, '__test3__'),
		{ configurable: false, enumerable: false, writable: true, value: 'marko3' },
		"Set before get: Custom cache name");
	a(o.test4, 'bar', "Resolve by value");

	a.h1("Flat");
	Object.defineProperties(Foo.prototype, t({
		flat: d(function () { return 'foo'; }, { flat: true }),
		flat2: d(function () { return 'bar'; }, { flat: true })
	}));

	a.h2("Instance");
	a(o.flat, 'foo', "Value");
	a(o.hasOwnProperty('flat'), false, "Instance");
	a(Foo.prototype.flat, 'foo', "Prototype");

	a.h2("Direct");
	a(Foo.prototype.flat2, 'bar');
};