1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
2 * vim: set ts=8 sw=4 et tw=78:
4 * ***** BEGIN LICENSE BLOCK *****
5 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
7 * The contents of this file are subject to the Mozilla Public License Version
8 * 1.1 (the "License"); you may not use this file except in compliance with
9 * the License. You may obtain a copy of the License at
10 * http://www.mozilla.org/MPL/
12 * Software distributed under the License is distributed on an "AS IS" basis,
13 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
14 * for the specific language governing rights and limitations under the
17 * The Original Code is Mozilla Communicator client code, released
20 * The Initial Developer of the Original Code is
21 * Netscape Communications Corporation.
22 * Portions created by the Initial Developer are Copyright (C) 1998
23 * the Initial Developer. All Rights Reserved.
27 * Alternatively, the contents of this file may be used under the terms of
28 * either of the GNU General Public License Version 2 or later (the "GPL"),
29 * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
30 * in which case the provisions of the GPL or the LGPL are applicable instead
31 * of those above. If you wish to allow use of your version of this file only
32 * under the terms of either the GPL or the LGPL, and not to allow others to
33 * use your version of this file under the terms of the MPL, indicate your
34 * decision by deleting the provisions above and replace them with the notice
35 * and other provisions required by the GPL or the LGPL. If you do not delete
36 * the provisions above, a recipient may use your version of this file under
37 * the terms of any one of the MPL, the GPL or the LGPL.
39 * ***** END LICENSE BLOCK ***** */
45 * JS object definitions.
47 * A JS object consists of a possibly-shared object descriptor containing
48 * ordered property names, called the map; and a dense vector of property
49 * values, called slots. The map/slot pointer pair is GC'ed, while the map
50 * is reference counted and the slot vector is malloc'ed.
55 #include "jsfriendapi.h"
62 #include "gc/Barrier.h"
65 #include "vm/ObjectImpl.h"
66 #include "vm/String.h"
70 class AutoPropDescArrayRooter
;
74 struct NativeIterator
;
76 namespace mjit
{ class Compiler
; }
79 CastAsObject(PropertyOp op
)
81 return JS_FUNC_TO_DATA_PTR(JSObject
*, op
);
85 CastAsObject(StrictPropertyOp op
)
87 return JS_FUNC_TO_DATA_PTR(JSObject
*, op
);
91 CastAsObjectJsval(PropertyOp op
)
93 return ObjectOrNullValue(CastAsObject(op
));
97 CastAsObjectJsval(StrictPropertyOp op
)
99 return ObjectOrNullValue(CastAsObject(op
));
103 * JSPropertySpec uses JSAPI JSPropertyOp and JSStrictPropertyOp in function
104 * signatures, but with JSPROP_NATIVE_ACCESSORS the actual values must be
105 * JSNatives. To avoid widespread casting, have JS_PSG and JS_PSGS perform
108 #define JS_PSG(name,getter,flags) \
109 {name, 0, (flags) | JSPROP_SHARED | JSPROP_NATIVE_ACCESSORS, \
110 (JSPropertyOp)getter, NULL}
111 #define JS_PSGS(name,getter,setter,flags) \
112 {name, 0, (flags) | JSPROP_SHARED | JSPROP_NATIVE_ACCESSORS, \
113 (JSPropertyOp)getter, (JSStrictPropertyOp)setter}
114 #define JS_PS_END {0, 0, 0, 0, 0}
116 /******************************************************************************/
118 typedef Vector
<PropDesc
, 1> PropDescArray
;
123 * On success, and if id was found, return true with *objp non-null and with a
124 * property of *objp stored in *propp. If successful but id was not found,
125 * return true with both *objp and *propp null.
127 extern JS_FRIEND_API(JSBool
)
128 js_LookupProperty(JSContext
*cx
, JSObject
*obj
, jsid id
, JSObject
**objp
,
134 LookupProperty(JSContext
*cx
, JSObject
*obj
, PropertyName
*name
,
135 JSObject
**objp
, JSProperty
**propp
)
137 return js_LookupProperty(cx
, obj
, NameToId(name
), objp
, propp
);
142 extern JS_FRIEND_API(JSBool
)
143 js_LookupElement(JSContext
*cx
, JSObject
*obj
, uint32_t index
,
144 JSObject
**objp
, JSProperty
**propp
);
147 js_DefineProperty(JSContext
*cx
, JSObject
*obj
, jsid id
, const js::Value
*value
,
148 JSPropertyOp getter
, JSStrictPropertyOp setter
, unsigned attrs
);
151 js_DefineElement(JSContext
*cx
, JSObject
*obj
, uint32_t index
, const js::Value
*value
,
152 JSPropertyOp getter
, JSStrictPropertyOp setter
, unsigned attrs
);
155 js_GetProperty(JSContext
*cx
, js::HandleObject obj
, js::HandleObject receiver
, jsid id
, js::Value
*vp
);
158 js_GetElement(JSContext
*cx
, js::HandleObject obj
, js::HandleObject receiver
, uint32_t, js::Value
*vp
);
161 js_GetProperty(JSContext
*cx
, js::HandleObject obj
, jsid id
, js::Value
*vp
)
163 return js_GetProperty(cx
, obj
, obj
, id
, vp
);
167 js_GetElement(JSContext
*cx
, js::HandleObject obj
, uint32_t index
, js::Value
*vp
)
169 return js_GetElement(cx
, obj
, obj
, index
, vp
);
175 GetPropertyDefault(JSContext
*cx
, js::HandleObject obj
, js::HandleId id
, const Value
&def
, Value
*vp
);
180 js_SetPropertyHelper(JSContext
*cx
, js::HandleObject obj
, jsid id
, unsigned defineHow
,
181 js::Value
*vp
, JSBool strict
);
186 SetPropertyHelper(JSContext
*cx
, HandleObject obj
, PropertyName
*name
, unsigned defineHow
,
187 Value
*vp
, JSBool strict
)
189 return !!js_SetPropertyHelper(cx
, obj
, NameToId(name
), defineHow
, vp
, strict
);
195 js_SetElementHelper(JSContext
*cx
, js::HandleObject obj
, uint32_t index
, unsigned defineHow
,
196 js::Value
*vp
, JSBool strict
);
199 js_GetAttributes(JSContext
*cx
, JSObject
*obj
, jsid id
, unsigned *attrsp
);
202 js_GetElementAttributes(JSContext
*cx
, JSObject
*obj
, uint32_t index
, unsigned *attrsp
);
205 js_SetAttributes(JSContext
*cx
, JSObject
*obj
, jsid id
, unsigned *attrsp
);
208 js_SetElementAttributes(JSContext
*cx
, JSObject
*obj
, uint32_t index
, unsigned *attrsp
);
211 js_DeleteProperty(JSContext
*cx
, JSObject
*obj
, js::PropertyName
*name
, js::Value
*rval
, JSBool strict
);
214 js_DeleteElement(JSContext
*cx
, JSObject
*obj
, uint32_t index
, js::Value
*rval
, JSBool strict
);
217 js_DeleteSpecial(JSContext
*cx
, JSObject
*obj
, js::SpecialId sid
, js::Value
*rval
, JSBool strict
);
220 js_DeleteGeneric(JSContext
*cx
, JSObject
*obj
, jsid id
, js::Value
*rval
, JSBool strict
);
223 js_TypeOf(JSContext
*cx
, JSObject
*obj
);
229 DefaultValue(JSContext
*cx
, HandleObject obj
, JSType hint
, Value
*vp
);
231 extern Class ArrayClass
;
232 extern Class ArrayBufferClass
;
233 extern Class BlockClass
;
234 extern Class BooleanClass
;
235 extern Class CallableObjectClass
;
236 extern Class DataViewClass
;
237 extern Class DateClass
;
238 extern Class ErrorClass
;
239 extern Class ElementIteratorClass
;
240 extern Class GeneratorClass
;
241 extern Class IteratorClass
;
242 extern Class JSONClass
;
243 extern Class MathClass
;
244 extern Class NumberClass
;
245 extern Class NormalArgumentsObjectClass
;
246 extern Class ObjectClass
;
247 extern Class ProxyClass
;
248 extern Class RegExpClass
;
249 extern Class RegExpStaticsClass
;
250 extern Class SlowArrayClass
;
251 extern Class StopIterationClass
;
252 extern Class StringClass
;
253 extern Class StrictArgumentsObjectClass
;
254 extern Class WeakMapClass
;
255 extern Class WithClass
;
256 extern Class XMLFilterClass
;
258 class ArgumentsObject
;
259 class ArrayBufferObject
;
262 class ClonedBlockObject
;
263 class DataViewObject
;
265 class ElementIteratorObject
;
267 class NestedScopeObject
;
268 class NewObjectCache
;
269 class NormalArgumentsObject
;
272 class StaticBlockObject
;
273 class StrictArgumentsObject
;
281 * The public interface for an object.
283 * Implementation of the underlying structure occurs in ObjectImpl, from which
284 * this struct inherits. This inheritance is currently public, but it will
285 * eventually be made protected. For full details, see vm/ObjectImpl.{h,cpp}.
287 * The JSFunction struct is an extension of this struct allocated from a larger
290 struct JSObject
: public js::ObjectImpl
293 friend struct js::Shape
;
294 friend struct js::GCMarker
;
295 friend class js::NewObjectCache
;
297 /* Make the type object to use for LAZY_TYPE objects. */
298 void makeLazyType(JSContext
*cx
);
302 * Update the last property, keeping the number of allocated slots in sync
303 * with the object's new slot span.
305 bool setLastProperty(JSContext
*cx
, const js::Shape
*shape
);
307 /* As above, but does not change the slot span. */
308 inline void setLastPropertyInfallible(const js::Shape
*shape
);
310 /* Make a non-array object with the specified initial state. */
311 static inline JSObject
*create(JSContext
*cx
,
312 js::gc::AllocKind kind
,
313 js::HandleShape shape
,
314 js::HandleTypeObject type
,
315 js::HeapSlot
*slots
);
317 /* Make a dense array object with the specified initial state. */
318 static inline JSObject
*createDenseArray(JSContext
*cx
,
319 js::gc::AllocKind kind
,
320 js::HandleShape shape
,
321 js::HandleTypeObject type
,
325 * Remove the last property of an object, provided that it is safe to do so
326 * (the shape and previous shape do not carry conflicting information about
327 * the object itself).
329 inline void removeLastProperty(JSContext
*cx
);
330 inline bool canRemoveLastProperty();
333 * Update the slot span directly for a dictionary object, and allocate
334 * slots to cover the new span if necessary.
336 bool setSlotSpan(JSContext
*cx
, uint32_t span
);
338 inline bool nativeContains(JSContext
*cx
, jsid id
);
339 inline bool nativeContains(JSContext
*cx
, const js::Shape
&shape
);
341 /* Upper bound on the number of elements in an object. */
342 static const uint32_t NELEMENTS_LIMIT
= JS_BIT(28);
345 inline bool setDelegate(JSContext
*cx
);
347 inline bool isBoundFunction() const;
350 * The meaning of the system object bit is defined by the API client. It is
351 * set in JS_NewSystemObject and is queried by JS_IsSystemObject, but it
352 * has no intrinsic meaning to SpiderMonkey.
354 inline bool isSystem() const;
355 inline bool setSystem(JSContext
*cx
);
357 inline bool hasSpecialEquality() const;
359 inline bool watched() const;
360 inline bool setWatched(JSContext
*cx
);
362 /* See StackFrame::varObj. */
363 inline bool isVarObj() const;
364 inline bool setVarObj(JSContext
*cx
);
367 * Objects with an uncacheable proto can have their prototype mutated
368 * without inducing a shape change on the object. Property cache entries
369 * and JIT inline caches should not be filled for lookups across prototype
370 * lookups on the object.
372 inline bool hasUncacheableProto() const;
373 inline bool setUncacheableProto(JSContext
*cx
);
375 bool generateOwnShape(JSContext
*cx
, js::Shape
*newShape
= NULL
) {
376 return replaceWithNewEquivalentShape(cx
, lastProperty(), newShape
);
380 js::Shape
*replaceWithNewEquivalentShape(JSContext
*cx
, js::Shape
*existingShape
,
381 js::Shape
*newShape
= NULL
);
388 bool setFlag(JSContext
*cx
, /*BaseShape::Flag*/ uint32_t flag
,
389 GenerateShape generateShape
= GENERATE_NONE
);
392 inline bool nativeEmpty() const;
394 bool shadowingShapeChange(JSContext
*cx
, const js::Shape
&shape
);
396 /* Whether there may be indexed properties on this object. */
397 inline bool isIndexed() const;
399 inline uint32_t propertyCount() const;
401 inline bool hasShapeTable() const;
403 inline size_t computedSizeOfThisSlotsElements() const;
405 inline void sizeOfExcludingThis(JSMallocSizeOfFun mallocSizeOf
,
406 size_t *slotsSize
, size_t *elementsSize
,
407 size_t *miscSize
) const;
409 static const uint32_t MAX_FIXED_SLOTS
= 16;
413 /* Accessors for properties. */
415 /* Whether a slot is at a fixed offset from this object. */
416 inline bool isFixedSlot(size_t slot
);
418 /* Index into the dynamic slots array to use for a dynamic slot. */
419 inline size_t dynamicSlotIndex(size_t slot
);
421 /* Get a raw pointer to the object's properties. */
422 inline const js::HeapSlot
*getRawSlots();
425 * Grow or shrink slots immediately before changing the slot span.
426 * The number of allocated slots is not stored explicitly, and changes to
427 * the slots must track changes in the slot span.
429 bool growSlots(JSContext
*cx
, uint32_t oldCount
, uint32_t newCount
);
430 void shrinkSlots(JSContext
*cx
, uint32_t oldCount
, uint32_t newCount
);
432 bool hasDynamicSlots() const { return slots
!= NULL
; }
435 inline bool updateSlotsForSpan(JSContext
*cx
, size_t oldSpan
, size_t newSpan
);
439 * Trigger the write barrier on a range of slots that will no longer be
442 inline void prepareSlotRangeForOverwrite(size_t start
, size_t end
);
443 inline void prepareElementRangeForOverwrite(size_t start
, size_t end
);
445 void rollbackProperties(JSContext
*cx
, uint32_t slotSpan
);
447 inline void nativeSetSlot(unsigned slot
, const js::Value
&value
);
448 inline void nativeSetSlotWithType(JSContext
*cx
, const js::Shape
*shape
, const js::Value
&value
);
450 inline const js::Value
&getReservedSlot(unsigned index
) const;
451 inline js::HeapSlot
&getReservedSlotRef(unsigned index
);
452 inline void initReservedSlot(unsigned index
, const js::Value
&v
);
453 inline void setReservedSlot(unsigned index
, const js::Value
&v
);
456 * Marks this object as having a singleton type, and leave the type lazy.
457 * Constructs a new, unique shape for the object.
459 inline bool setSingletonType(JSContext
*cx
);
461 inline js::types::TypeObject
*getType(JSContext
*cx
);
463 const js::HeapPtr
<js::types::TypeObject
> &typeFromGC() const {
464 /* Direct field access for use by GC. */
468 inline void setType(js::types::TypeObject
*newType
);
470 js::types::TypeObject
*getNewType(JSContext
*cx
, JSFunction
*fun
= NULL
);
473 bool hasNewType(js::types::TypeObject
*newType
);
477 * Mark an object that has been iterated over and is a singleton. We need
478 * to recover this information in the object's type information after it
481 inline bool setIteratedSingleton(JSContext
*cx
);
484 * Mark an object as requiring its default 'new' type to have unknown
487 bool setNewTypeUnknown(JSContext
*cx
);
489 /* Set a new prototype for an object with a singleton type. */
490 bool splicePrototype(JSContext
*cx
, JSObject
*proto
);
493 * For bootstrapping, whether to splice a prototype for Function.prototype
494 * or the global object.
496 bool shouldSplicePrototype(JSContext
*cx
);
499 * Parents and scope chains.
501 * All script-accessible objects with a NULL parent are global objects,
502 * and all global objects have a NULL parent. Some builtin objects which
503 * are not script-accessible also have a NULL parent, such as parser
504 * created functions for non-compileAndGo scripts.
506 * Except for the non-script-accessible builtins, the global with which an
507 * object is associated can be reached by following parent links to that
508 * global (see global()).
510 * The scope chain of an object is the link in the search path when a
511 * script does a name lookup on a scope object. For JS internal scope
512 * objects --- Call, DeclEnv and block --- the chain is stored in
513 * the first fixed slot of the object, and the object's parent is the
514 * associated global. For other scope objects, the chain is stored in the
517 * In compileAndGo code, scope chains can contain only internal scope
518 * objects with a global object at the root as the scope of the outermost
519 * non-function script. In non-compileAndGo code, the scope of the
520 * outermost non-function script might not be a global object, and can have
521 * a mix of other objects above it before the global object is reached.
524 /* Access the parent link of an object. */
525 inline JSObject
*getParent() const;
526 static bool setParent(JSContext
*cx
, js::HandleObject obj
, js::HandleObject newParent
);
529 * Get the enclosing scope of an object. When called on non-scope object,
530 * this will just be the global (the name "enclosing scope" still applies
531 * in this situation because non-scope objects can be on the scope chain).
533 inline JSObject
*enclosingScope();
535 inline js::GlobalObject
&global() const;
537 /* N.B. Infallible: NULL means 'no principal', not an error. */
538 inline JSPrincipals
*principals(JSContext
*cx
);
540 /* Remove the type (and prototype) or parent from a new object. */
541 inline bool clearType(JSContext
*cx
);
542 bool clearParent(JSContext
*cx
);
545 * ES5 meta-object properties and operations.
549 enum ImmutabilityType
{ SEAL
, FREEZE
};
552 * The guts of Object.seal (ES5 15.2.3.8) and Object.freeze (ES5 15.2.3.9): mark the
553 * object as non-extensible, and adjust each property's attributes appropriately: each
554 * property becomes non-configurable, and if |freeze|, data properties become
557 bool sealOrFreeze(JSContext
*cx
, ImmutabilityType it
);
559 bool isSealedOrFrozen(JSContext
*cx
, ImmutabilityType it
, bool *resultp
);
561 static inline unsigned getSealedOrFrozenAttributes(unsigned attrs
, ImmutabilityType it
);
564 bool preventExtensions(JSContext
*cx
);
566 /* ES5 15.2.3.8: non-extensible, all props non-configurable */
567 inline bool seal(JSContext
*cx
) { return sealOrFreeze(cx
, SEAL
); }
568 /* ES5 15.2.3.9: non-extensible, all properties non-configurable, all data props read-only */
569 bool freeze(JSContext
*cx
) { return sealOrFreeze(cx
, FREEZE
); }
571 bool isSealed(JSContext
*cx
, bool *resultp
) { return isSealedOrFrozen(cx
, SEAL
, resultp
); }
572 bool isFrozen(JSContext
*cx
, bool *resultp
) { return isSealedOrFrozen(cx
, FREEZE
, resultp
); }
574 /* Accessors for elements. */
576 inline bool ensureElements(JSContext
*cx
, unsigned cap
);
577 bool growElements(JSContext
*cx
, unsigned cap
);
578 void shrinkElements(JSContext
*cx
, unsigned cap
);
580 inline js::ElementIteratorObject
*asElementIterator();
583 * Array-specific getters and setters (for both dense and slow arrays).
586 bool allocateSlowArrayElements(JSContext
*cx
);
588 inline uint32_t getArrayLength() const;
589 inline void setArrayLength(JSContext
*cx
, uint32_t length
);
591 inline uint32_t getDenseArrayCapacity();
592 inline void setDenseArrayLength(uint32_t length
);
593 inline void setDenseArrayInitializedLength(uint32_t length
);
594 inline void ensureDenseArrayInitializedLength(JSContext
*cx
, unsigned index
, unsigned extra
);
595 inline void setDenseArrayElement(unsigned idx
, const js::Value
&val
);
596 inline void initDenseArrayElement(unsigned idx
, const js::Value
&val
);
597 inline void setDenseArrayElementWithType(JSContext
*cx
, unsigned idx
, const js::Value
&val
);
598 inline void initDenseArrayElementWithType(JSContext
*cx
, unsigned idx
, const js::Value
&val
);
599 inline void copyDenseArrayElements(unsigned dstStart
, const js::Value
*src
, unsigned count
);
600 inline void initDenseArrayElements(unsigned dstStart
, const js::Value
*src
, unsigned count
);
601 inline void moveDenseArrayElements(unsigned dstStart
, unsigned srcStart
, unsigned count
);
602 inline void moveDenseArrayElementsUnbarriered(unsigned dstStart
, unsigned srcStart
, unsigned count
);
603 inline bool denseArrayHasInlineSlots() const;
605 /* Packed information for this array. */
606 inline void markDenseArrayNotPacked(JSContext
*cx
);
609 * ensureDenseArrayElements ensures that the dense array can hold at least
610 * index + extra elements. It returns ED_OK on success, ED_FAILED on
611 * failure to grow the array, ED_SPARSE when the array is too sparse to
612 * grow (this includes the case of index + extra overflow). In the last
613 * two cases the array is kept intact.
615 enum EnsureDenseResult
{ ED_OK
, ED_FAILED
, ED_SPARSE
};
616 inline EnsureDenseResult
ensureDenseArrayElements(JSContext
*cx
, unsigned index
, unsigned extra
);
619 * Check if after growing the dense array will be too sparse.
620 * newElementsHint is an estimated number of elements to be added.
622 bool willBeSparseDenseArray(unsigned requiredCapacity
, unsigned newElementsHint
);
624 static bool makeDenseArraySlow(JSContext
*cx
, js::HandleObject obj
);
627 * If this array object has a data property with index i, set *vp to its
628 * value and return true. If not, do vp->setMagic(JS_ARRAY_HOLE) and return
629 * true. On OOM, report it and return false.
631 bool arrayGetOwnDataElement(JSContext
*cx
, size_t i
, js::Value
*vp
);
635 * Date-specific getters and setters.
638 static const uint32_t JSSLOT_DATE_UTC_TIME
= 0;
641 * Cached slots holding local properties of the date.
642 * These are undefined until the first actual lookup occurs
643 * and are reset to undefined whenever the date's time is modified.
645 static const uint32_t JSSLOT_DATE_COMPONENTS_START
= 1;
647 static const uint32_t JSSLOT_DATE_LOCAL_TIME
= 1;
648 static const uint32_t JSSLOT_DATE_LOCAL_YEAR
= 2;
649 static const uint32_t JSSLOT_DATE_LOCAL_MONTH
= 3;
650 static const uint32_t JSSLOT_DATE_LOCAL_DATE
= 4;
651 static const uint32_t JSSLOT_DATE_LOCAL_DAY
= 5;
652 static const uint32_t JSSLOT_DATE_LOCAL_HOURS
= 6;
653 static const uint32_t JSSLOT_DATE_LOCAL_MINUTES
= 7;
654 static const uint32_t JSSLOT_DATE_LOCAL_SECONDS
= 8;
656 static const uint32_t DATE_CLASS_RESERVED_SLOTS
= 9;
658 inline const js::Value
&getDateUTCTime() const;
659 inline void setDateUTCTime(const js::Value
&pthis
);
662 * Function-specific getters and setters.
665 friend struct JSFunction
;
667 inline JSFunction
*toFunction();
668 inline const JSFunction
*toFunction() const;
672 * Iterator-specific getters and setters.
675 static const uint32_t ITER_CLASS_NFIXED_SLOTS
= 1;
677 inline js::NativeIterator
*getNativeIterator() const;
678 inline void setNativeIterator(js::NativeIterator
*);
681 * XML-related getters and setters.
685 * Slots for XML-related classes are as follows:
686 * - NamespaceClass.base reserves the *_NAME_* and *_NAMESPACE_* slots.
687 * - QNameClass.base, AttributeNameClass, AnyNameClass reserve
688 * the *_NAME_* and *_QNAME_* slots.
689 * - Others (XMLClass, js_XMLFilterClass) don't reserve any slots.
692 static const uint32_t JSSLOT_NAME_PREFIX
= 0; // shared
693 static const uint32_t JSSLOT_NAME_URI
= 1; // shared
695 static const uint32_t JSSLOT_NAMESPACE_DECLARED
= 2;
697 static const uint32_t JSSLOT_QNAME_LOCAL_NAME
= 2;
700 static const uint32_t NAMESPACE_CLASS_RESERVED_SLOTS
= 3;
701 static const uint32_t QNAME_CLASS_RESERVED_SLOTS
= 3;
703 inline JSLinearString
*getNamePrefix() const;
704 inline jsval
getNamePrefixVal() const;
705 inline void setNamePrefix(JSLinearString
*prefix
);
706 inline void clearNamePrefix();
708 inline JSLinearString
*getNameURI() const;
709 inline jsval
getNameURIVal() const;
710 inline void setNameURI(JSLinearString
*uri
);
712 inline jsval
getNamespaceDeclared() const;
713 inline void setNamespaceDeclared(jsval decl
);
715 inline JSAtom
*getQNameLocalName() const;
716 inline jsval
getQNameLocalNameVal() const;
717 inline void setQNameLocalName(JSAtom
*name
);
720 * Back to generic stuff.
722 inline bool isCallable();
724 inline void finish(js::FreeOp
*fop
);
725 JS_ALWAYS_INLINE
void finalize(js::FreeOp
*fop
);
727 inline bool hasProperty(JSContext
*cx
, jsid id
, bool *foundp
, unsigned flags
= 0);
730 * Allocate and free an object slot.
732 * FIXME: bug 593129 -- slot allocation should be done by object methods
733 * after calling object-parameter-free shape methods, avoiding coupling
734 * logic across the object vs. shape module wall.
736 bool allocSlot(JSContext
*cx
, uint32_t *slotp
);
737 void freeSlot(JSContext
*cx
, uint32_t slot
);
740 bool reportNotConfigurable(JSContext
* cx
, jsid id
, unsigned report
= JSREPORT_ERROR
);
741 bool reportNotExtensible(JSContext
*cx
, unsigned report
= JSREPORT_ERROR
);
744 * Get the property with the given id, then call it as a function with the
745 * given arguments, providing this object as |this|. If the property isn't
746 * callable a TypeError will be thrown. On success the value returned by
747 * the call is stored in *vp.
749 bool callMethod(JSContext
*cx
, jsid id
, unsigned argc
, js::Value
*argv
, js::Value
*vp
);
752 js::Shape
*getChildProperty(JSContext
*cx
, js::Shape
*parent
, js::StackShape
&child
);
756 * Internal helper that adds a shape not yet mapped by this object.
759 * 1. getter and setter must be normalized based on flags (see jsscope.cpp).
760 * 2. !isExtensible() checking must be done by callers.
762 js::Shape
*addPropertyInternal(JSContext
*cx
, jsid id
,
763 JSPropertyOp getter
, JSStrictPropertyOp setter
,
764 uint32_t slot
, unsigned attrs
,
765 unsigned flags
, int shortid
, js::Shape
**spp
,
766 bool allowDictionary
);
769 bool toDictionaryMode(JSContext
*cx
);
771 struct TradeGutsReserved
;
772 static bool ReserveForTradeGuts(JSContext
*cx
, JSObject
*a
, JSObject
*b
,
773 TradeGutsReserved
&reserved
);
775 static void TradeGuts(JSContext
*cx
, JSObject
*a
, JSObject
*b
,
776 TradeGutsReserved
&reserved
);
779 /* Add a property whose id is not yet in this scope. */
780 js::Shape
*addProperty(JSContext
*cx
, jsid id
,
781 JSPropertyOp getter
, JSStrictPropertyOp setter
,
782 uint32_t slot
, unsigned attrs
,
783 unsigned flags
, int shortid
, bool allowDictionary
= true);
785 /* Add a data property whose id is not yet in this scope. */
786 js::Shape
*addDataProperty(JSContext
*cx
, jsid id
, uint32_t slot
, unsigned attrs
) {
787 JS_ASSERT(!(attrs
& (JSPROP_GETTER
| JSPROP_SETTER
)));
788 return addProperty(cx
, id
, NULL
, NULL
, slot
, attrs
, 0, 0);
791 /* Add or overwrite a property for id in this scope. */
792 js::Shape
*putProperty(JSContext
*cx
, jsid id
,
793 JSPropertyOp getter
, JSStrictPropertyOp setter
,
794 uint32_t slot
, unsigned attrs
,
795 unsigned flags
, int shortid
);
797 putProperty(JSContext
*cx
, js::PropertyName
*name
,
798 JSPropertyOp getter
, JSStrictPropertyOp setter
,
799 uint32_t slot
, unsigned attrs
, unsigned flags
, int shortid
) {
800 return putProperty(cx
, js::NameToId(name
), getter
, setter
, slot
, attrs
, flags
, shortid
);
803 /* Change the given property into a sibling with the same id in this scope. */
804 js::Shape
*changeProperty(JSContext
*cx
, js::Shape
*shape
, unsigned attrs
, unsigned mask
,
805 JSPropertyOp getter
, JSStrictPropertyOp setter
);
807 inline bool changePropertyAttributes(JSContext
*cx
, js::Shape
*shape
, unsigned attrs
);
809 /* Remove the property named by id from this object. */
810 bool removeProperty(JSContext
*cx
, jsid id
);
812 /* Clear the scope, making it empty. */
813 void clear(JSContext
*cx
);
815 inline JSBool
lookupGeneric(JSContext
*cx
, jsid id
, JSObject
**objp
, JSProperty
**propp
);
816 inline JSBool
lookupProperty(JSContext
*cx
, js::PropertyName
*name
, JSObject
**objp
, JSProperty
**propp
);
817 inline JSBool
lookupElement(JSContext
*cx
, uint32_t index
,
818 JSObject
**objp
, JSProperty
**propp
);
819 inline JSBool
lookupSpecial(JSContext
*cx
, js::SpecialId sid
,
820 JSObject
**objp
, JSProperty
**propp
);
822 inline JSBool
defineGeneric(JSContext
*cx
, jsid id
, const js::Value
&value
,
823 JSPropertyOp getter
= JS_PropertyStub
,
824 JSStrictPropertyOp setter
= JS_StrictPropertyStub
,
825 unsigned attrs
= JSPROP_ENUMERATE
);
826 inline JSBool
defineProperty(JSContext
*cx
, js::PropertyName
*name
, const js::Value
&value
,
827 JSPropertyOp getter
= JS_PropertyStub
,
828 JSStrictPropertyOp setter
= JS_StrictPropertyStub
,
829 unsigned attrs
= JSPROP_ENUMERATE
);
831 inline JSBool
defineElement(JSContext
*cx
, uint32_t index
, const js::Value
&value
,
832 JSPropertyOp getter
= JS_PropertyStub
,
833 JSStrictPropertyOp setter
= JS_StrictPropertyStub
,
834 unsigned attrs
= JSPROP_ENUMERATE
);
835 inline JSBool
defineSpecial(JSContext
*cx
, js::SpecialId sid
, const js::Value
&value
,
836 JSPropertyOp getter
= JS_PropertyStub
,
837 JSStrictPropertyOp setter
= JS_StrictPropertyStub
,
838 unsigned attrs
= JSPROP_ENUMERATE
);
840 inline JSBool
getGeneric(JSContext
*cx
, JSObject
*receiver
, jsid id
, js::Value
*vp
);
841 inline JSBool
getProperty(JSContext
*cx
, JSObject
*receiver
, js::PropertyName
*name
,
843 inline JSBool
getElement(JSContext
*cx
, JSObject
*receiver
, uint32_t index
, js::Value
*vp
);
844 /* If element is not present (e.g. array hole) *present is set to
845 false and the contents of *vp are unusable garbage. */
846 inline JSBool
getElementIfPresent(JSContext
*cx
, JSObject
*receiver
, uint32_t index
,
847 js::Value
*vp
, bool *present
);
848 inline JSBool
getSpecial(JSContext
*cx
, JSObject
*receiver
, js::SpecialId sid
, js::Value
*vp
);
850 inline JSBool
getGeneric(JSContext
*cx
, jsid id
, js::Value
*vp
);
851 inline JSBool
getProperty(JSContext
*cx
, js::PropertyName
*name
, js::Value
*vp
);
852 inline JSBool
getElement(JSContext
*cx
, uint32_t index
, js::Value
*vp
);
853 inline JSBool
getSpecial(JSContext
*cx
, js::SpecialId sid
, js::Value
*vp
);
855 inline JSBool
setGeneric(JSContext
*cx
, jsid id
, js::Value
*vp
, JSBool strict
);
856 inline JSBool
setProperty(JSContext
*cx
, js::PropertyName
*name
, js::Value
*vp
, JSBool strict
);
857 inline JSBool
setElement(JSContext
*cx
, uint32_t index
, js::Value
*vp
, JSBool strict
);
858 inline JSBool
setSpecial(JSContext
*cx
, js::SpecialId sid
, js::Value
*vp
, JSBool strict
);
860 JSBool
nonNativeSetProperty(JSContext
*cx
, jsid id
, js::Value
*vp
, JSBool strict
);
861 JSBool
nonNativeSetElement(JSContext
*cx
, uint32_t index
, js::Value
*vp
, JSBool strict
);
863 inline JSBool
getGenericAttributes(JSContext
*cx
, jsid id
, unsigned *attrsp
);
864 inline JSBool
getPropertyAttributes(JSContext
*cx
, js::PropertyName
*name
, unsigned *attrsp
);
865 inline JSBool
getElementAttributes(JSContext
*cx
, uint32_t index
, unsigned *attrsp
);
866 inline JSBool
getSpecialAttributes(JSContext
*cx
, js::SpecialId sid
, unsigned *attrsp
);
868 inline JSBool
setGenericAttributes(JSContext
*cx
, jsid id
, unsigned *attrsp
);
869 inline JSBool
setPropertyAttributes(JSContext
*cx
, js::PropertyName
*name
, unsigned *attrsp
);
870 inline JSBool
setElementAttributes(JSContext
*cx
, uint32_t index
, unsigned *attrsp
);
871 inline JSBool
setSpecialAttributes(JSContext
*cx
, js::SpecialId sid
, unsigned *attrsp
);
873 inline bool deleteProperty(JSContext
*cx
, js::PropertyName
*name
, js::Value
*rval
, bool strict
);
874 inline bool deleteElement(JSContext
*cx
, uint32_t index
, js::Value
*rval
, bool strict
);
875 inline bool deleteSpecial(JSContext
*cx
, js::SpecialId sid
, js::Value
*rval
, bool strict
);
876 bool deleteByValue(JSContext
*cx
, const js::Value
&property
, js::Value
*rval
, bool strict
);
878 inline bool enumerate(JSContext
*cx
, JSIterateOp iterop
, js::Value
*statep
, jsid
*idp
);
879 inline bool defaultValue(JSContext
*cx
, JSType hint
, js::Value
*vp
);
880 inline JSType
typeOf(JSContext
*cx
);
881 inline JSObject
*thisObject(JSContext
*cx
);
883 static bool thisObject(JSContext
*cx
, const js::Value
&v
, js::Value
*vp
);
885 bool swap(JSContext
*cx
, JSObject
*other
);
887 inline void initArrayClass();
890 * In addition to the generic object interface provided by JSObject,
891 * specific types of objects may provide additional operations. To access,
892 * these addition operations, callers should use the pattern:
895 * XObject &x = obj.asX();
899 * These XObject classes form a hierarchy. For example, for a cloned block
900 * object, the following predicates are true: isClonedBlock, isBlock,
901 * isNestedScope and isScope. Each of these has a respective class that
902 * derives and adds operations.
904 * A class XObject is defined in a vm/XObject{.h, .cpp, -inl.h} file
905 * triplet (along with any class YObject that derives XObject).
907 * Note that X represents a low-level representation and does not query the
908 * [[Class]] property of object defined by the spec (for this, see
909 * js::ObjectClassIs).
911 * SpiderMonkey has not been completely switched to the isX/asX/XObject
912 * pattern so in some cases there is no XObject class and the engine
913 * instead pokes directly at reserved slots and getPrivate. In such cases,
914 * consider adding the missing XObject class.
917 /* Direct subtypes of JSObject: */
918 inline bool isArguments() const;
919 inline bool isArrayBuffer() const;
920 inline bool isDataView() const;
921 inline bool isDate() const;
922 inline bool isElementIterator() const;
923 inline bool isError() const;
924 inline bool isFunction() const;
925 inline bool isGenerator() const;
926 inline bool isGlobal() const;
927 inline bool isIterator() const;
928 inline bool isNamespace() const;
929 inline bool isObject() const;
930 inline bool isQName() const;
931 inline bool isPrimitive() const;
932 inline bool isProxy() const;
933 inline bool isRegExp() const;
934 inline bool isRegExpStatics() const;
935 inline bool isScope() const;
936 inline bool isScript() const;
937 inline bool isStopIteration() const;
938 inline bool isTypedArray() const;
939 inline bool isWeakMap() const;
940 inline bool isXML() const;
941 inline bool isXMLId() const;
943 /* Subtypes of ScopeObject. */
944 inline bool isBlock() const;
945 inline bool isCall() const;
946 inline bool isDeclEnv() const;
947 inline bool isNestedScope() const;
948 inline bool isWith() const;
949 inline bool isClonedBlock() const;
950 inline bool isStaticBlock() const;
952 /* Subtypes of PrimitiveObject. */
953 inline bool isBoolean() const;
954 inline bool isNumber() const;
955 inline bool isString() const;
957 /* Subtypes of ArgumentsObject. */
958 inline bool isNormalArguments() const;
959 inline bool isStrictArguments() const;
961 /* Subtypes of Proxy. */
962 inline bool isWrapper() const;
963 inline bool isFunctionProxy() const;
964 inline bool isCrossCompartmentWrapper() const;
966 inline js::ArgumentsObject
&asArguments();
967 inline js::ArrayBufferObject
&asArrayBuffer();
968 inline const js::ArgumentsObject
&asArguments() const;
969 inline js::BlockObject
&asBlock();
970 inline js::BooleanObject
&asBoolean();
971 inline js::CallObject
&asCall();
972 inline js::ClonedBlockObject
&asClonedBlock();
973 inline js::DataViewObject
&asDataView();
974 inline js::DeclEnvObject
&asDeclEnv();
975 inline js::GlobalObject
&asGlobal();
976 inline js::NestedScopeObject
&asNestedScope();
977 inline js::NormalArgumentsObject
&asNormalArguments();
978 inline js::NumberObject
&asNumber();
979 inline js::RegExpObject
&asRegExp();
980 inline js::ScopeObject
&asScope();
981 inline js::StrictArgumentsObject
&asStrictArguments();
982 inline js::StaticBlockObject
&asStaticBlock();
983 inline js::StringObject
&asString();
984 inline js::WithObject
&asWith();
986 static inline js::ThingRootKind
rootKind() { return js::THING_ROOT_OBJECT
; }
993 static void staticAsserts() {
994 MOZ_STATIC_ASSERT(sizeof(JSObject
) == sizeof(js::shadow::Object
),
995 "shadow interface must match actual interface");
996 MOZ_STATIC_ASSERT(sizeof(JSObject
) == sizeof(js::ObjectImpl
),
997 "JSObject itself must not have any fields");
998 MOZ_STATIC_ASSERT(sizeof(JSObject
) % sizeof(js::Value
) == 0,
999 "fixed slots after an object must be aligned");
1002 JSObject() MOZ_DELETE
;
1003 JSObject(const JSObject
&other
) MOZ_DELETE
;
1004 void operator=(const JSObject
&other
) MOZ_DELETE
;
1008 * The only sensible way to compare JSObject with == is by identity. We use
1009 * const& instead of * as a syntactic way to assert non-null. This leads to an
1010 * abundance of address-of operators to identity. Hence this overload.
1012 static JS_ALWAYS_INLINE
bool
1013 operator==(const JSObject
&lhs
, const JSObject
&rhs
)
1015 return &lhs
== &rhs
;
1018 static JS_ALWAYS_INLINE
bool
1019 operator!=(const JSObject
&lhs
, const JSObject
&rhs
)
1021 return &lhs
!= &rhs
;
1024 struct JSObject_Slots2
: JSObject
{ js::Value fslots
[2]; };
1025 struct JSObject_Slots4
: JSObject
{ js::Value fslots
[4]; };
1026 struct JSObject_Slots8
: JSObject
{ js::Value fslots
[8]; };
1027 struct JSObject_Slots12
: JSObject
{ js::Value fslots
[12]; };
1028 struct JSObject_Slots16
: JSObject
{ js::Value fslots
[16]; };
1030 #define JSSLOT_FREE(clasp) JSCLASS_RESERVED_SLOTS(clasp)
1032 class JSValueArray
{
1037 JSValueArray(jsval
*v
, size_t c
) : array(v
), length(c
) {}
1045 ValueArray(js::Value
*v
, size_t c
) : array(v
), length(c
) {}
1048 /* For manipulating JSContext::sharpObjectMap. */
1050 js_EnterSharpObject(JSContext
*cx
, js::HandleObject obj
, JSIdArray
**idap
, bool *alreadySeen
, bool *isSharp
);
1053 js_LeaveSharpObject(JSContext
*cx
, JSIdArray
**idap
);
1056 * Mark objects stored in map if GC happens between js_EnterSharpObject
1057 * and js_LeaveSharpObject. GC calls this when map->depth > 0.
1060 js_TraceSharpMap(JSTracer
*trc
, JSSharpObjectMap
*map
);
1063 js_HasOwnPropertyHelper(JSContext
*cx
, js::LookupGenericOp lookup
, unsigned argc
,
1067 js_HasOwnProperty(JSContext
*cx
, js::LookupGenericOp lookup
, js::HandleObject obj
, jsid id
,
1068 JSObject
**objp
, JSProperty
**propp
);
1071 js_PropertyIsEnumerable(JSContext
*cx
, JSObject
*obj
, jsid id
, js::Value
*vp
);
1073 #if JS_HAS_OBJ_PROTO_PROP
1074 extern JSPropertySpec object_props
[];
1076 #define object_props NULL
1079 extern JSFunctionSpec object_methods
[];
1080 extern JSFunctionSpec object_static_methods
[];
1085 IsStandardClassResolved(JSObject
*obj
, js::Class
*clasp
);
1088 MarkStandardClassInitializedNoProto(JSObject
*obj
, js::Class
*clasp
);
1090 } /* namespace js */
1093 * Select Object.prototype method names shared between jsapi.cpp and jsobj.cpp.
1095 extern const char js_watch_str
[];
1096 extern const char js_unwatch_str
[];
1097 extern const char js_hasOwnProperty_str
[];
1098 extern const char js_isPrototypeOf_str
[];
1099 extern const char js_propertyIsEnumerable_str
[];
1101 #ifdef OLD_GETTER_SETTER_METHODS
1102 extern const char js_defineGetter_str
[];
1103 extern const char js_defineSetter_str
[];
1104 extern const char js_lookupGetter_str
[];
1105 extern const char js_lookupSetter_str
[];
1109 js_PopulateObject(JSContext
*cx
, js::HandleObject newborn
, JSObject
*props
);
1112 * Fast access to immutable standard objects (constructors and prototypes).
1115 js_GetClassObject(JSContext
*cx
, JSObject
*obj
, JSProtoKey key
,
1119 * If protoKey is not JSProto_Null, then clasp is ignored. If protoKey is
1120 * JSProto_Null, clasp must non-null.
1123 js_FindClassObject(JSContext
*cx
, JSObject
*start
, JSProtoKey key
,
1124 js::Value
*vp
, js::Class
*clasp
= NULL
);
1126 // Specialized call for constructing |this| with a known function callee,
1127 // and a known prototype.
1129 js_CreateThisForFunctionWithProto(JSContext
*cx
, js::HandleObject callee
, JSObject
*proto
);
1131 // Specialized call for constructing |this| with a known function callee.
1133 js_CreateThisForFunction(JSContext
*cx
, js::HandleObject callee
, bool newType
);
1135 // Generic call for constructing |this|.
1137 js_CreateThis(JSContext
*cx
, js::Class
*clasp
, JSObject
*callee
);
1140 * Find or create a property named by id in obj's scope, with the given getter
1141 * and setter, slot, attributes, and other members.
1144 js_AddNativeProperty(JSContext
*cx
, js::HandleObject obj
, jsid id
,
1145 JSPropertyOp getter
, JSStrictPropertyOp setter
, uint32_t slot
,
1146 unsigned attrs
, unsigned flags
, int shortid
);
1149 js_DefineOwnProperty(JSContext
*cx
, js::HandleObject obj
, js::HandleId id
,
1150 const js::Value
&descriptor
, JSBool
*bp
);
1155 * Flags for the defineHow parameter of js_DefineNativeProperty.
1157 const unsigned DNP_CACHE_RESULT
= 1; /* an interpreter call from JSOP_INITPROP */
1158 const unsigned DNP_DONT_PURGE
= 2; /* suppress js_PurgeScopeChain */
1159 const unsigned DNP_UNQUALIFIED
= 4; /* Unqualified property set. Only used in
1160 the defineHow argument of
1161 js_SetPropertyHelper. */
1162 const unsigned DNP_SKIP_TYPE
= 8; /* Don't update type information */
1165 * Return successfully added or changed shape or NULL on error.
1167 extern const Shape
*
1168 DefineNativeProperty(JSContext
*cx
, HandleObject obj
, jsid id
, const Value
&value
,
1169 PropertyOp getter
, StrictPropertyOp setter
, unsigned attrs
,
1170 unsigned flags
, int shortid
, unsigned defineHow
= 0);
1172 inline const Shape
*
1173 DefineNativeProperty(JSContext
*cx
, HandleObject obj
, PropertyName
*name
, const Value
&value
,
1174 PropertyOp getter
, StrictPropertyOp setter
, unsigned attrs
,
1175 unsigned flags
, int shortid
, unsigned defineHow
= 0)
1177 return DefineNativeProperty(cx
, obj
, NameToId(name
), value
, getter
, setter
, attrs
, flags
,
1178 shortid
, defineHow
);
1182 * Specialized subroutine that allows caller to preset JSRESOLVE_* flags.
1185 LookupPropertyWithFlags(JSContext
*cx
, JSObject
*obj
, jsid id
, unsigned flags
,
1186 JSObject
**objp
, JSProperty
**propp
);
1189 LookupPropertyWithFlags(JSContext
*cx
, JSObject
*obj
, PropertyName
*name
, unsigned flags
,
1190 JSObject
**objp
, JSProperty
**propp
)
1192 return LookupPropertyWithFlags(cx
, obj
, NameToId(name
), flags
, objp
, propp
);
1196 * Call the [[DefineOwnProperty]] internal method of obj.
1198 * If obj is an array, this follows ES5 15.4.5.1.
1199 * If obj is any other native object, this follows ES5 8.12.9.
1200 * If obj is a proxy, this calls the proxy handler's defineProperty method.
1201 * Otherwise, this reports an error and returns false.
1204 DefineProperty(JSContext
*cx
, js::HandleObject obj
,
1205 js::HandleId id
, const PropDesc
&desc
, bool throwError
,
1209 * Read property descriptors from props, as for Object.defineProperties. See
1210 * ES5 15.2.3.7 steps 3-5.
1213 ReadPropertyDescriptors(JSContext
*cx
, JSObject
*props
, bool checkAccessors
,
1214 AutoIdVector
*ids
, AutoPropDescArrayRooter
*descs
);
1217 * Constant to pass to js_LookupPropertyWithFlags to infer bits from current
1220 static const unsigned RESOLVE_INFER
= 0xffff;
1223 * If cacheResult is false, return JS_NO_PROP_CACHE_FILL on success.
1226 FindPropertyHelper(JSContext
*cx
, HandlePropertyName name
,
1227 bool cacheResult
, HandleObject scopeChain
,
1228 JSObject
**objp
, JSObject
**pobjp
, JSProperty
**propp
);
1231 * Search for name either on the current scope chain or on the scope chain's
1232 * global object, per the global parameter.
1235 FindProperty(JSContext
*cx
, HandlePropertyName name
, HandleObject scopeChain
,
1236 JSObject
**objp
, JSObject
**pobjp
, JSProperty
**propp
);
1239 FindIdentifierBase(JSContext
*cx
, HandleObject scopeChain
, HandlePropertyName name
);
1244 js_FindVariableScope(JSContext
*cx
, JSFunction
**funp
);
1246 /* JSGET_CACHE_RESULT is the analogue of DNP_CACHE_RESULT for js_GetMethod. */
1247 const unsigned JSGET_CACHE_RESULT
= 1; // from a caching interpreter opcode
1250 * NB: js_NativeGet and js_NativeSet are called with the scope containing shape
1251 * (pobj's scope for Get, obj's for Set) locked, and on successful return, that
1252 * scope is again locked. But on failure, both functions return false with the
1253 * scope containing shape unlocked.
1256 js_NativeGet(JSContext
*cx
, JSObject
*obj
, JSObject
*pobj
, const js::Shape
*shape
, unsigned getHow
,
1260 js_NativeSet(JSContext
*cx
, JSObject
*obj
, const js::Shape
*shape
, bool added
,
1261 bool strict
, js::Value
*vp
);
1266 GetPropertyHelper(JSContext
*cx
, HandleObject obj
, jsid id
, uint32_t getHow
, Value
*vp
);
1269 GetPropertyHelper(JSContext
*cx
, HandleObject obj
, PropertyName
*name
, uint32_t getHow
, Value
*vp
)
1271 return GetPropertyHelper(cx
, obj
, NameToId(name
), getHow
, vp
);
1275 GetOwnPropertyDescriptor(JSContext
*cx
, HandleObject obj
, HandleId id
, PropertyDescriptor
*desc
);
1278 GetOwnPropertyDescriptor(JSContext
*cx
, HandleObject obj
, HandleId id
, Value
*vp
);
1281 NewPropertyDescriptorObject(JSContext
*cx
, const PropertyDescriptor
*desc
, Value
*vp
);
1283 } /* namespace js */
1286 js_GetMethod(JSContext
*cx
, js::HandleObject obj
, jsid id
, unsigned getHow
, js::Value
*vp
);
1291 GetMethod(JSContext
*cx
, HandleObject obj
, PropertyName
*name
, unsigned getHow
, Value
*vp
)
1293 return js_GetMethod(cx
, obj
, NameToId(name
), getHow
, vp
);
1296 } /* namespace js */
1301 * If obj has an already-resolved data property for id, return true and
1302 * store the property value in *vp.
1305 HasDataProperty(JSContext
*cx
, HandleObject obj
, jsid id
, Value
*vp
);
1308 HasDataProperty(JSContext
*cx
, HandleObject obj
, PropertyName
*name
, Value
*vp
)
1310 return HasDataProperty(cx
, obj
, NameToId(name
), vp
);
1314 CheckAccess(JSContext
*cx
, JSObject
*obj
, jsid id
, JSAccessMode mode
,
1315 js::Value
*vp
, unsigned *attrsp
);
1317 } /* namespace js */
1320 js_IsDelegate(JSContext
*cx
, JSObject
*obj
, const js::Value
&v
);
1323 * Wrap boolean, number or string as Boolean, Number or String object.
1324 * *vp must not be an object, null or undefined.
1327 js_PrimitiveToObject(JSContext
*cx
, js::Value
*vp
);
1330 js_ValueToObjectOrNull(JSContext
*cx
, const js::Value
&v
, JSObject
**objp
);
1332 /* Throws if v could not be converted to an object. */
1334 js_ValueToNonNullObject(JSContext
*cx
, const js::Value
&v
);
1339 * Invokes the ES5 ToObject algorithm on *vp, writing back the object to vp.
1340 * If *vp might already be an object, use ToObject.
1343 ToObjectSlow(JSContext
*cx
, Value
*vp
);
1345 JS_ALWAYS_INLINE JSObject
*
1346 ToObject(JSContext
*cx
, Value
*vp
)
1349 return &vp
->toObject();
1350 return ToObjectSlow(cx
, vp
);
1353 /* As for ToObject, but preserves the original value. */
1355 ValueToObject(JSContext
*cx
, const Value
&v
)
1358 return &v
.toObject();
1359 return js_ValueToNonNullObject(cx
, v
);
1362 } /* namespace js */
1365 js_PrintObjectSlotName(JSTracer
*trc
, char *buf
, size_t bufsize
);
1368 js_ClearNative(JSContext
*cx
, JSObject
*obj
);
1371 js_ReportGetterOnlyAssignment(JSContext
*cx
);
1374 js_InferFlags(JSContext
*cx
, unsigned defaultFlags
);
1376 /* Object constructor native. Exposed only so the JIT can know its address. */
1378 js_Object(JSContext
*cx
, unsigned argc
, js::Value
*vp
);
1381 * If protoKey is not JSProto_Null, then clasp is ignored. If protoKey is
1382 * JSProto_Null, clasp must non-null.
1384 * If protoKey is constant and scope is non-null, use GlobalObject's prototype
1387 extern JS_FRIEND_API(JSBool
)
1388 js_GetClassPrototype(JSContext
*cx
, JSObject
*scope
, JSProtoKey protoKey
,
1389 JSObject
**protop
, js::Class
*clasp
= NULL
);
1394 SetProto(JSContext
*cx
, HandleObject obj
, HandleObject proto
, bool checkForCycles
);
1397 obj_toStringHelper(JSContext
*cx
, JSObject
*obj
);
1400 eval(JSContext
*cx
, unsigned argc
, Value
*vp
);
1403 * Performs a direct eval for the given arguments, which must correspond to the
1404 * currently-executing stack frame, which must be a script frame. On completion
1405 * the result is returned in args.rval.
1408 DirectEval(JSContext
*cx
, const CallArgs
&args
);
1411 * True iff |v| is the built-in eval function for the global object that
1412 * corresponds to |scopeChain|.
1415 IsBuiltinEvalForScope(JSObject
*scopeChain
, const js::Value
&v
);
1417 /* True iff fun is a built-in eval function. */
1419 IsAnyBuiltinEval(JSFunction
*fun
);
1421 /* 'call' should be for the eval/Function native invocation. */
1422 extern JSPrincipals
*
1423 PrincipalsForCompiledCode(const CallReceiver
&call
, JSContext
*cx
);
1426 NonNullObject(JSContext
*cx
, const Value
&v
);
1429 InformalValueTypeName(const Value
&v
);
1432 DestroyIdArray(FreeOp
*fop
, JSIdArray
*ida
);
1435 GetFirstArgumentAsObject(JSContext
*cx
, unsigned argc
, Value
*vp
, const char *method
, JSObject
**objp
);
1437 /* Helpers for throwing. These always return false. */
1439 Throw(JSContext
*cx
, jsid id
, unsigned errorNumber
);
1442 Throw(JSContext
*cx
, JSObject
*obj
, unsigned errorNumber
);
1444 } /* namespace js */
1446 #endif /* jsobj_h___ */