83 |
JSHasInstanceOp hasInstance; |
JSHasInstanceOp hasInstance; |
84 |
JSTraceOp trace; |
JSTraceOp trace; |
85 |
JSFinalizeOp clear; |
JSFinalizeOp clear; |
|
JSGetRequiredSlotOp getRequiredSlot; |
|
|
JSSetRequiredSlotOp setRequiredSlot; |
|
86 |
}; |
}; |
87 |
|
|
88 |
struct JSObjectMap { |
struct JSObjectMap { |
89 |
JSObjectOps *ops; /* high level object operation vtable */ |
const JSObjectOps * const ops; /* high level object operation vtable */ |
90 |
|
uint32 shape; /* shape identifier */ |
91 |
|
|
92 |
|
#ifdef __cplusplus /* Allow inclusion from LiveConnect C files. */ |
93 |
|
|
94 |
|
explicit JSObjectMap(const JSObjectOps *ops, uint32 shape) : ops(ops), shape(shape) {} |
95 |
|
enum { SHAPELESS = 0xffffffff }; |
96 |
|
|
97 |
|
#endif |
98 |
|
|
99 |
}; |
}; |
100 |
|
|
101 |
/* Shorthand macros for frequently-made calls. */ |
#ifndef __cplusplus /* Allow inclusion from LiveConnect C files. */ |
102 |
|
|
103 |
#define OBJ_LOOKUP_PROPERTY(cx,obj,id,objp,propp) \ |
#define OBJ_LOOKUP_PROPERTY(cx,obj,id,objp,propp) \ |
104 |
(obj)->map->ops->lookupProperty(cx,obj,id,objp,propp) |
(obj)->map->ops->lookupProperty(cx,obj,id,objp,propp) |
105 |
#define OBJ_DEFINE_PROPERTY(cx,obj,id,value,getter,setter,attrs,propp) \ |
|
|
(obj)->map->ops->defineProperty(cx,obj,id,value,getter,setter,attrs,propp) |
|
|
#define OBJ_GET_PROPERTY(cx,obj,id,vp) \ |
|
|
(obj)->map->ops->getProperty(cx,obj,id,vp) |
|
|
#define OBJ_SET_PROPERTY(cx,obj,id,vp) \ |
|
|
(obj)->map->ops->setProperty(cx,obj,id,vp) |
|
|
#define OBJ_GET_ATTRIBUTES(cx,obj,id,prop,attrsp) \ |
|
|
(obj)->map->ops->getAttributes(cx,obj,id,prop,attrsp) |
|
|
#define OBJ_SET_ATTRIBUTES(cx,obj,id,prop,attrsp) \ |
|
|
(obj)->map->ops->setAttributes(cx,obj,id,prop,attrsp) |
|
|
#define OBJ_DELETE_PROPERTY(cx,obj,id,rval) \ |
|
|
(obj)->map->ops->deleteProperty(cx,obj,id,rval) |
|
|
#define OBJ_DEFAULT_VALUE(cx,obj,hint,vp) \ |
|
|
(obj)->map->ops->defaultValue(cx,obj,hint,vp) |
|
|
#define OBJ_ENUMERATE(cx,obj,enum_op,statep,idp) \ |
|
|
(obj)->map->ops->enumerate(cx,obj,enum_op,statep,idp) |
|
|
#define OBJ_CHECK_ACCESS(cx,obj,id,mode,vp,attrsp) \ |
|
|
(obj)->map->ops->checkAccess(cx,obj,id,mode,vp,attrsp) |
|
|
|
|
|
/* These four are time-optimized to avoid stub calls. */ |
|
|
#define OBJ_THIS_OBJECT(cx,obj) \ |
|
|
((obj)->map->ops->thisObject \ |
|
|
? (obj)->map->ops->thisObject(cx,obj) \ |
|
|
: (obj)) |
|
106 |
#define OBJ_DROP_PROPERTY(cx,obj,prop) \ |
#define OBJ_DROP_PROPERTY(cx,obj,prop) \ |
107 |
((obj)->map->ops->dropProperty \ |
((obj)->map->ops->dropProperty \ |
108 |
? (obj)->map->ops->dropProperty(cx,obj,prop) \ |
? (obj)->map->ops->dropProperty(cx,obj,prop) \ |
109 |
: (void)0) |
: (void)0) |
|
#define OBJ_GET_REQUIRED_SLOT(cx,obj,slot) \ |
|
|
((obj)->map->ops->getRequiredSlot \ |
|
|
? (obj)->map->ops->getRequiredSlot(cx, obj, slot) \ |
|
|
: JSVAL_VOID) |
|
|
#define OBJ_SET_REQUIRED_SLOT(cx,obj,slot,v) \ |
|
|
((obj)->map->ops->setRequiredSlot \ |
|
|
? (obj)->map->ops->setRequiredSlot(cx, obj, slot, v) \ |
|
|
: JS_TRUE) |
|
110 |
|
|
111 |
#define OBJ_TO_INNER_OBJECT(cx,obj) \ |
#define OBJ_GET_ATTRIBUTES(cx,obj,id,prop,attrsp) \ |
112 |
JS_BEGIN_MACRO \ |
(obj)->map->ops->getAttributes(cx,obj,id,prop,attrsp) |
|
JSClass *clasp_ = OBJ_GET_CLASS(cx, obj); \ |
|
|
if (clasp_->flags & JSCLASS_IS_EXTENDED) { \ |
|
|
JSExtendedClass *xclasp_ = (JSExtendedClass*)clasp_; \ |
|
|
if (xclasp_->innerObject) \ |
|
|
obj = xclasp_->innerObject(cx, obj); \ |
|
|
} \ |
|
|
JS_END_MACRO |
|
113 |
|
|
114 |
#define OBJ_TO_OUTER_OBJECT(cx,obj) \ |
#endif /* __cplusplus */ |
115 |
JS_BEGIN_MACRO \ |
|
116 |
JSClass *clasp_ = OBJ_GET_CLASS(cx, obj); \ |
#ifdef __cplusplus /* Allow inclusion from LiveConnect C files. */ |
117 |
if (clasp_->flags & JSCLASS_IS_EXTENDED) { \ |
const uint32 JS_INITIAL_NSLOTS = 5; |
|
JSExtendedClass *xclasp_ = (JSExtendedClass*)clasp_; \ |
|
|
if (xclasp_->outerObject) \ |
|
|
obj = xclasp_->outerObject(cx, obj); \ |
|
|
} \ |
|
|
JS_END_MACRO |
|
118 |
|
|
119 |
#define JS_INITIAL_NSLOTS 5 |
const uint32 JSSLOT_PROTO = 0; |
120 |
|
const uint32 JSSLOT_PARENT = 1; |
121 |
|
|
122 |
|
/* |
123 |
|
* The first available slot to store generic value. For JSCLASS_HAS_PRIVATE |
124 |
|
* classes the slot stores a pointer to private data reinterpreted as jsval. |
125 |
|
* Such pointer is stored as is without an overhead of PRIVATE_TO_JSVAL |
126 |
|
* tagging and should be accessed using the (get|set)Private methods of |
127 |
|
* JSObject. |
128 |
|
*/ |
129 |
|
const uint32 JSSLOT_PRIVATE = 2; |
130 |
|
|
131 |
|
const uint32 JSSLOT_PRIMITIVE_THIS = JSSLOT_PRIVATE; |
132 |
|
|
133 |
|
const uintptr_t JSSLOT_CLASS_MASK_BITS = 3; |
134 |
|
#else /* __cplusplus */ |
135 |
|
#define JS_INITIAL_NSLOTS 5 |
136 |
|
|
137 |
|
#define JSSLOT_PROTO 0 |
138 |
|
#define JSSLOT_PARENT 1 |
139 |
|
#define JSSLOT_PRIVATE 2 |
140 |
|
|
141 |
|
#define JSSLOT_CLASS_MASK_BITS 3 |
142 |
|
#endif /* __cplusplus */ |
143 |
|
|
144 |
/* |
/* |
145 |
* JSObject struct, with members sized to fit in 32 bytes on 32-bit targets, |
* JSObject struct, with members sized to fit in 32 bytes on 32-bit targets, |
148 |
* |
* |
149 |
* The classword member stores the JSClass pointer for this object, with the |
* The classword member stores the JSClass pointer for this object, with the |
150 |
* least two bits encoding whether this object is a "delegate" or a "system" |
* least two bits encoding whether this object is a "delegate" or a "system" |
151 |
* object. |
* object. We do *not* synchronize updates of classword -- API clients must |
152 |
|
* take care. |
153 |
* |
* |
154 |
* An object is a delegate if it is on another object's prototype (linked by |
* An object is a delegate if it is on another object's prototype (linked by |
155 |
* JSSLOT_PROTO) or scope (JSSLOT_PARENT) chain, and therefore the delegate |
* JSSLOT_PROTO) or scope (JSSLOT_PARENT) chain, and therefore the delegate |
167 |
* any such association. |
* any such association. |
168 |
* |
* |
169 |
* Both these classword tag bits are initially zero; they may be set or queried |
* Both these classword tag bits are initially zero; they may be set or queried |
170 |
* using the STOBJ_(IS|SET)_(DELEGATE|SYSTEM) macros. |
* using the (is|set)(Delegate|System) inline methods. |
171 |
* |
* |
172 |
* The dslots member is null or a pointer into a dynamically allocated vector |
* The dslots member is null or a pointer into a dynamically allocated vector |
173 |
* of jsvals for reserved and dynamic slots. If dslots is not null, dslots[-1] |
* of jsvals for reserved and dynamic slots. If dslots is not null, dslots[-1] |
174 |
* records the number of available slots. |
* records the number of available slots. |
175 |
*/ |
*/ |
176 |
struct JSObject { |
struct JSObject { |
177 |
JSObjectMap *map; /* propery map, see jsscope.h */ |
JSObjectMap *map; /* property map, see jsscope.h */ |
178 |
jsuword classword; /* classword, see above */ |
jsuword classword; /* JSClass ptr | bits, see above */ |
179 |
jsval fslots[JS_INITIAL_NSLOTS]; /* small number of fixed slots */ |
jsval fslots[JS_INITIAL_NSLOTS]; /* small number of fixed slots */ |
180 |
jsval *dslots; /* dynamically allocated slots */ |
jsval *dslots; /* dynamically allocated slots */ |
181 |
|
|
182 |
|
#ifdef __cplusplus /* Allow inclusion from LiveConnect C files. */ |
183 |
|
|
184 |
|
JSClass *getClass() const { |
185 |
|
return (JSClass *) (classword & ~JSSLOT_CLASS_MASK_BITS); |
186 |
|
} |
187 |
|
|
188 |
|
bool isDelegate() const { |
189 |
|
return (classword & jsuword(1)) != jsuword(0); |
190 |
|
} |
191 |
|
|
192 |
|
void setDelegate() { |
193 |
|
classword |= jsuword(1); |
194 |
|
} |
195 |
|
|
196 |
|
static void setDelegateNullSafe(JSObject *obj) { |
197 |
|
if (obj) |
198 |
|
obj->setDelegate(); |
199 |
|
} |
200 |
|
|
201 |
|
bool isSystem() const { |
202 |
|
return (classword & jsuword(2)) != jsuword(0); |
203 |
|
} |
204 |
|
|
205 |
|
void setSystem() { |
206 |
|
classword |= jsuword(2); |
207 |
|
} |
208 |
|
|
209 |
|
JSObject *getProto() const { |
210 |
|
return JSVAL_TO_OBJECT(fslots[JSSLOT_PROTO]); |
211 |
|
} |
212 |
|
|
213 |
|
void clearProto() { |
214 |
|
fslots[JSSLOT_PROTO] = JSVAL_NULL; |
215 |
|
} |
216 |
|
|
217 |
|
void setProto(JSObject *newProto) { |
218 |
|
setDelegateNullSafe(newProto); |
219 |
|
fslots[JSSLOT_PROTO] = OBJECT_TO_JSVAL(newProto); |
220 |
|
} |
221 |
|
|
222 |
|
JSObject *getParent() const { |
223 |
|
return JSVAL_TO_OBJECT(fslots[JSSLOT_PARENT]); |
224 |
|
} |
225 |
|
|
226 |
|
void clearParent() { |
227 |
|
fslots[JSSLOT_PARENT] = JSVAL_NULL; |
228 |
|
} |
229 |
|
|
230 |
|
void setParent(JSObject *newParent) { |
231 |
|
setDelegateNullSafe(newParent); |
232 |
|
fslots[JSSLOT_PARENT] = OBJECT_TO_JSVAL(newParent); |
233 |
|
} |
234 |
|
|
235 |
|
void traceProtoAndParent(JSTracer *trc) const { |
236 |
|
JSObject *proto = getProto(); |
237 |
|
if (proto) |
238 |
|
JS_CALL_OBJECT_TRACER(trc, proto, "__proto__"); |
239 |
|
|
240 |
|
JSObject *parent = getParent(); |
241 |
|
if (parent) |
242 |
|
JS_CALL_OBJECT_TRACER(trc, parent, "__parent__"); |
243 |
|
} |
244 |
|
|
245 |
|
void *getPrivate() const { |
246 |
|
JS_ASSERT(getClass()->flags & JSCLASS_HAS_PRIVATE); |
247 |
|
jsval v = fslots[JSSLOT_PRIVATE]; |
248 |
|
JS_ASSERT((v & jsval(1)) == jsval(0)); |
249 |
|
return reinterpret_cast<void *>(v); |
250 |
|
} |
251 |
|
|
252 |
|
void setPrivate(void *data) { |
253 |
|
JS_ASSERT(getClass()->flags & JSCLASS_HAS_PRIVATE); |
254 |
|
jsval v = reinterpret_cast<jsval>(data); |
255 |
|
JS_ASSERT((v & jsval(1)) == jsval(0)); |
256 |
|
fslots[JSSLOT_PRIVATE] = v; |
257 |
|
} |
258 |
|
|
259 |
|
static jsval defaultPrivate(JSClass *clasp) { |
260 |
|
return (clasp->flags & JSCLASS_HAS_PRIVATE) |
261 |
|
? JSVAL_NULL |
262 |
|
: JSVAL_VOID; |
263 |
|
} |
264 |
|
|
265 |
|
/* The map field is not initialized here and should be set separately. */ |
266 |
|
void init(JSClass *clasp, JSObject *proto, JSObject *parent, |
267 |
|
jsval privateSlotValue) { |
268 |
|
JS_ASSERT(((jsuword) clasp & 3) == 0); |
269 |
|
JS_STATIC_ASSERT(JSSLOT_PRIVATE + 3 == JS_INITIAL_NSLOTS); |
270 |
|
JS_ASSERT_IF(clasp->flags & JSCLASS_HAS_PRIVATE, |
271 |
|
(privateSlotValue & jsval(1)) == jsval(0)); |
272 |
|
|
273 |
|
classword = jsuword(clasp); |
274 |
|
JS_ASSERT(!isDelegate()); |
275 |
|
JS_ASSERT(!isSystem()); |
276 |
|
|
277 |
|
setProto(proto); |
278 |
|
setParent(parent); |
279 |
|
fslots[JSSLOT_PRIVATE] = privateSlotValue; |
280 |
|
fslots[JSSLOT_PRIVATE + 1] = JSVAL_VOID; |
281 |
|
fslots[JSSLOT_PRIVATE + 2] = JSVAL_VOID; |
282 |
|
dslots = NULL; |
283 |
|
} |
284 |
|
|
285 |
|
/* |
286 |
|
* Like init, but also initializes map. The catch: proto must be the result |
287 |
|
* of a call to js_InitClass(...clasp, ...). |
288 |
|
*/ |
289 |
|
inline void initSharingEmptyScope(JSClass *clasp, JSObject *proto, JSObject *parent, |
290 |
|
jsval privateSlotValue); |
291 |
|
|
292 |
|
JSBool lookupProperty(JSContext *cx, jsid id, |
293 |
|
JSObject **objp, JSProperty **propp) { |
294 |
|
return map->ops->lookupProperty(cx, this, id, objp, propp); |
295 |
|
} |
296 |
|
|
297 |
|
JSBool defineProperty(JSContext *cx, jsid id, jsval value, |
298 |
|
JSPropertyOp getter = JS_PropertyStub, |
299 |
|
JSPropertyOp setter = JS_PropertyStub, |
300 |
|
uintN attrs = JSPROP_ENUMERATE) { |
301 |
|
return map->ops->defineProperty(cx, this, id, value, getter, setter, attrs); |
302 |
|
} |
303 |
|
|
304 |
|
JSBool getProperty(JSContext *cx, jsid id, jsval *vp) { |
305 |
|
return map->ops->getProperty(cx, this, id, vp); |
306 |
|
} |
307 |
|
|
308 |
|
JSBool setProperty(JSContext *cx, jsid id, jsval *vp) { |
309 |
|
return map->ops->setProperty(cx, this, id, vp); |
310 |
|
} |
311 |
|
|
312 |
|
JSBool getAttributes(JSContext *cx, jsid id, JSProperty *prop, |
313 |
|
uintN *attrsp) { |
314 |
|
return map->ops->getAttributes(cx, this, id, prop, attrsp); |
315 |
|
} |
316 |
|
|
317 |
|
JSBool setAttributes(JSContext *cx, jsid id, JSProperty *prop, |
318 |
|
uintN *attrsp) { |
319 |
|
return map->ops->setAttributes(cx, this, id, prop, attrsp); |
320 |
|
} |
321 |
|
|
322 |
|
JSBool deleteProperty(JSContext *cx, jsid id, jsval *rval) { |
323 |
|
return map->ops->deleteProperty(cx, this, id, rval); |
324 |
|
} |
325 |
|
|
326 |
|
JSBool defaultValue(JSContext *cx, JSType hint, jsval *vp) { |
327 |
|
return map->ops->defaultValue(cx, this, hint, vp); |
328 |
|
} |
329 |
|
|
330 |
|
JSBool enumerate(JSContext *cx, JSIterateOp op, jsval *statep, |
331 |
|
jsid *idp) { |
332 |
|
return map->ops->enumerate(cx, this, op, statep, idp); |
333 |
|
} |
334 |
|
|
335 |
|
JSBool checkAccess(JSContext *cx, jsid id, JSAccessMode mode, jsval *vp, |
336 |
|
uintN *attrsp) { |
337 |
|
return map->ops->checkAccess(cx, this, id, mode, vp, attrsp); |
338 |
|
} |
339 |
|
|
340 |
|
/* These four are time-optimized to avoid stub calls. */ |
341 |
|
JSObject *thisObject(JSContext *cx) { |
342 |
|
return map->ops->thisObject ? map->ops->thisObject(cx, this) : this; |
343 |
|
} |
344 |
|
|
345 |
|
void dropProperty(JSContext *cx, JSProperty *prop) { |
346 |
|
if (map->ops->dropProperty) |
347 |
|
map->ops->dropProperty(cx, this, prop); |
348 |
|
} |
349 |
|
|
350 |
|
#endif /* __cplusplus */ |
351 |
}; |
}; |
352 |
|
|
353 |
#define JSSLOT_PROTO 0 |
/* Compatibility macros. */ |
354 |
#define JSSLOT_PARENT 1 |
#define STOBJ_GET_PROTO(obj) ((obj)->getProto()) |
355 |
#define JSSLOT_PRIVATE 2 |
#define STOBJ_SET_PROTO(obj,proto) ((obj)->setProto(proto)) |
356 |
|
#define STOBJ_CLEAR_PROTO(obj) ((obj)->clearProto()) |
357 |
|
|
358 |
|
#define STOBJ_GET_PARENT(obj) ((obj)->getParent()) |
359 |
|
#define STOBJ_SET_PARENT(obj,parent) ((obj)->setParent(parent)) |
360 |
|
#define STOBJ_CLEAR_PARENT(obj) ((obj)->clearParent()) |
361 |
|
|
362 |
|
#define OBJ_GET_PROTO(cx,obj) STOBJ_GET_PROTO(obj) |
363 |
|
#define OBJ_SET_PROTO(cx,obj,proto) STOBJ_SET_PROTO(obj, proto) |
364 |
|
#define OBJ_CLEAR_PROTO(cx,obj) STOBJ_CLEAR_PROTO(obj) |
365 |
|
|
366 |
|
#define OBJ_GET_PARENT(cx,obj) STOBJ_GET_PARENT(obj) |
367 |
|
#define OBJ_SET_PARENT(cx,obj,parent) STOBJ_SET_PARENT(obj, parent) |
368 |
|
#define OBJ_CLEAR_PARENT(cx,obj) STOBJ_CLEAR_PARENT(obj) |
369 |
|
|
370 |
#define JSSLOT_START(clasp) (((clasp)->flags & JSCLASS_HAS_PRIVATE) \ |
#define JSSLOT_START(clasp) (((clasp)->flags & JSCLASS_HAS_PRIVATE) \ |
371 |
? JSSLOT_PRIVATE + 1 \ |
? JSSLOT_PRIVATE + 1 \ |
372 |
: JSSLOT_PARENT + 1) |
: JSSLOT_PRIVATE) |
373 |
|
|
374 |
#define JSSLOT_FREE(clasp) (JSSLOT_START(clasp) \ |
#define JSSLOT_FREE(clasp) (JSSLOT_START(clasp) \ |
375 |
+ JSCLASS_RESERVED_SLOTS(clasp)) |
+ JSCLASS_RESERVED_SLOTS(clasp)) |
376 |
|
|
377 |
/* |
/* |
378 |
* Maximum net gross capacity of the obj->dslots vector, excluding the additional |
* Maximum capacity of the obj->dslots vector, net of the hidden slot at |
379 |
* hidden slot used to store the length of the vector. |
* obj->dslots[-1] that is used to store the length of the vector biased by |
380 |
|
* JS_INITIAL_NSLOTS (and again net of the slot at index -1). |
381 |
*/ |
*/ |
382 |
#define MAX_DSLOTS_LENGTH (JS_MAX(~(uint32)0, ~(size_t)0) / sizeof(jsval)) |
#define MAX_DSLOTS_LENGTH (JS_MAX(~uint32(0), ~size_t(0)) / sizeof(jsval) - 1) |
383 |
|
#define MAX_DSLOTS_LENGTH32 (~uint32(0) / sizeof(jsval) - 1) |
384 |
|
|
385 |
/* |
/* |
386 |
* STOBJ prefix means Single Threaded Object. Use the following fast macros to |
* STOBJ prefix means Single Threaded Object. Use the following fast macros to |
403 |
: (JS_ASSERT((slot) < (uint32)(obj)->dslots[-1]), \ |
: (JS_ASSERT((slot) < (uint32)(obj)->dslots[-1]), \ |
404 |
(obj)->dslots[(slot) - JS_INITIAL_NSLOTS] = (value))) |
(obj)->dslots[(slot) - JS_INITIAL_NSLOTS] = (value))) |
405 |
|
|
406 |
#define STOBJ_GET_PROTO(obj) \ |
#ifdef __cplusplus /* Allow inclusion from LiveConnect C files. */ |
407 |
JSVAL_TO_OBJECT((obj)->fslots[JSSLOT_PROTO]) |
inline JSClass* |
408 |
#define STOBJ_SET_PROTO(obj,proto) \ |
STOBJ_GET_CLASS(const JSObject* obj) |
409 |
(void)(STOBJ_NULLSAFE_SET_DELEGATE(proto), \ |
{ |
410 |
(obj)->fslots[JSSLOT_PROTO] = OBJECT_TO_JSVAL(proto)) |
return obj->getClass(); |
411 |
#define STOBJ_CLEAR_PROTO(obj) \ |
} |
412 |
((obj)->fslots[JSSLOT_PROTO] = JSVAL_NULL) |
#else |
|
|
|
|
#define STOBJ_GET_PARENT(obj) \ |
|
|
JSVAL_TO_OBJECT((obj)->fslots[JSSLOT_PARENT]) |
|
|
#define STOBJ_SET_PARENT(obj,parent) \ |
|
|
(void)(STOBJ_NULLSAFE_SET_DELEGATE(parent), \ |
|
|
(obj)->fslots[JSSLOT_PARENT] = OBJECT_TO_JSVAL(parent)) |
|
|
#define STOBJ_CLEAR_PARENT(obj) \ |
|
|
((obj)->fslots[JSSLOT_PARENT] = JSVAL_NULL) |
|
|
|
|
|
/* |
|
|
* We use JSObject.classword to store both JSClass* and the delegate and system |
|
|
* flags in the two least significant bits. We do *not* synchronize updates of |
|
|
* obj->classword -- API clients must take care. |
|
|
*/ |
|
|
#define JSSLOT_CLASS_MASK_BITS 3 |
|
|
|
|
413 |
static JS_ALWAYS_INLINE JSClass* |
static JS_ALWAYS_INLINE JSClass* |
414 |
STOBJ_GET_CLASS(const JSObject* obj) |
STOBJ_GET_CLASS(const JSObject* obj) |
415 |
{ |
{ |
416 |
return (JSClass *) (obj->classword & ~JSSLOT_CLASS_MASK_BITS); |
return (JSClass *) (obj->classword & ~JSSLOT_CLASS_MASK_BITS); |
417 |
} |
} |
418 |
|
#endif |
|
#define STOBJ_IS_DELEGATE(obj) (((obj)->classword & 1) != 0) |
|
|
#define STOBJ_SET_DELEGATE(obj) ((obj)->classword |= 1) |
|
|
#define STOBJ_NULLSAFE_SET_DELEGATE(obj) \ |
|
|
(!(obj) || STOBJ_SET_DELEGATE((JSObject*)obj)) |
|
|
#define STOBJ_IS_SYSTEM(obj) (((obj)->classword & 2) != 0) |
|
|
#define STOBJ_SET_SYSTEM(obj) ((obj)->classword |= 2) |
|
|
|
|
|
#define STOBJ_GET_PRIVATE(obj) \ |
|
|
(JS_ASSERT(JSVAL_IS_INT(STOBJ_GET_SLOT(obj, JSSLOT_PRIVATE))), \ |
|
|
JSVAL_TO_PRIVATE(STOBJ_GET_SLOT(obj, JSSLOT_PRIVATE))) |
|
419 |
|
|
420 |
#define OBJ_CHECK_SLOT(obj,slot) \ |
#define OBJ_CHECK_SLOT(obj,slot) \ |
421 |
JS_ASSERT_IF(OBJ_IS_NATIVE(obj), slot < OBJ_SCOPE(obj)->freeslot) |
(JS_ASSERT(OBJ_IS_NATIVE(obj)), JS_ASSERT(slot < OBJ_SCOPE(obj)->freeslot)) |
422 |
|
|
423 |
#define LOCKED_OBJ_GET_SLOT(obj,slot) \ |
#define LOCKED_OBJ_GET_SLOT(obj,slot) \ |
424 |
(OBJ_CHECK_SLOT(obj, slot), STOBJ_GET_SLOT(obj, slot)) |
(OBJ_CHECK_SLOT(obj, slot), STOBJ_GET_SLOT(obj, slot)) |
430 |
* that may contain a function reference already, or where the new value is a |
* that may contain a function reference already, or where the new value is a |
431 |
* function ref, and the object's scope may be branded with a property cache |
* function ref, and the object's scope may be branded with a property cache |
432 |
* structural type capability that distinguishes versions of the object with |
* structural type capability that distinguishes versions of the object with |
433 |
* and without the function property. Instead use LOCKED_OBJ_WRITE_BARRIER or |
* and without the function property. Instead use LOCKED_OBJ_WRITE_SLOT or a |
434 |
* a fast inline equivalent (JSOP_SETNAME/JSOP_SETPROP cases in jsinterp.c). |
* fast inline equivalent (JSOP_SETNAME/JSOP_SETPROP cases in jsinterp.cpp). |
435 |
*/ |
*/ |
436 |
#define LOCKED_OBJ_WRITE_BARRIER(cx,obj,slot,newval) \ |
#define LOCKED_OBJ_WRITE_SLOT(cx,obj,slot,newval) \ |
437 |
JS_BEGIN_MACRO \ |
JS_BEGIN_MACRO \ |
438 |
JSScope *scope_ = OBJ_SCOPE(obj); \ |
LOCKED_OBJ_WRITE_BARRIER(cx, obj, slot, newval); \ |
|
JS_ASSERT(scope_->object == (obj)); \ |
|
|
GC_WRITE_BARRIER(cx, scope_, LOCKED_OBJ_GET_SLOT(obj, slot), newval); \ |
|
439 |
LOCKED_OBJ_SET_SLOT(obj, slot, newval); \ |
LOCKED_OBJ_SET_SLOT(obj, slot, newval); \ |
440 |
JS_END_MACRO |
JS_END_MACRO |
441 |
|
|
442 |
#define LOCKED_OBJ_GET_PROTO(obj) \ |
/* |
443 |
(OBJ_CHECK_SLOT(obj, JSSLOT_PROTO), STOBJ_GET_PROTO(obj)) |
* Write barrier macro monitoring property update for slot in obj from its old |
444 |
#define LOCKED_OBJ_SET_PROTO(obj,proto) \ |
* value to newval. |
445 |
(OBJ_CHECK_SLOT(obj, JSSLOT_PROTO), STOBJ_SET_PROTO(obj, proto)) |
* |
446 |
|
* NB: obj must be locked, and remains locked after the calls to this macro. |
447 |
#define LOCKED_OBJ_GET_PARENT(obj) \ |
*/ |
448 |
(OBJ_CHECK_SLOT(obj, JSSLOT_PARENT), STOBJ_GET_PARENT(obj)) |
#define LOCKED_OBJ_WRITE_BARRIER(cx,obj,slot,newval) \ |
449 |
#define LOCKED_OBJ_SET_PARENT(obj,parent) \ |
JS_BEGIN_MACRO \ |
450 |
(OBJ_CHECK_SLOT(obj, JSSLOT_PARENT), STOBJ_SET_PARENT(obj, parent)) |
JSScope *scope_ = OBJ_SCOPE(obj); \ |
451 |
|
JS_ASSERT(scope_->object == obj); \ |
452 |
#define LOCKED_OBJ_GET_CLASS(obj) \ |
if (scope_->branded()) { \ |
453 |
STOBJ_GET_CLASS(obj) |
jsval oldval_ = LOCKED_OBJ_GET_SLOT(obj, slot); \ |
454 |
|
if (oldval_ != (newval) && \ |
455 |
#define LOCKED_OBJ_GET_PRIVATE(obj) \ |
(VALUE_IS_FUNCTION(cx, oldval_) || \ |
456 |
(OBJ_CHECK_SLOT(obj, JSSLOT_PRIVATE), STOBJ_GET_PRIVATE(obj)) |
VALUE_IS_FUNCTION(cx, newval))) { \ |
457 |
|
scope_->methodShapeChange(cx, slot, newval); \ |
458 |
|
} \ |
459 |
|
} \ |
460 |
|
GC_POKE(cx, oldval); \ |
461 |
|
JS_END_MACRO |
462 |
|
|
463 |
#ifdef JS_THREADSAFE |
#ifdef JS_THREADSAFE |
464 |
|
|
465 |
/* Thread-safe functions and wrapper macros for accessing slots in obj. */ |
/* Thread-safe functions and wrapper macros for accessing slots in obj. */ |
466 |
#define OBJ_GET_SLOT(cx,obj,slot) \ |
#define OBJ_GET_SLOT(cx,obj,slot) \ |
467 |
(OBJ_CHECK_SLOT(obj, slot), \ |
(OBJ_CHECK_SLOT(obj, slot), \ |
468 |
(OBJ_IS_NATIVE(obj) && OBJ_SCOPE(obj)->title.ownercx == cx) \ |
(OBJ_SCOPE(obj)->title.ownercx == cx) \ |
469 |
? LOCKED_OBJ_GET_SLOT(obj, slot) \ |
? LOCKED_OBJ_GET_SLOT(obj, slot) \ |
470 |
: js_GetSlotThreadSafe(cx, obj, slot)) |
: js_GetSlotThreadSafe(cx, obj, slot)) |
471 |
|
|
472 |
#define OBJ_SET_SLOT(cx,obj,slot,value) \ |
#define OBJ_SET_SLOT(cx,obj,slot,value) \ |
473 |
JS_BEGIN_MACRO \ |
JS_BEGIN_MACRO \ |
474 |
OBJ_CHECK_SLOT(obj, slot); \ |
OBJ_CHECK_SLOT(obj, slot); \ |
475 |
if (OBJ_IS_NATIVE(obj) && OBJ_SCOPE(obj)->title.ownercx == cx) \ |
if (OBJ_SCOPE(obj)->title.ownercx == cx) \ |
476 |
LOCKED_OBJ_WRITE_BARRIER(cx, obj, slot, value); \ |
LOCKED_OBJ_WRITE_SLOT(cx, obj, slot, value); \ |
477 |
else \ |
else \ |
478 |
js_SetSlotThreadSafe(cx, obj, slot, value); \ |
js_SetSlotThreadSafe(cx, obj, slot, value); \ |
479 |
JS_END_MACRO |
JS_END_MACRO |
499 |
#else /* !JS_THREADSAFE */ |
#else /* !JS_THREADSAFE */ |
500 |
|
|
501 |
#define OBJ_GET_SLOT(cx,obj,slot) LOCKED_OBJ_GET_SLOT(obj,slot) |
#define OBJ_GET_SLOT(cx,obj,slot) LOCKED_OBJ_GET_SLOT(obj,slot) |
502 |
#define OBJ_SET_SLOT(cx,obj,slot,value) LOCKED_OBJ_WRITE_BARRIER(cx,obj,slot, \ |
#define OBJ_SET_SLOT(cx,obj,slot,value) LOCKED_OBJ_WRITE_SLOT(cx,obj,slot,value) |
|
value) |
|
503 |
|
|
504 |
#endif /* !JS_THREADSAFE */ |
#endif /* !JS_THREADSAFE */ |
505 |
|
|
|
/* Thread-safe delegate, proto, parent, and class access macros. */ |
|
|
#define OBJ_IS_DELEGATE(cx,obj) STOBJ_IS_DELEGATE(obj) |
|
|
#define OBJ_SET_DELEGATE(cx,obj) STOBJ_SET_DELEGATE(obj) |
|
|
|
|
|
#define OBJ_GET_PROTO(cx,obj) STOBJ_GET_PROTO(obj) |
|
|
#define OBJ_SET_PROTO(cx,obj,proto) STOBJ_SET_PROTO(obj, proto) |
|
|
#define OBJ_CLEAR_PROTO(cx,obj) STOBJ_CLEAR_PROTO(obj) |
|
|
|
|
|
#define OBJ_GET_PARENT(cx,obj) STOBJ_GET_PARENT(obj) |
|
|
#define OBJ_SET_PARENT(cx,obj,parent) STOBJ_SET_PARENT(obj, parent) |
|
|
#define OBJ_CLEAR_PARENT(cx,obj) STOBJ_CLEAR_PARENT(obj) |
|
|
|
|
506 |
/* |
/* |
507 |
* Class is invariant and comes from the fixed clasp member. Thus no locking |
* Class is invariant and comes from the fixed clasp member. Thus no locking |
508 |
* is necessary to read it. Same for the private slot. |
* is necessary to read it. Same for the private slot. |
509 |
*/ |
*/ |
510 |
#define OBJ_GET_CLASS(cx,obj) STOBJ_GET_CLASS(obj) |
#define OBJ_GET_CLASS(cx,obj) STOBJ_GET_CLASS(obj) |
|
#define OBJ_GET_PRIVATE(cx,obj) STOBJ_GET_PRIVATE(obj) |
|
511 |
|
|
512 |
/* |
/* |
513 |
* Test whether the object is native. FIXME bug 492938: consider how it would |
* Test whether the object is native. FIXME bug 492938: consider how it would |
518 |
|
|
519 |
#define OBJ_IS_NATIVE(obj) OPS_IS_NATIVE((obj)->map->ops) |
#define OBJ_IS_NATIVE(obj) OPS_IS_NATIVE((obj)->map->ops) |
520 |
|
|
521 |
|
#ifdef __cplusplus |
522 |
|
inline void |
523 |
|
OBJ_TO_INNER_OBJECT(JSContext *cx, JSObject *&obj) |
524 |
|
{ |
525 |
|
JSClass *clasp = OBJ_GET_CLASS(cx, obj); |
526 |
|
if (clasp->flags & JSCLASS_IS_EXTENDED) { |
527 |
|
JSExtendedClass *xclasp = (JSExtendedClass *) clasp; |
528 |
|
if (xclasp->innerObject) |
529 |
|
obj = xclasp->innerObject(cx, obj); |
530 |
|
} |
531 |
|
} |
532 |
|
|
533 |
|
/* |
534 |
|
* The following function has been copied to jsd/jsd_val.c. If making changes to |
535 |
|
* OBJ_TO_OUTER_OBJECT, please update jsd/jsd_val.c as well. |
536 |
|
*/ |
537 |
|
inline void |
538 |
|
OBJ_TO_OUTER_OBJECT(JSContext *cx, JSObject *&obj) |
539 |
|
{ |
540 |
|
JSClass *clasp = OBJ_GET_CLASS(cx, obj); |
541 |
|
if (clasp->flags & JSCLASS_IS_EXTENDED) { |
542 |
|
JSExtendedClass *xclasp = (JSExtendedClass *) clasp; |
543 |
|
if (xclasp->outerObject) |
544 |
|
obj = xclasp->outerObject(cx, obj); |
545 |
|
} |
546 |
|
} |
547 |
|
#endif |
548 |
|
|
549 |
extern JS_FRIEND_DATA(JSObjectOps) js_ObjectOps; |
extern JS_FRIEND_DATA(JSObjectOps) js_ObjectOps; |
550 |
extern JS_FRIEND_DATA(JSObjectOps) js_WithObjectOps; |
extern JS_FRIEND_DATA(JSObjectOps) js_WithObjectOps; |
551 |
extern JSClass js_ObjectClass; |
extern JSClass js_ObjectClass; |
569 |
*/ |
*/ |
570 |
#define JSSLOT_BLOCK_DEPTH (JSSLOT_PRIVATE + 1) |
#define JSSLOT_BLOCK_DEPTH (JSSLOT_PRIVATE + 1) |
571 |
|
|
572 |
#define OBJ_IS_CLONED_BLOCK(obj) \ |
#ifdef __cplusplus /* Allow inclusion from LiveConnect C files. */ |
573 |
(OBJ_SCOPE(obj)->object != (obj)) |
static inline bool |
574 |
|
OBJ_IS_CLONED_BLOCK(JSObject *obj) |
575 |
|
{ |
576 |
|
return obj->getProto() != NULL; |
577 |
|
} |
578 |
|
#else |
579 |
|
static JSBool |
580 |
|
OBJ_IS_CLONED_BLOCK(JSObject *obj) |
581 |
|
{ |
582 |
|
return JSVAL_TO_OBJECT(obj->fslots[JSSLOT_PROTO]) != NULL; |
583 |
|
} |
584 |
|
#endif |
585 |
|
|
586 |
|
extern JSBool |
587 |
|
js_DefineBlockVariable(JSContext *cx, JSObject *obj, jsid id, int16 index); |
588 |
|
|
589 |
#define OBJ_BLOCK_COUNT(cx,obj) \ |
#define OBJ_BLOCK_COUNT(cx,obj) \ |
590 |
(OBJ_SCOPE(obj)->entryCount) |
(OBJ_SCOPE(obj)->entryCount) |
591 |
#define OBJ_BLOCK_DEPTH(cx,obj) \ |
#define OBJ_BLOCK_DEPTH(cx,obj) \ |
599 |
* With object that does not correspond to a stack slot, pass -1 for depth. |
* With object that does not correspond to a stack slot, pass -1 for depth. |
600 |
* |
* |
601 |
* When popping the stack across this object's "with" statement, client code |
* When popping the stack across this object's "with" statement, client code |
602 |
* must call JS_SetPrivate(cx, withobj, NULL). |
* must call withobj->setPrivate(NULL). |
603 |
*/ |
*/ |
604 |
extern JS_REQUIRES_STACK JSObject * |
extern JS_REQUIRES_STACK JSObject * |
605 |
js_NewWithObject(JSContext *cx, JSObject *proto, JSObject *parent, jsint depth); |
js_NewWithObject(JSContext *cx, JSObject *proto, JSObject *parent, jsint depth); |
614 |
js_NewBlockObject(JSContext *cx); |
js_NewBlockObject(JSContext *cx); |
615 |
|
|
616 |
extern JSObject * |
extern JSObject * |
617 |
js_CloneBlockObject(JSContext *cx, JSObject *proto, JSObject *parent, |
js_CloneBlockObject(JSContext *cx, JSObject *proto, JSStackFrame *fp); |
|
JSStackFrame *fp); |
|
618 |
|
|
619 |
extern JS_REQUIRES_STACK JSBool |
extern JS_REQUIRES_STACK JSBool |
620 |
js_PutBlockObject(JSContext *cx, JSBool normalUnwind); |
js_PutBlockObject(JSContext *cx, JSBool normalUnwind); |
690 |
extern JSBool |
extern JSBool |
691 |
js_GetClassId(JSContext *cx, JSClass *clasp, jsid *idp); |
js_GetClassId(JSContext *cx, JSClass *clasp, jsid *idp); |
692 |
|
|
693 |
|
#ifdef __cplusplus /* Allow inclusion from LiveConnect C files. */ |
694 |
|
extern JSObject * |
695 |
|
js_NewObject(JSContext *cx, JSClass *clasp, JSObject *proto, |
696 |
|
JSObject *parent, size_t objectSize = 0); |
697 |
|
#else |
698 |
extern JSObject * |
extern JSObject * |
699 |
js_NewObject(JSContext *cx, JSClass *clasp, JSObject *proto, JSObject *parent, |
js_NewObject(JSContext *cx, JSClass *clasp, JSObject *proto, |
700 |
uintN objectSize); |
JSObject *parent, size_t objectSize); |
701 |
|
#endif |
702 |
|
|
703 |
/* |
/* |
704 |
* See jsapi.h, JS_NewObjectWithGivenProto. |
* See jsapi.h, JS_NewObjectWithGivenProto. |
|
* |
|
|
* objectSize is either the explicit size for the allocated object or 0 |
|
|
* indicating to use the default size based on object's class. |
|
705 |
*/ |
*/ |
706 |
|
#ifdef __cplusplus /* Allow inclusion from LiveConnect C files. */ |
707 |
extern JSObject * |
extern JSObject * |
708 |
js_NewObjectWithGivenProto(JSContext *cx, JSClass *clasp, JSObject *proto, |
js_NewObjectWithGivenProto(JSContext *cx, JSClass *clasp, JSObject *proto, |
709 |
JSObject *parent, uintN objectSize); |
JSObject *parent, size_t objectSize = 0); |
710 |
|
#else |
711 |
|
extern JSObject * |
712 |
|
js_NewObjectWithGivenProto(JSContext *cx, JSClass *clasp, JSObject *proto, |
713 |
|
JSObject *parent, size_t objectSize); |
714 |
|
#endif |
715 |
|
|
716 |
/* |
/* |
717 |
* Allocate a new native object and initialize all fslots with JSVAL_VOID |
* Allocate a new native object with the given value of the proto and private |
718 |
* starting with the specified slot. The parent slot is set to the value of |
* slots. The parent slot is set to the value of proto's parent slot. |
719 |
* proto's parent slot. |
* |
720 |
|
* clasp must be a native class. proto must be the result of a call to |
721 |
|
* js_InitClass(...clasp, ...). |
722 |
* |
* |
723 |
* Note that this is the correct global object for native class instances, but |
* Note that this is the correct global object for native class instances, but |
724 |
* not for user-defined functions called as constructors. Functions used as |
* not for user-defined functions called as constructors. Functions used as |
726 |
* object, not by the parent of its .prototype object value. |
* object, not by the parent of its .prototype object value. |
727 |
*/ |
*/ |
728 |
extern JSObject* |
extern JSObject* |
729 |
js_NewNativeObject(JSContext *cx, JSClass *clasp, JSObject *proto, uint32 slot); |
js_NewObjectWithClassProto(JSContext *cx, JSClass *clasp, JSObject *proto, |
730 |
|
jsval privateSlotValue); |
731 |
|
|
732 |
/* |
/* |
733 |
* Fast access to immutable standard objects (constructors and prototypes). |
* Fast access to immutable standard objects (constructors and prototypes). |
746 |
js_ConstructObject(JSContext *cx, JSClass *clasp, JSObject *proto, |
js_ConstructObject(JSContext *cx, JSClass *clasp, JSObject *proto, |
747 |
JSObject *parent, uintN argc, jsval *argv); |
JSObject *parent, uintN argc, jsval *argv); |
748 |
|
|
|
extern void |
|
|
js_FinalizeObject(JSContext *cx, JSObject *obj); |
|
|
|
|
749 |
extern JSBool |
extern JSBool |
750 |
js_AllocSlot(JSContext *cx, JSObject *obj, uint32 *slotp); |
js_AllocSlot(JSContext *cx, JSObject *obj, uint32 *slotp); |
751 |
|
|
752 |
extern void |
extern void |
753 |
js_FreeSlot(JSContext *cx, JSObject *obj, uint32 slot); |
js_FreeSlot(JSContext *cx, JSObject *obj, uint32 slot); |
754 |
|
|
755 |
/* JSVAL_INT_MAX as a string */ |
#ifdef __cplusplus /* Allow inclusion from LiveConnect C files. */ |
756 |
#define JSVAL_INT_MAX_STRING "1073741823" |
extern bool |
757 |
|
#else |
758 |
|
extern JSBool |
759 |
|
#endif |
760 |
|
js_GrowSlots(JSContext *cx, JSObject *obj, size_t nslots); |
761 |
|
|
762 |
|
extern void |
763 |
|
js_ShrinkSlots(JSContext *cx, JSObject *obj, size_t nslots); |
764 |
|
|
765 |
|
static inline void |
766 |
|
js_FreeSlots(JSContext *cx, JSObject *obj) |
767 |
|
{ |
768 |
|
if (obj->dslots) |
769 |
|
js_ShrinkSlots(cx, obj, 0); |
770 |
|
} |
771 |
|
|
772 |
/* |
/* |
773 |
* Convert string indexes that convert to int jsvals as ints to save memory. |
* Ensure that the object has at least JSCLASS_RESERVED_SLOTS(clasp)+nreserved |
774 |
* Care must be taken to use this macro every time a property name is used, or |
* slots. The function can be called only for native objects just created with |
775 |
* else double-sets, incorrect property cache misses, or other mistakes could |
* js_NewObject or its forms. In particular, the object should not be shared |
776 |
* occur. |
* between threads and its dslots array must be null. nreserved must match the |
777 |
*/ |
* value that JSClass.reserveSlots (if any) would return after the object is |
778 |
#define CHECK_FOR_STRING_INDEX(id) \ |
* fully initialized. |
779 |
JS_BEGIN_MACRO \ |
*/ |
780 |
if (JSID_IS_ATOM(id)) { \ |
#ifdef __cplusplus /* Allow inclusion from LiveConnect C files. */ |
781 |
JSAtom *atom_ = JSID_TO_ATOM(id); \ |
bool |
782 |
JSString *str_ = ATOM_TO_STRING(atom_); \ |
#else |
783 |
const jschar *s_ = JSFLATSTR_CHARS(str_); \ |
JSBool |
784 |
JSBool negative_ = (*s_ == '-'); \ |
#endif |
785 |
if (negative_) s_++; \ |
js_EnsureReservedSlots(JSContext *cx, JSObject *obj, size_t nreserved); |
|
if (JS7_ISDEC(*s_)) { \ |
|
|
size_t n_ = JSFLATSTR_LENGTH(str_) - negative_; \ |
|
|
if (n_ <= sizeof(JSVAL_INT_MAX_STRING) - 1) \ |
|
|
id = js_CheckForStringIndex(id, s_, s_ + n_, negative_); \ |
|
|
} \ |
|
|
} \ |
|
|
JS_END_MACRO |
|
786 |
|
|
787 |
extern jsid |
extern jsid |
788 |
js_CheckForStringIndex(jsid id, const jschar *cp, const jschar *end, |
js_CheckForStringIndex(jsid id); |
|
JSBool negative); |
|
789 |
|
|
790 |
/* |
/* |
791 |
* js_PurgeScopeChain does nothing if obj is not itself a prototype or parent |
* js_PurgeScopeChain does nothing if obj is not itself a prototype or parent |
800 |
static JS_INLINE void |
static JS_INLINE void |
801 |
js_PurgeScopeChain(JSContext *cx, JSObject *obj, jsid id) |
js_PurgeScopeChain(JSContext *cx, JSObject *obj, jsid id) |
802 |
{ |
{ |
803 |
if (OBJ_IS_DELEGATE(cx, obj)) |
if (obj->isDelegate()) |
804 |
js_PurgeScopeChainHelper(cx, obj, id); |
js_PurgeScopeChainHelper(cx, obj, id); |
805 |
} |
} |
806 |
#endif |
#endif |
824 |
JSScopeProperty *sprop, uintN attrs, uintN mask, |
JSScopeProperty *sprop, uintN attrs, uintN mask, |
825 |
JSPropertyOp getter, JSPropertyOp setter); |
JSPropertyOp getter, JSPropertyOp setter); |
826 |
|
|
|
/* |
|
|
* On error, return false. On success, if propp is non-null, return true with |
|
|
* obj locked and with a held property in *propp; if propp is null, return true |
|
|
* but release obj's lock first. Therefore all callers who pass non-null propp |
|
|
* result parameters must later call OBJ_DROP_PROPERTY(cx, obj, *propp) both to |
|
|
* drop the held property, and to release the lock on obj. |
|
|
*/ |
|
827 |
extern JSBool |
extern JSBool |
828 |
js_DefineProperty(JSContext *cx, JSObject *obj, jsid id, jsval value, |
js_DefineProperty(JSContext *cx, JSObject *obj, jsid id, jsval value, |
829 |
JSPropertyOp getter, JSPropertyOp setter, uintN attrs, |
JSPropertyOp getter, JSPropertyOp setter, uintN attrs); |
|
JSProperty **propp); |
|
830 |
|
|
831 |
#ifdef __cplusplus /* FIXME: bug 442399 removes this LiveConnect requirement. */ |
#ifdef __cplusplus /* Allow inclusion from LiveConnect C files. */ |
832 |
|
|
833 |
/* |
/* |
834 |
* Flags for the defineHow parameter of js_DefineNativeProperty. |
* Flags for the defineHow parameter of js_DefineNativeProperty. |
836 |
const uintN JSDNP_CACHE_RESULT = 1; /* an interpreter call from JSOP_INITPROP */ |
const uintN JSDNP_CACHE_RESULT = 1; /* an interpreter call from JSOP_INITPROP */ |
837 |
const uintN JSDNP_DONT_PURGE = 2; /* suppress js_PurgeScopeChain */ |
const uintN JSDNP_DONT_PURGE = 2; /* suppress js_PurgeScopeChain */ |
838 |
|
|
839 |
|
/* |
840 |
|
* On error, return false. On success, if propp is non-null, return true with |
841 |
|
* obj locked and with a held property in *propp; if propp is null, return true |
842 |
|
* but release obj's lock first. Therefore all callers who pass non-null propp |
843 |
|
* result parameters must later call obj->dropProperty(cx, *propp) both to drop |
844 |
|
* the held property, and to release the lock on obj. |
845 |
|
*/ |
846 |
extern JSBool |
extern JSBool |
847 |
js_DefineNativeProperty(JSContext *cx, JSObject *obj, jsid id, jsval value, |
js_DefineNativeProperty(JSContext *cx, JSObject *obj, jsid id, jsval value, |
848 |
JSPropertyOp getter, JSPropertyOp setter, uintN attrs, |
JSPropertyOp getter, JSPropertyOp setter, uintN attrs, |
849 |
uintN flags, intN shortid, JSProperty **propp, |
uintN flags, intN shortid, JSProperty **propp, |
850 |
uintN defineHow = 0); |
uintN defineHow = 0); |
851 |
#endif |
#endif /* __cplusplus */ |
852 |
|
|
853 |
/* |
/* |
854 |
* Unlike js_DefineProperty, propp must be non-null. On success, and if id was |
* Unlike js_DefineNativeProperty, propp must be non-null. On success, and if |
855 |
* found, return true with *objp non-null and locked, and with a held property |
* id was found, return true with *objp non-null and locked, and with a held |
856 |
* stored in *propp. If successful but id was not found, return true with both |
* property stored in *propp. If successful but id was not found, return true |
857 |
* *objp and *propp null. Therefore all callers who receive a non-null *propp |
* with both *objp and *propp null. Therefore all callers who receive a |
858 |
* must later call OBJ_DROP_PROPERTY(cx, *objp, *propp). |
* non-null *propp must later call (*objp)->dropProperty(cx, *propp). |
859 |
*/ |
*/ |
860 |
extern JS_FRIEND_API(JSBool) |
extern JS_FRIEND_API(JSBool) |
861 |
js_LookupProperty(JSContext *cx, JSObject *obj, jsid id, JSObject **objp, |
js_LookupProperty(JSContext *cx, JSObject *obj, jsid id, JSObject **objp, |
870 |
js_LookupPropertyWithFlags(JSContext *cx, JSObject *obj, jsid id, uintN flags, |
js_LookupPropertyWithFlags(JSContext *cx, JSObject *obj, jsid id, uintN flags, |
871 |
JSObject **objp, JSProperty **propp); |
JSObject **objp, JSProperty **propp); |
872 |
|
|
873 |
|
|
874 |
|
/* |
875 |
|
* We cache name lookup results only for the global object or for native |
876 |
|
* non-global objects without prototype or with prototype that never mutates, |
877 |
|
* see bug 462734 and bug 487039. |
878 |
|
*/ |
879 |
|
#ifdef __cplusplus /* Allow inclusion from LiveConnect C files. */ |
880 |
|
static inline bool |
881 |
|
js_IsCacheableNonGlobalScope(JSObject *obj) |
882 |
|
{ |
883 |
|
extern JS_FRIEND_DATA(JSClass) js_CallClass; |
884 |
|
extern JS_FRIEND_DATA(JSClass) js_DeclEnvClass; |
885 |
|
JS_ASSERT(STOBJ_GET_PARENT(obj)); |
886 |
|
|
887 |
|
JSClass *clasp = STOBJ_GET_CLASS(obj); |
888 |
|
bool cacheable = (clasp == &js_CallClass || |
889 |
|
clasp == &js_BlockClass || |
890 |
|
clasp == &js_DeclEnvClass); |
891 |
|
|
892 |
|
JS_ASSERT_IF(cacheable, obj->map->ops->lookupProperty == js_LookupProperty); |
893 |
|
return cacheable; |
894 |
|
} |
895 |
|
#endif |
896 |
|
|
897 |
/* |
/* |
898 |
* If cacheResult is false, return JS_NO_PROP_CACHE_FILL on success. |
* If cacheResult is false, return JS_NO_PROP_CACHE_FILL on success. |
899 |
*/ |
*/ |
972 |
jsval *statep, jsid *idp); |
jsval *statep, jsid *idp); |
973 |
|
|
974 |
extern void |
extern void |
975 |
js_TraceNativeEnumerators(JSTracer *trc); |
js_MarkEnumeratorState(JSTracer *trc, JSObject *obj, jsval state); |
976 |
|
|
977 |
|
extern void |
978 |
|
js_PurgeCachedNativeEnumerators(JSContext *cx, JSThreadData *data); |
979 |
|
|
980 |
extern JSBool |
extern JSBool |
981 |
js_CheckAccess(JSContext *cx, JSObject *obj, jsid id, JSAccessMode mode, |
js_CheckAccess(JSContext *cx, JSObject *obj, jsid id, JSAccessMode mode, |
1038 |
extern void |
extern void |
1039 |
js_Clear(JSContext *cx, JSObject *obj); |
js_Clear(JSContext *cx, JSObject *obj); |
1040 |
|
|
1041 |
extern jsval |
#ifdef __cplusplus /* Allow inclusion from LiveConnect C files. */ |
1042 |
js_GetRequiredSlot(JSContext *cx, JSObject *obj, uint32 slot); |
extern bool |
1043 |
|
#else |
1044 |
extern JSBool |
extern JSBool |
1045 |
js_SetRequiredSlot(JSContext *cx, JSObject *obj, uint32 slot, jsval v); |
#endif |
1046 |
|
js_GetReservedSlot(JSContext *cx, JSObject *obj, uint32 index, jsval *vp); |
1047 |
|
|
1048 |
|
#ifdef __cplusplus /* Allow inclusion from LiveConnect C files. */ |
1049 |
|
bool |
1050 |
|
#else |
1051 |
|
JSBool |
1052 |
|
#endif |
1053 |
|
js_SetReservedSlot(JSContext *cx, JSObject *obj, uint32 index, jsval v); |
1054 |
|
|
1055 |
/* |
/* |
1056 |
* Precondition: obj must be locked. |
* Precondition: obj must be locked. |
1092 |
JS_FRIEND_API(void) js_DumpValue(jsval val); |
JS_FRIEND_API(void) js_DumpValue(jsval val); |
1093 |
JS_FRIEND_API(void) js_DumpId(jsid id); |
JS_FRIEND_API(void) js_DumpId(jsid id); |
1094 |
JS_FRIEND_API(void) js_DumpObject(JSObject *obj); |
JS_FRIEND_API(void) js_DumpObject(JSObject *obj); |
1095 |
|
JS_FRIEND_API(void) js_DumpStackFrame(JSStackFrame *fp); |
1096 |
#endif |
#endif |
1097 |
|
|
1098 |
|
extern uintN |
1099 |
|
js_InferFlags(JSContext *cx, uintN defaultFlags); |
1100 |
|
|
1101 |
|
/* Object constructor native. Exposed only so the JIT can know its address. */ |
1102 |
|
JSBool |
1103 |
|
js_Object(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval); |
1104 |
|
|
1105 |
JS_END_EXTERN_C |
JS_END_EXTERN_C |
1106 |
|
|
1107 |
#endif /* jsobj_h___ */ |
#endif /* jsobj_h___ */ |