Debian Codegraph @

js/src/vm/RealmFuses.cpp

raw
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2 * vim: set ts=8 sts=2 et sw=2 tw=80:
3 * This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 #include "vm/RealmFuses.h"
7
8 #include "builtin/MapObject.h"
9 #include "builtin/Promise.h"
10 #include "builtin/RegExp.h"
11 #include "builtin/WeakMapObject.h"
12 #include "builtin/WeakSetObject.h"
13 #include "vm/GlobalObject.h"
14 #include "vm/NativeObject.h"
15 #include "vm/ObjectOperations.h"
16 #include "vm/Realm.h"
17 #include "vm/SelfHosting.h"
18
19 #include "vm/JSObject-inl.h"
20
21 using namespace js;
22
23 void js::InvalidatingRealmFuse::popFuse(JSContext* cx, RealmFuses& realmFuses) {
24 InvalidatingFuse::popFuse(cx);
25
26 for (auto& fd : realmFuses.fuseDependencies) {
27 fd.invalidateForFuse(cx, this);
28 }
29 }
30
31 bool js::InvalidatingRealmFuse::addFuseDependency(JSContext* cx,
32 Handle<JSScript*> script) {
33 MOZ_ASSERT(script->realm() == cx->realm());
34 auto* dss =
35 cx->realm()->realmFuses.fuseDependencies.getOrCreateDependentScriptSet(
36 cx, this);
37 if (!dss) {
38 return false;
39 }
40
41 return dss->addScriptForFuse(this, script);
42 }
43
44 void js::PopsOptimizedGetIteratorFuse::popFuse(JSContext* cx,
45 RealmFuses& realmFuses) {
46 // Pop Self.
47 RealmFuse::popFuse(cx);
48
49 // Pop associated fuse in same realm as current object.
50 realmFuses.optimizeGetIteratorFuse.popFuse(cx, realmFuses);
51 }
52
53 void js::PopsOptimizedArrayIteratorPrototypeFuse::popFuse(
54 JSContext* cx, RealmFuses& realmFuses) {
55 // Pop Self.
56 RealmFuse::popFuse(cx);
57
58 // Pop associated fuse in same realm as current object.
59 realmFuses.optimizeArrayIteratorPrototypeFuse.popFuse(cx, realmFuses);
60 }
61
62 int32_t js::RealmFuses::fuseOffsets[uint8_t(
63 RealmFuses::FuseIndex::LastFuseIndex)] = {
64 #define FUSE(Name, LowerName) offsetof(RealmFuses, LowerName),
65 FOR_EACH_REALM_FUSE(FUSE)
66 #undef FUSE
67 };
68
69 // static
70 int32_t js::RealmFuses::offsetOfFuseWordRelativeToRealm(
71 RealmFuses::FuseIndex index) {
72 int32_t base_offset = offsetof(Realm, realmFuses);
73 int32_t fuse_offset = RealmFuses::fuseOffsets[uint8_t(index)];
74 int32_t fuseWordOffset = GuardFuse::fuseOffset();
75
76 return base_offset + fuse_offset + fuseWordOffset;
77 }
78
79 const char* js::RealmFuses::fuseNames[] = {
80 #define FUSE(Name, LowerName) #LowerName,
81 FOR_EACH_REALM_FUSE(FUSE)
82 #undef FUSE
83 };
84
85 // TODO: It is not elegant that we have both this mechanism, but also
86 // GuardFuse::name, and all the overrides for naming fuses. The issue is
87 // that this method is static to handle consumers that don't have a
88 // RealmFuses around but work with indexes (e.g. spew code).
89 //
90 // I'd love it if we had a better answer.
91 const char* js::RealmFuses::getFuseName(RealmFuses::FuseIndex index) {
92 uint8_t rawIndex = uint8_t(index);
93 MOZ_ASSERT(index < RealmFuses::FuseIndex::LastFuseIndex);
94 return fuseNames[rawIndex];
95 }
96
97 bool js::OptimizeGetIteratorFuse::checkInvariant(JSContext* cx) {
98 // Simple invariant: this fuse merely reflects the conjunction of a group of
99 // fuses, so if this fuse is intact, then the invariant it asserts is that
100 // these two realm fuses are also intact.
101 auto& realmFuses = cx->realm()->realmFuses;
102 return realmFuses.arrayPrototypeIteratorFuse.intact() &&
103 realmFuses.optimizeArrayIteratorPrototypeFuse.intact();
104 }
105
106 void js::OptimizeGetIteratorFuse::popFuse(JSContext* cx,
107 RealmFuses& realmFuses) {
108 InvalidatingRealmFuse::popFuse(cx, realmFuses);
109 MOZ_ASSERT(cx->global());
110 cx->runtime()->setUseCounter(cx->global(),
111 JSUseCounter::OPTIMIZE_GET_ITERATOR_FUSE);
112 }
113
114 bool js::OptimizeArrayIteratorPrototypeFuse::checkInvariant(JSContext* cx) {
115 // Simple invariant: this fuse merely reflects the conjunction of a group of
116 // fuses, so if this fuse is intact, then the invariant it asserts is that
117 // these realm fuses are also intact.
118 auto& realmFuses = cx->realm()->realmFuses;
119 return realmFuses.arrayPrototypeIteratorNextFuse.intact() &&
120 realmFuses.arrayIteratorPrototypeHasNoReturnProperty.intact() &&
121 realmFuses.iteratorPrototypeHasNoReturnProperty.intact() &&
122 realmFuses.arrayIteratorPrototypeHasIteratorProto.intact() &&
123 realmFuses.iteratorPrototypeHasObjectProto.intact() &&
124 realmFuses.objectPrototypeHasNoReturnProperty.intact();
125 }
126
127 static bool ObjectHasDataProperty(NativeObject* obj, PropertyKey key,
128 Value* val) {
129 mozilla::Maybe<PropertyInfo> prop = obj->lookupPure(key);
130 if (prop.isNothing() || !prop->isDataProperty()) {
131 return false;
132 }
133 *val = obj->getSlot(prop->slot());
134 return true;
135 }
136
137 // Returns true if `obj` has a data property with the given `key` and its value
138 // is `expectedValue`.
139 static bool ObjectHasDataPropertyValue(NativeObject* obj, PropertyKey key,
140 const Value& expectedValue) {
141 Value v;
142 if (!ObjectHasDataProperty(obj, key, &v)) {
143 return false;
144 }
145 return v == expectedValue;
146 }
147
148 // Returns true if `obj` has a data property with the given `key` and its value
149 // is a native function that matches `expectedFunction`.
150 static bool ObjectHasDataPropertyFunction(NativeObject* obj, PropertyKey key,
151 JSNative expectedFunction) {
152 Value v;
153 if (!ObjectHasDataProperty(obj, key, &v)) {
154 return false;
155 }
156 if (!IsNativeFunction(v, expectedFunction)) {
157 return false;
158 }
159 if (obj->realm() != v.toObject().as<JSFunction>().realm()) {
160 return false;
161 }
162 return true;
163 }
164
165 // Returns true if `obj` has a data property with the given `key` and its value
166 // is a self-hosted function with `selfHostedName`.
167 static bool ObjectHasDataPropertyFunction(NativeObject* obj, PropertyKey key,
168 PropertyName* selfHostedName) {
169 Value v;
170 if (!ObjectHasDataProperty(obj, key, &v)) {
171 return false;
172 }
173 if (!IsSelfHostedFunctionWithName(v, selfHostedName)) {
174 return false;
175 }
176 if (obj->realm() != v.toObject().as<JSFunction>().realm()) {
177 return false;
178 }
179 return true;
180 }
181
182 static bool ObjectHasGetterProperty(NativeObject* obj, PropertyKey key,
183 JSFunction** getter) {
184 mozilla::Maybe<PropertyInfo> prop = obj->lookupPure(key);
185 if (prop.isNothing() || !prop->isAccessorProperty()) {
186 return false;
187 }
188 JSObject* getterObject = obj->getGetter(*prop);
189 if (!getterObject || !getterObject->is<JSFunction>()) {
190 return false;
191 }
192 if (obj->realm() != getterObject->as<JSFunction>().realm()) {
193 return false;
194 }
195 *getter = &getterObject->as<JSFunction>();
196 return true;
197 }
198
199 // Returns true if `obj` has an accessor property with the given `key` and the
200 // getter is a native function that matches `expectedFunction`.
201 static bool ObjectHasGetterFunction(NativeObject* obj, PropertyKey key,
202 JSNative expectedGetter) {
203 JSFunction* getter;
204 if (!ObjectHasGetterProperty(obj, key, &getter)) {
205 return false;
206 }
207 return IsNativeFunction(getter, expectedGetter);
208 }
209
210 // Returns true if `obj` has an accessor property with the given `key` and the
211 // getter is a self-hosted function with `selfHostedName`.
212 static bool ObjectHasGetterFunction(NativeObject* obj, PropertyKey key,
213 PropertyName* selfHostedName) {
214 JSFunction* getter;
215 if (!ObjectHasGetterProperty(obj, key, &getter)) {
216 return false;
217 }
218 return IsSelfHostedFunctionWithName(getter, selfHostedName);
219 }
220
221 bool js::ArrayPrototypeIteratorFuse::checkInvariant(JSContext* cx) {
222 // Prototype must be Array.prototype.
223 auto* proto = cx->global()->maybeGetArrayPrototype();
224 if (!proto) {
225 // No proto, invariant still holds
226 return true;
227 }
228
229 PropertyKey iteratorKey =
230 PropertyKey::Symbol(cx->wellKnownSymbols().iterator);
231
232 // Ensure that Array.prototype's @@iterator slot is unchanged.
233 return ObjectHasDataPropertyFunction(proto, iteratorKey,
234 cx->names().dollar_ArrayValues_);
235 }
236
237 /* static */
238 bool js::ArrayPrototypeIteratorNextFuse::checkInvariant(JSContext* cx) {
239 auto* proto = cx->global()->maybeGetArrayIteratorPrototype();
240
241 if (!proto) {
242 // Invariant holds if there is no array iterator proto.
243 return true;
244 }
245
246 // Ensure that %ArrayIteratorPrototype%'s "next" slot is unchanged.
247 return ObjectHasDataPropertyFunction(proto, NameToId(cx->names().next),
248 cx->names().ArrayIteratorNext);
249 }
250
251 static bool HasNoReturnName(JSContext* cx, JS::HandleObject proto) {
252 if (!proto) {
253 // Invariant holds if there is no array iterator proto.
254 return true;
255 }
256
257 JS::RootedId returnName(cx, NameToId(cx->names().return_));
258
259 // An alternative design here would chain together all the has-return-property
260 // fuses such that the fuses each express a stronger invariant; for now these
261 // fuses have only the invariant that each object -itself- has no return
262 // property.
263 bool found = true;
264 if (!HasOwnProperty(cx, proto, returnName, &found)) {
265 cx->recoverFromOutOfMemory();
266 return true;
267 }
268
269 return !found;
270 }
271
272 /* static */
273 bool js::ArrayIteratorPrototypeHasNoReturnProperty::checkInvariant(
274 JSContext* cx) {
275 RootedObject proto(cx, cx->global()->maybeGetArrayIteratorPrototype());
276
277 if (!proto) {
278 // Invariant holds if there is no array iterator proto.
279 return true;
280 }
281
282 return HasNoReturnName(cx, proto);
283 }
284
285 /* static */
286 bool js::IteratorPrototypeHasNoReturnProperty::checkInvariant(JSContext* cx) {
287 RootedObject proto(cx, cx->global()->maybeGetIteratorPrototype());
288
289 if (!proto) {
290 // Invariant holds if there is no array iterator proto.
291 return true;
292 }
293
294 return HasNoReturnName(cx, proto);
295 }
296
297 /* static */
298 bool js::ArrayIteratorPrototypeHasIteratorProto::checkInvariant(JSContext* cx) {
299 RootedObject proto(cx, cx->global()->maybeGetArrayIteratorPrototype());
300 if (!proto) {
301 // Invariant holds if there is no array iterator proto.
302 return true;
303 }
304
305 RootedObject iterProto(cx, cx->global()->maybeGetIteratorPrototype());
306 if (!iterProto) {
307 MOZ_CRASH("Can we have the array iter proto without the iterator proto?");
308 return true;
309 }
310
311 return proto->staticPrototype() == iterProto;
312 }
313
314 /* static */
315 bool js::IteratorPrototypeHasObjectProto::checkInvariant(JSContext* cx) {
316 RootedObject proto(cx, cx->global()->maybeGetIteratorPrototype());
317 if (!proto) {
318 // Invariant holds if there is no array iterator proto.
319 return true;
320 }
321
322 return proto->staticPrototype() == &cx->global()->getObjectPrototype();
323 }
324
325 /* static */
326 bool js::ObjectPrototypeHasNoReturnProperty::checkInvariant(JSContext* cx) {
327 RootedObject proto(cx, &cx->global()->getObjectPrototype());
328 return HasNoReturnName(cx, proto);
329 }
330
331 void js::OptimizeArraySpeciesFuse::popFuse(JSContext* cx,
332 RealmFuses& realmFuses) {
333 InvalidatingRealmFuse::popFuse(cx, realmFuses);
334 MOZ_ASSERT(cx->global());
335 cx->runtime()->setUseCounter(cx->global(),
336 JSUseCounter::OPTIMIZE_ARRAY_SPECIES_FUSE);
337 }
338
339 static bool SpeciesFuseCheckInvariant(JSContext* cx, JSProtoKey protoKey,
340 PropertyName* selfHostedSpeciesAccessor) {
341 // Prototype must be initialized.
342 auto* proto = cx->global()->maybeGetPrototype<NativeObject>(protoKey);
343 if (!proto) {
344 // No proto, invariant still holds
345 return true;
346 }
347
348 auto* ctor = cx->global()->maybeGetConstructor<NativeObject>(protoKey);
349 MOZ_ASSERT(ctor);
350
351 // Ensure the prototype's `constructor` slot is the original constructor.
352 if (!ObjectHasDataPropertyValue(proto, NameToId(cx->names().constructor),
353 ObjectValue(*ctor))) {
354 return false;
355 }
356
357 // Ensure constructor's `@@species` slot is the original species getter.
358 PropertyKey speciesKey = PropertyKey::Symbol(cx->wellKnownSymbols().species);
359 return ObjectHasGetterFunction(ctor, speciesKey, selfHostedSpeciesAccessor);
360 }
361
362 bool js::OptimizeArraySpeciesFuse::checkInvariant(JSContext* cx) {
363 return SpeciesFuseCheckInvariant(cx, JSProto_Array,
364 cx->names().dollar_ArraySpecies_);
365 }
366
367 bool js::OptimizeArrayBufferSpeciesFuse::checkInvariant(JSContext* cx) {
368 return SpeciesFuseCheckInvariant(cx, JSProto_ArrayBuffer,
369 cx->names().dollar_ArrayBufferSpecies_);
370 }
371
372 bool js::OptimizeSharedArrayBufferSpeciesFuse::checkInvariant(JSContext* cx) {
373 return SpeciesFuseCheckInvariant(
374 cx, JSProto_SharedArrayBuffer,
375 cx->names().dollar_SharedArrayBufferSpecies_);
376 }
377
378 void js::OptimizePromiseLookupFuse::popFuse(JSContext* cx,
379 RealmFuses& realmFuses) {
380 RealmFuse::popFuse(cx, realmFuses);
381 MOZ_ASSERT(cx->global());
382 cx->runtime()->setUseCounter(cx->global(),
383 JSUseCounter::OPTIMIZE_PROMISE_LOOKUP_FUSE);
384 }
385
386 bool js::OptimizePromiseLookupFuse::checkInvariant(JSContext* cx) {
387 // Prototype must be Promise.prototype.
388 auto* proto = cx->global()->maybeGetPrototype<NativeObject>(JSProto_Promise);
389 if (!proto) {
390 // No proto, invariant still holds.
391 return true;
392 }
393
394 auto* ctor = cx->global()->maybeGetConstructor<NativeObject>(JSProto_Promise);
395 MOZ_ASSERT(ctor);
396
397 // Ensure Promise.prototype's `constructor` slot is the `Promise` constructor.
398 if (!ObjectHasDataPropertyValue(proto, NameToId(cx->names().constructor),
399 ObjectValue(*ctor))) {
400 return false;
401 }
402
403 // Ensure Promise.prototype's `then` slot is the original function.
404 if (!ObjectHasDataPropertyFunction(proto, NameToId(cx->names().then),
405 js::Promise_then)) {
406 return false;
407 }
408
409 // Ensure Promise's `@@species` slot is the original getter.
410 PropertyKey speciesKey = PropertyKey::Symbol(cx->wellKnownSymbols().species);
411 if (!ObjectHasGetterFunction(ctor, speciesKey, js::Promise_static_species)) {
412 return false;
413 }
414
415 // Ensure Promise's `resolve` slot is the original function.
416 if (!ObjectHasDataPropertyFunction(ctor, NameToId(cx->names().resolve),
417 js::Promise_static_resolve)) {
418 return false;
419 }
420
421 return true;
422 }
423
424 bool js::OptimizeRegExpPrototypeFuse::checkInvariant(JSContext* cx) {
425 auto* proto = cx->global()->maybeGetPrototype<NativeObject>(JSProto_RegExp);
426 if (!proto) {
427 // No proto, invariant still holds.
428 return true;
429 }
430
431 // Check getters are unchanged.
432 if (!ObjectHasGetterFunction(proto, NameToId(cx->names().flags),
433 cx->names().dollar_RegExpFlagsGetter_)) {
434 return false;
435 }
436 if (!ObjectHasGetterFunction(proto, NameToId(cx->names().global),
437 regexp_global)) {
438 return false;
439 }
440 if (!ObjectHasGetterFunction(proto, NameToId(cx->names().hasIndices),
441 regexp_hasIndices)) {
442 return false;
443 }
444 if (!ObjectHasGetterFunction(proto, NameToId(cx->names().ignoreCase),
445 regexp_ignoreCase)) {
446 return false;
447 }
448 if (!ObjectHasGetterFunction(proto, NameToId(cx->names().multiline),
449 regexp_multiline)) {
450 return false;
451 }
452 if (!ObjectHasGetterFunction(proto, NameToId(cx->names().sticky),
453 regexp_sticky)) {
454 return false;
455 }
456 if (!ObjectHasGetterFunction(proto, NameToId(cx->names().unicode),
457 regexp_unicode)) {
458 return false;
459 }
460 if (!ObjectHasGetterFunction(proto, NameToId(cx->names().unicodeSets),
461 regexp_unicodeSets)) {
462 return false;
463 }
464 if (!ObjectHasGetterFunction(proto, NameToId(cx->names().dotAll),
465 regexp_dotAll)) {
466 return false;
467 }
468
469 // Check data properties are unchanged.
470 if (!ObjectHasDataPropertyFunction(proto, NameToId(cx->names().exec),
471 cx->names().RegExp_prototype_Exec)) {
472 return false;
473 }
474 if (!ObjectHasDataPropertyFunction(
475 proto, PropertyKey::Symbol(cx->wellKnownSymbols().match),
476 cx->names().RegExpMatch)) {
477 return false;
478 }
479 if (!ObjectHasDataPropertyFunction(
480 proto, PropertyKey::Symbol(cx->wellKnownSymbols().matchAll),
481 cx->names().RegExpMatchAll)) {
482 return false;
483 }
484 if (!ObjectHasDataPropertyFunction(
485 proto, PropertyKey::Symbol(cx->wellKnownSymbols().replace),
486 cx->names().RegExpReplace)) {
487 return false;
488 }
489 if (!ObjectHasDataPropertyFunction(
490 proto, PropertyKey::Symbol(cx->wellKnownSymbols().search),
491 cx->names().RegExpSearch)) {
492 return false;
493 }
494 if (!ObjectHasDataPropertyFunction(
495 proto, PropertyKey::Symbol(cx->wellKnownSymbols().split),
496 cx->names().RegExpSplit)) {
497 return false;
498 }
499
500 return true;
501 }
502
503 bool js::OptimizeStringPrototypeSymbolsFuse::checkInvariant(JSContext* cx) {
504 auto* stringProto =
505 cx->global()->maybeGetPrototype<NativeObject>(JSProto_String);
506 if (!stringProto) {
507 // No proto, invariant still holds.
508 return true;
509 }
510
511 // String.prototype must have Object.prototype as proto.
512 auto* objectProto = &cx->global()->getObjectPrototype().as<NativeObject>();
513 if (stringProto->staticPrototype() != objectProto) {
514 return false;
515 }
516
517 // The objects must not have a @@match, @@replace, @@search, @@split property.
518 auto hasSymbolProp = [&](JS::Symbol* symbol) {
519 PropertyKey key = PropertyKey::Symbol(symbol);
520 return stringProto->containsPure(key) || objectProto->containsPure(key);
521 };
522 if (hasSymbolProp(cx->wellKnownSymbols().match) ||
523 hasSymbolProp(cx->wellKnownSymbols().replace) ||
524 hasSymbolProp(cx->wellKnownSymbols().search) ||
525 hasSymbolProp(cx->wellKnownSymbols().split)) {
526 return false;
527 }
528
529 return true;
530 }
531
532 bool js::OptimizeMapObjectIteratorFuse::checkInvariant(JSContext* cx) {
533 // Ensure Map.prototype's @@iterator slot is unchanged.
534 auto* proto = cx->global()->maybeGetPrototype<NativeObject>(JSProto_Map);
535 if (!proto) {
536 // No proto, invariant still holds
537 return true;
538 }
539 PropertyKey iteratorKey =
540 PropertyKey::Symbol(cx->wellKnownSymbols().iterator);
541 if (!ObjectHasDataPropertyFunction(proto, iteratorKey, MapObject::entries)) {
542 return false;
543 }
544
545 // Ensure %MapIteratorPrototype%'s `next` slot is unchanged.
546 auto* iterProto = cx->global()->maybeBuiltinProto(
547 GlobalObject::ProtoKind::MapIteratorProto);
548 if (!iterProto) {
549 // No proto, invariant still holds
550 return true;
551 }
552 return ObjectHasDataPropertyFunction(&iterProto->as<NativeObject>(),
553 NameToId(cx->names().next),
554 cx->names().MapIteratorNext);
555 }
556
557 bool js::OptimizeSetObjectIteratorFuse::checkInvariant(JSContext* cx) {
558 // Ensure Set.prototype's @@iterator slot is unchanged.
559 auto* proto = cx->global()->maybeGetPrototype<NativeObject>(JSProto_Set);
560 if (!proto) {
561 // No proto, invariant still holds
562 return true;
563 }
564 PropertyKey iteratorKey =
565 PropertyKey::Symbol(cx->wellKnownSymbols().iterator);
566 if (!ObjectHasDataPropertyFunction(proto, iteratorKey, SetObject::values)) {
567 return false;
568 }
569
570 // Ensure %SetIteratorPrototype%'s `next` slot is unchanged.
571 auto* iterProto = cx->global()->maybeBuiltinProto(
572 GlobalObject::ProtoKind::SetIteratorProto);
573 if (!iterProto) {
574 // No proto, invariant still holds
575 return true;
576 }
577 return ObjectHasDataPropertyFunction(&iterProto->as<NativeObject>(),
578 NameToId(cx->names().next),
579 cx->names().SetIteratorNext);
580 }
581
582 bool js::OptimizeMapPrototypeSetFuse::checkInvariant(JSContext* cx) {
583 auto* proto = cx->global()->maybeGetPrototype<NativeObject>(JSProto_Map);
584 if (!proto) {
585 // No proto, invariant still holds
586 return true;
587 }
588 return ObjectHasDataPropertyFunction(proto, NameToId(cx->names().set),
589 MapObject::set);
590 }
591
592 bool js::OptimizeSetPrototypeAddFuse::checkInvariant(JSContext* cx) {
593 auto* proto = cx->global()->maybeGetPrototype<NativeObject>(JSProto_Set);
594 if (!proto) {
595 // No proto, invariant still holds
596 return true;
597 }
598 return ObjectHasDataPropertyFunction(proto, NameToId(cx->names().add),
599 SetObject::add);
600 }
601
602 bool js::OptimizeWeakMapPrototypeSetFuse::checkInvariant(JSContext* cx) {
603 auto* proto = cx->global()->maybeGetPrototype<NativeObject>(JSProto_WeakMap);
604 if (!proto) {
605 // No proto, invariant still holds
606 return true;
607 }
608 return ObjectHasDataPropertyFunction(proto, NameToId(cx->names().set),
609 WeakMapObject::set);
610 }
611
612 bool js::OptimizeWeakSetPrototypeAddFuse::checkInvariant(JSContext* cx) {
613 auto* proto = cx->global()->maybeGetPrototype<NativeObject>(JSProto_WeakSet);
614 if (!proto) {
615 // No proto, invariant still holds
616 return true;
617 }
618 return ObjectHasDataPropertyFunction(proto, NameToId(cx->names().add),
619 WeakSetObject::add);
620 }