Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(657)

Side by Side Diff: src/js/weak-collection.js

Issue 2222893002: Move family of MakeError functions to C++ (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Fix in prologue.js Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 (function(global, utils) { 5 (function(global, utils) {
6 6
7 "use strict"; 7 "use strict";
8 8
9 %CheckIsBootstrapping(); 9 %CheckIsBootstrapping();
10 10
11 // ------------------------------------------------------------------- 11 // -------------------------------------------------------------------
12 // Imports 12 // Imports
13 13
14 var GetExistingHash; 14 var GetExistingHash;
15 var GetHash; 15 var GetHash;
16 var GlobalObject = global.Object; 16 var GlobalObject = global.Object;
17 var GlobalWeakMap = global.WeakMap; 17 var GlobalWeakMap = global.WeakMap;
18 var GlobalWeakSet = global.WeakSet; 18 var GlobalWeakSet = global.WeakSet;
19 var MakeTypeError;
20 var toStringTagSymbol = utils.ImportNow("to_string_tag_symbol"); 19 var toStringTagSymbol = utils.ImportNow("to_string_tag_symbol");
21 20
22 utils.Import(function(from) { 21 utils.Import(function(from) {
23 GetExistingHash = from.GetExistingHash; 22 GetExistingHash = from.GetExistingHash;
24 GetHash = from.GetHash; 23 GetHash = from.GetHash;
25 MakeTypeError = from.MakeTypeError;
26 }); 24 });
27 25
28 // ------------------------------------------------------------------- 26 // -------------------------------------------------------------------
29 // Harmony WeakMap 27 // Harmony WeakMap
30 28
31 function WeakMapConstructor(iterable) { 29 function WeakMapConstructor(iterable) {
32 if (IS_UNDEFINED(new.target)) { 30 if (IS_UNDEFINED(new.target)) {
33 throw MakeTypeError(kConstructorNotFunction, "WeakMap"); 31 throw %make_type_error(kConstructorNotFunction, "WeakMap");
34 } 32 }
35 33
36 %WeakCollectionInitialize(this); 34 %WeakCollectionInitialize(this);
37 35
38 if (!IS_NULL_OR_UNDEFINED(iterable)) { 36 if (!IS_NULL_OR_UNDEFINED(iterable)) {
39 var adder = this.set; 37 var adder = this.set;
40 if (!IS_CALLABLE(adder)) { 38 if (!IS_CALLABLE(adder)) {
41 throw MakeTypeError(kPropertyNotFunction, adder, 'set', this); 39 throw %make_type_error(kPropertyNotFunction, adder, 'set', this);
42 } 40 }
43 for (var nextItem of iterable) { 41 for (var nextItem of iterable) {
44 if (!IS_RECEIVER(nextItem)) { 42 if (!IS_RECEIVER(nextItem)) {
45 throw MakeTypeError(kIteratorValueNotAnObject, nextItem); 43 throw %make_type_error(kIteratorValueNotAnObject, nextItem);
46 } 44 }
47 %_Call(adder, this, nextItem[0], nextItem[1]); 45 %_Call(adder, this, nextItem[0], nextItem[1]);
48 } 46 }
49 } 47 }
50 } 48 }
51 49
52 50
53 function WeakMapGet(key) { 51 function WeakMapGet(key) {
54 if (!IS_WEAKMAP(this)) { 52 if (!IS_WEAKMAP(this)) {
55 throw MakeTypeError(kIncompatibleMethodReceiver, 53 throw %make_type_error(kIncompatibleMethodReceiver,
56 'WeakMap.prototype.get', this); 54 'WeakMap.prototype.get', this);
57 } 55 }
58 if (!IS_RECEIVER(key)) return UNDEFINED; 56 if (!IS_RECEIVER(key)) return UNDEFINED;
59 var hash = GetExistingHash(key); 57 var hash = GetExistingHash(key);
60 if (IS_UNDEFINED(hash)) return UNDEFINED; 58 if (IS_UNDEFINED(hash)) return UNDEFINED;
61 return %WeakCollectionGet(this, key, hash); 59 return %WeakCollectionGet(this, key, hash);
62 } 60 }
63 61
64 62
65 function WeakMapSet(key, value) { 63 function WeakMapSet(key, value) {
66 if (!IS_WEAKMAP(this)) { 64 if (!IS_WEAKMAP(this)) {
67 throw MakeTypeError(kIncompatibleMethodReceiver, 65 throw %make_type_error(kIncompatibleMethodReceiver,
68 'WeakMap.prototype.set', this); 66 'WeakMap.prototype.set', this);
69 } 67 }
70 if (!IS_RECEIVER(key)) throw MakeTypeError(kInvalidWeakMapKey); 68 if (!IS_RECEIVER(key)) throw %make_type_error(kInvalidWeakMapKey);
71 return %WeakCollectionSet(this, key, value, GetHash(key)); 69 return %WeakCollectionSet(this, key, value, GetHash(key));
72 } 70 }
73 71
74 72
75 function WeakMapHas(key) { 73 function WeakMapHas(key) {
76 if (!IS_WEAKMAP(this)) { 74 if (!IS_WEAKMAP(this)) {
77 throw MakeTypeError(kIncompatibleMethodReceiver, 75 throw %make_type_error(kIncompatibleMethodReceiver,
78 'WeakMap.prototype.has', this); 76 'WeakMap.prototype.has', this);
79 } 77 }
80 if (!IS_RECEIVER(key)) return false; 78 if (!IS_RECEIVER(key)) return false;
81 var hash = GetExistingHash(key); 79 var hash = GetExistingHash(key);
82 if (IS_UNDEFINED(hash)) return false; 80 if (IS_UNDEFINED(hash)) return false;
83 return %WeakCollectionHas(this, key, hash); 81 return %WeakCollectionHas(this, key, hash);
84 } 82 }
85 83
86 84
87 function WeakMapDelete(key) { 85 function WeakMapDelete(key) {
88 if (!IS_WEAKMAP(this)) { 86 if (!IS_WEAKMAP(this)) {
89 throw MakeTypeError(kIncompatibleMethodReceiver, 87 throw %make_type_error(kIncompatibleMethodReceiver,
90 'WeakMap.prototype.delete', this); 88 'WeakMap.prototype.delete', this);
91 } 89 }
92 if (!IS_RECEIVER(key)) return false; 90 if (!IS_RECEIVER(key)) return false;
93 var hash = GetExistingHash(key); 91 var hash = GetExistingHash(key);
94 if (IS_UNDEFINED(hash)) return false; 92 if (IS_UNDEFINED(hash)) return false;
95 return %WeakCollectionDelete(this, key, hash); 93 return %WeakCollectionDelete(this, key, hash);
96 } 94 }
97 95
98 96
99 // ------------------------------------------------------------------- 97 // -------------------------------------------------------------------
(...skipping 12 matching lines...) Expand all
112 "set", WeakMapSet, 110 "set", WeakMapSet,
113 "has", WeakMapHas, 111 "has", WeakMapHas,
114 "delete", WeakMapDelete 112 "delete", WeakMapDelete
115 ]); 113 ]);
116 114
117 // ------------------------------------------------------------------- 115 // -------------------------------------------------------------------
118 // Harmony WeakSet 116 // Harmony WeakSet
119 117
120 function WeakSetConstructor(iterable) { 118 function WeakSetConstructor(iterable) {
121 if (IS_UNDEFINED(new.target)) { 119 if (IS_UNDEFINED(new.target)) {
122 throw MakeTypeError(kConstructorNotFunction, "WeakSet"); 120 throw %make_type_error(kConstructorNotFunction, "WeakSet");
123 } 121 }
124 122
125 %WeakCollectionInitialize(this); 123 %WeakCollectionInitialize(this);
126 124
127 if (!IS_NULL_OR_UNDEFINED(iterable)) { 125 if (!IS_NULL_OR_UNDEFINED(iterable)) {
128 var adder = this.add; 126 var adder = this.add;
129 if (!IS_CALLABLE(adder)) { 127 if (!IS_CALLABLE(adder)) {
130 throw MakeTypeError(kPropertyNotFunction, adder, 'add', this); 128 throw %make_type_error(kPropertyNotFunction, adder, 'add', this);
131 } 129 }
132 for (var value of iterable) { 130 for (var value of iterable) {
133 %_Call(adder, this, value); 131 %_Call(adder, this, value);
134 } 132 }
135 } 133 }
136 } 134 }
137 135
138 136
139 function WeakSetAdd(value) { 137 function WeakSetAdd(value) {
140 if (!IS_WEAKSET(this)) { 138 if (!IS_WEAKSET(this)) {
141 throw MakeTypeError(kIncompatibleMethodReceiver, 139 throw %make_type_error(kIncompatibleMethodReceiver,
142 'WeakSet.prototype.add', this); 140 'WeakSet.prototype.add', this);
143 } 141 }
144 if (!IS_RECEIVER(value)) throw MakeTypeError(kInvalidWeakSetValue); 142 if (!IS_RECEIVER(value)) throw %make_type_error(kInvalidWeakSetValue);
145 return %WeakCollectionSet(this, value, true, GetHash(value)); 143 return %WeakCollectionSet(this, value, true, GetHash(value));
146 } 144 }
147 145
148 146
149 function WeakSetHas(value) { 147 function WeakSetHas(value) {
150 if (!IS_WEAKSET(this)) { 148 if (!IS_WEAKSET(this)) {
151 throw MakeTypeError(kIncompatibleMethodReceiver, 149 throw %make_type_error(kIncompatibleMethodReceiver,
152 'WeakSet.prototype.has', this); 150 'WeakSet.prototype.has', this);
153 } 151 }
154 if (!IS_RECEIVER(value)) return false; 152 if (!IS_RECEIVER(value)) return false;
155 var hash = GetExistingHash(value); 153 var hash = GetExistingHash(value);
156 if (IS_UNDEFINED(hash)) return false; 154 if (IS_UNDEFINED(hash)) return false;
157 return %WeakCollectionHas(this, value, hash); 155 return %WeakCollectionHas(this, value, hash);
158 } 156 }
159 157
160 158
161 function WeakSetDelete(value) { 159 function WeakSetDelete(value) {
162 if (!IS_WEAKSET(this)) { 160 if (!IS_WEAKSET(this)) {
163 throw MakeTypeError(kIncompatibleMethodReceiver, 161 throw %make_type_error(kIncompatibleMethodReceiver,
164 'WeakSet.prototype.delete', this); 162 'WeakSet.prototype.delete', this);
165 } 163 }
166 if (!IS_RECEIVER(value)) return false; 164 if (!IS_RECEIVER(value)) return false;
167 var hash = GetExistingHash(value); 165 var hash = GetExistingHash(value);
168 if (IS_UNDEFINED(hash)) return false; 166 if (IS_UNDEFINED(hash)) return false;
169 return %WeakCollectionDelete(this, value, hash); 167 return %WeakCollectionDelete(this, value, hash);
170 } 168 }
171 169
172 170
173 // ------------------------------------------------------------------- 171 // -------------------------------------------------------------------
174 172
175 %SetCode(GlobalWeakSet, WeakSetConstructor); 173 %SetCode(GlobalWeakSet, WeakSetConstructor);
176 %FunctionSetLength(GlobalWeakSet, 0); 174 %FunctionSetLength(GlobalWeakSet, 0);
177 %FunctionSetPrototype(GlobalWeakSet, new GlobalObject()); 175 %FunctionSetPrototype(GlobalWeakSet, new GlobalObject());
178 %AddNamedProperty(GlobalWeakSet.prototype, "constructor", GlobalWeakSet, 176 %AddNamedProperty(GlobalWeakSet.prototype, "constructor", GlobalWeakSet,
179 DONT_ENUM); 177 DONT_ENUM);
180 %AddNamedProperty(GlobalWeakSet.prototype, toStringTagSymbol, "WeakSet", 178 %AddNamedProperty(GlobalWeakSet.prototype, toStringTagSymbol, "WeakSet",
181 DONT_ENUM | READ_ONLY); 179 DONT_ENUM | READ_ONLY);
182 180
183 // Set up the non-enumerable functions on the WeakSet prototype object. 181 // Set up the non-enumerable functions on the WeakSet prototype object.
184 utils.InstallFunctions(GlobalWeakSet.prototype, DONT_ENUM, [ 182 utils.InstallFunctions(GlobalWeakSet.prototype, DONT_ENUM, [
185 "add", WeakSetAdd, 183 "add", WeakSetAdd,
186 "has", WeakSetHas, 184 "has", WeakSetHas,
187 "delete", WeakSetDelete 185 "delete", WeakSetDelete
188 ]); 186 ]);
189 187
190 }) 188 })
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698