1 |
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- |
2 |
* vim: set ts=8 sw=4 et tw=78: |
3 |
* |
4 |
* ***** BEGIN LICENSE BLOCK ***** |
5 |
* Version: MPL 1.1/GPL 2.0/LGPL 2.1 |
6 |
* |
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/ |
11 |
* |
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 |
15 |
* License. |
16 |
* |
17 |
* The Original Code is Mozilla Communicator client code, released |
18 |
* March 31, 1998. |
19 |
* |
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. |
24 |
* |
25 |
* Contributor(s): |
26 |
* |
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. |
38 |
* |
39 |
* ***** END LICENSE BLOCK ***** */ |
40 |
|
41 |
#ifndef jsobj_h___ |
42 |
#define jsobj_h___ |
43 |
/* |
44 |
* JS object definitions. |
45 |
* |
46 |
* A JS object consists of a possibly-shared object descriptor containing |
47 |
* ordered property names, called the map; and a dense vector of property |
48 |
* values, called slots. The map/slot pointer pair is GC'ed, while the map |
49 |
* is reference counted and the slot vector is malloc'ed. |
50 |
*/ |
51 |
#include "jshash.h" /* Added by JSIFY */ |
52 |
#include "jsprvtd.h" |
53 |
#include "jspubtd.h" |
54 |
|
55 |
JS_BEGIN_EXTERN_C |
56 |
|
57 |
struct JSObjectMap { |
58 |
jsrefcount nrefs; /* count of all referencing objects */ |
59 |
JSObjectOps *ops; /* high level object operation vtable */ |
60 |
uint32 freeslot; /* index of next free slot in object */ |
61 |
}; |
62 |
|
63 |
/* Shorthand macros for frequently-made calls. */ |
64 |
#define OBJ_LOOKUP_PROPERTY(cx,obj,id,objp,propp) \ |
65 |
(obj)->map->ops->lookupProperty(cx,obj,id,objp,propp) |
66 |
#define OBJ_DEFINE_PROPERTY(cx,obj,id,value,getter,setter,attrs,propp) \ |
67 |
(obj)->map->ops->defineProperty(cx,obj,id,value,getter,setter,attrs,propp) |
68 |
#define OBJ_GET_PROPERTY(cx,obj,id,vp) \ |
69 |
(obj)->map->ops->getProperty(cx,obj,id,vp) |
70 |
#define OBJ_SET_PROPERTY(cx,obj,id,vp) \ |
71 |
(obj)->map->ops->setProperty(cx,obj,id,vp) |
72 |
#define OBJ_GET_ATTRIBUTES(cx,obj,id,prop,attrsp) \ |
73 |
(obj)->map->ops->getAttributes(cx,obj,id,prop,attrsp) |
74 |
#define OBJ_SET_ATTRIBUTES(cx,obj,id,prop,attrsp) \ |
75 |
(obj)->map->ops->setAttributes(cx,obj,id,prop,attrsp) |
76 |
#define OBJ_DELETE_PROPERTY(cx,obj,id,rval) \ |
77 |
(obj)->map->ops->deleteProperty(cx,obj,id,rval) |
78 |
#define OBJ_DEFAULT_VALUE(cx,obj,hint,vp) \ |
79 |
(obj)->map->ops->defaultValue(cx,obj,hint,vp) |
80 |
#define OBJ_ENUMERATE(cx,obj,enum_op,statep,idp) \ |
81 |
(obj)->map->ops->enumerate(cx,obj,enum_op,statep,idp) |
82 |
#define OBJ_CHECK_ACCESS(cx,obj,id,mode,vp,attrsp) \ |
83 |
(obj)->map->ops->checkAccess(cx,obj,id,mode,vp,attrsp) |
84 |
|
85 |
/* These four are time-optimized to avoid stub calls. */ |
86 |
#define OBJ_THIS_OBJECT(cx,obj) \ |
87 |
((obj)->map->ops->thisObject \ |
88 |
? (obj)->map->ops->thisObject(cx,obj) \ |
89 |
: (obj)) |
90 |
#define OBJ_DROP_PROPERTY(cx,obj,prop) \ |
91 |
((obj)->map->ops->dropProperty \ |
92 |
? (obj)->map->ops->dropProperty(cx,obj,prop) \ |
93 |
: (void)0) |
94 |
#define OBJ_GET_REQUIRED_SLOT(cx,obj,slot) \ |
95 |
((obj)->map->ops->getRequiredSlot \ |
96 |
? (obj)->map->ops->getRequiredSlot(cx, obj, slot) \ |
97 |
: JSVAL_VOID) |
98 |
#define OBJ_SET_REQUIRED_SLOT(cx,obj,slot,v) \ |
99 |
((obj)->map->ops->setRequiredSlot \ |
100 |
? (obj)->map->ops->setRequiredSlot(cx, obj, slot, v) \ |
101 |
: JS_TRUE) |
102 |
|
103 |
#define OBJ_TO_INNER_OBJECT(cx,obj) \ |
104 |
JS_BEGIN_MACRO \ |
105 |
JSClass *clasp_ = OBJ_GET_CLASS(cx, obj); \ |
106 |
if (clasp_->flags & JSCLASS_IS_EXTENDED) { \ |
107 |
JSExtendedClass *xclasp_ = (JSExtendedClass*)clasp_; \ |
108 |
if (xclasp_->innerObject) \ |
109 |
obj = xclasp_->innerObject(cx, obj); \ |
110 |
} \ |
111 |
JS_END_MACRO |
112 |
|
113 |
#define OBJ_TO_OUTER_OBJECT(cx,obj) \ |
114 |
JS_BEGIN_MACRO \ |
115 |
JSClass *clasp_ = OBJ_GET_CLASS(cx, obj); \ |
116 |
if (clasp_->flags & JSCLASS_IS_EXTENDED) { \ |
117 |
JSExtendedClass *xclasp_ = (JSExtendedClass*)clasp_; \ |
118 |
if (xclasp_->outerObject) \ |
119 |
obj = xclasp_->outerObject(cx, obj); \ |
120 |
} \ |
121 |
JS_END_MACRO |
122 |
|
123 |
#define JS_INITIAL_NSLOTS 5 |
124 |
|
125 |
/* |
126 |
* When JSObject.dslots is not null, JSObject.dslots[-1] records the number of |
127 |
* available slots. |
128 |
*/ |
129 |
struct JSObject { |
130 |
JSObjectMap *map; |
131 |
jsuword classword; |
132 |
jsval fslots[JS_INITIAL_NSLOTS]; |
133 |
jsval *dslots; /* dynamically allocated slots */ |
134 |
}; |
135 |
|
136 |
#define JSSLOT_PROTO 0 |
137 |
#define JSSLOT_PARENT 1 |
138 |
#define JSSLOT_PRIVATE 2 |
139 |
#define JSSLOT_START(clasp) (((clasp)->flags & JSCLASS_HAS_PRIVATE) \ |
140 |
? JSSLOT_PRIVATE + 1 \ |
141 |
: JSSLOT_PARENT + 1) |
142 |
|
143 |
#define JSSLOT_FREE(clasp) (JSSLOT_START(clasp) \ |
144 |
+ JSCLASS_RESERVED_SLOTS(clasp)) |
145 |
|
146 |
/* |
147 |
* STOBJ prefix means Single Threaded Object. Use the following fast macros to |
148 |
* directly manipulate slots in obj when only one thread can access obj and |
149 |
* when obj->map->freeslot can be inconsistent with slots. |
150 |
*/ |
151 |
|
152 |
#define STOBJ_NSLOTS(obj) \ |
153 |
((obj)->dslots ? (uint32)(obj)->dslots[-1] : (uint32)JS_INITIAL_NSLOTS) |
154 |
|
155 |
#define STOBJ_GET_SLOT(obj,slot) \ |
156 |
((slot) < JS_INITIAL_NSLOTS \ |
157 |
? (obj)->fslots[(slot)] \ |
158 |
: (JS_ASSERT((slot) < (uint32)(obj)->dslots[-1]), \ |
159 |
(obj)->dslots[(slot) - JS_INITIAL_NSLOTS])) |
160 |
|
161 |
#define STOBJ_SET_SLOT(obj,slot,value) \ |
162 |
((slot) < JS_INITIAL_NSLOTS \ |
163 |
? (obj)->fslots[(slot)] = (value) \ |
164 |
: (JS_ASSERT((slot) < (uint32)(obj)->dslots[-1]), \ |
165 |
(obj)->dslots[(slot) - JS_INITIAL_NSLOTS] = (value))) |
166 |
|
167 |
#define STOBJ_GET_PROTO(obj) \ |
168 |
JSVAL_TO_OBJECT((obj)->fslots[JSSLOT_PROTO]) |
169 |
#define STOBJ_SET_PROTO(obj,proto) \ |
170 |
(void)(STOBJ_NULLSAFE_SET_DELEGATE(proto), \ |
171 |
(obj)->fslots[JSSLOT_PROTO] = OBJECT_TO_JSVAL(proto)) |
172 |
#define STOBJ_CLEAR_PROTO(obj) \ |
173 |
((obj)->fslots[JSSLOT_PROTO] = JSVAL_NULL) |
174 |
|
175 |
#define STOBJ_GET_PARENT(obj) \ |
176 |
JSVAL_TO_OBJECT((obj)->fslots[JSSLOT_PARENT]) |
177 |
#define STOBJ_SET_PARENT(obj,parent) \ |
178 |
(void)(STOBJ_NULLSAFE_SET_DELEGATE(parent), \ |
179 |
(obj)->fslots[JSSLOT_PARENT] = OBJECT_TO_JSVAL(parent)) |
180 |
#define STOBJ_CLEAR_PARENT(obj) \ |
181 |
((obj)->fslots[JSSLOT_PARENT] = JSVAL_NULL) |
182 |
|
183 |
/* |
184 |
* We use JSObject.classword to store both JSClass* and the delegate and system |
185 |
* flags in the two least significant bits. We do *not* synchronize updates of |
186 |
* obj->classword -- API clients must take care. |
187 |
*/ |
188 |
#define STOBJ_GET_CLASS(obj) ((JSClass *)((obj)->classword & ~3)) |
189 |
#define STOBJ_IS_DELEGATE(obj) (((obj)->classword & 1) != 0) |
190 |
#define STOBJ_SET_DELEGATE(obj) ((obj)->classword |= 1) |
191 |
#define STOBJ_NULLSAFE_SET_DELEGATE(obj) \ |
192 |
(!(obj) || STOBJ_SET_DELEGATE((JSObject*)obj)) |
193 |
#define STOBJ_IS_SYSTEM(obj) (((obj)->classword & 2) != 0) |
194 |
#define STOBJ_SET_SYSTEM(obj) ((obj)->classword |= 2) |
195 |
|
196 |
#define STOBJ_GET_PRIVATE(obj) \ |
197 |
(JS_ASSERT(JSVAL_IS_INT(STOBJ_GET_SLOT(obj, JSSLOT_PRIVATE))), \ |
198 |
JSVAL_TO_PRIVATE(STOBJ_GET_SLOT(obj, JSSLOT_PRIVATE))) |
199 |
|
200 |
#define OBJ_CHECK_SLOT(obj,slot) \ |
201 |
JS_ASSERT(slot < (obj)->map->freeslot) |
202 |
|
203 |
#define LOCKED_OBJ_GET_SLOT(obj,slot) \ |
204 |
(OBJ_CHECK_SLOT(obj, slot), STOBJ_GET_SLOT(obj, slot)) |
205 |
#define LOCKED_OBJ_SET_SLOT(obj,slot,value) \ |
206 |
(OBJ_CHECK_SLOT(obj, slot), STOBJ_SET_SLOT(obj, slot, value)) |
207 |
|
208 |
/* |
209 |
* NB: Don't call LOCKED_OBJ_SET_SLOT or STOBJ_SET_SLOT for a write to a slot |
210 |
* that may contain a function reference already, or where the new value is a |
211 |
* function ref, and the object's scope may be branded with a property cache |
212 |
* structural type capability that distinguishes versions of the object with |
213 |
* and without the function property. Instead use LOCKED_OBJ_WRITE_BARRIER or |
214 |
* a fast inline equivalent (JSOP_SETNAME/JSOP_SETPROP cases in jsinterp.c). |
215 |
*/ |
216 |
#define LOCKED_OBJ_WRITE_BARRIER(cx,obj,slot,newval) \ |
217 |
JS_BEGIN_MACRO \ |
218 |
JSScope *scope_ = OBJ_SCOPE(obj); \ |
219 |
JS_ASSERT(scope_->object == (obj)); \ |
220 |
GC_WRITE_BARRIER(cx, scope_, LOCKED_OBJ_GET_SLOT(obj, slot), newval); \ |
221 |
LOCKED_OBJ_SET_SLOT(obj, slot, newval); \ |
222 |
JS_END_MACRO |
223 |
|
224 |
#define LOCKED_OBJ_GET_PROTO(obj) \ |
225 |
(OBJ_CHECK_SLOT(obj, JSSLOT_PROTO), STOBJ_GET_PROTO(obj)) |
226 |
#define LOCKED_OBJ_SET_PROTO(obj,proto) \ |
227 |
(OBJ_CHECK_SLOT(obj, JSSLOT_PROTO), STOBJ_SET_PROTO(obj, proto)) |
228 |
|
229 |
#define LOCKED_OBJ_GET_PARENT(obj) \ |
230 |
(OBJ_CHECK_SLOT(obj, JSSLOT_PARENT), STOBJ_GET_PARENT(obj)) |
231 |
#define LOCKED_OBJ_SET_PARENT(obj,parent) \ |
232 |
(OBJ_CHECK_SLOT(obj, JSSLOT_PARENT), STOBJ_SET_PARENT(obj, parent)) |
233 |
|
234 |
#define LOCKED_OBJ_GET_CLASS(obj) \ |
235 |
STOBJ_GET_CLASS(obj) |
236 |
|
237 |
#define LOCKED_OBJ_GET_PRIVATE(obj) \ |
238 |
(OBJ_CHECK_SLOT(obj, JSSLOT_PRIVATE), STOBJ_GET_PRIVATE(obj)) |
239 |
|
240 |
#ifdef JS_THREADSAFE |
241 |
|
242 |
/* Thread-safe functions and wrapper macros for accessing slots in obj. */ |
243 |
#define OBJ_GET_SLOT(cx,obj,slot) \ |
244 |
(OBJ_CHECK_SLOT(obj, slot), \ |
245 |
(OBJ_IS_NATIVE(obj) && OBJ_SCOPE(obj)->title.ownercx == cx) \ |
246 |
? LOCKED_OBJ_GET_SLOT(obj, slot) \ |
247 |
: js_GetSlotThreadSafe(cx, obj, slot)) |
248 |
|
249 |
#define OBJ_SET_SLOT(cx,obj,slot,value) \ |
250 |
JS_BEGIN_MACRO \ |
251 |
OBJ_CHECK_SLOT(obj, slot); \ |
252 |
if (OBJ_IS_NATIVE(obj) && OBJ_SCOPE(obj)->title.ownercx == cx) \ |
253 |
LOCKED_OBJ_WRITE_BARRIER(cx, obj, slot, value); \ |
254 |
else \ |
255 |
js_SetSlotThreadSafe(cx, obj, slot, value); \ |
256 |
JS_END_MACRO |
257 |
|
258 |
/* |
259 |
* If thread-safe, define an OBJ_GET_SLOT wrapper that bypasses, for a native |
260 |
* object, the lock-free "fast path" test of (OBJ_SCOPE(obj)->ownercx == cx), |
261 |
* to avoid needlessly switching from lock-free to lock-full scope when doing |
262 |
* GC on a different context from the last one to own the scope. The caller |
263 |
* in this case is probably a JSClass.mark function, e.g., fun_mark, or maybe |
264 |
* a finalizer. |
265 |
* |
266 |
* The GC runs only when all threads except the one on which the GC is active |
267 |
* are suspended at GC-safe points, so calling STOBJ_GET_SLOT from the GC's |
268 |
* thread is safe when rt->gcRunning is set. See jsgc.c for details. |
269 |
*/ |
270 |
#define THREAD_IS_RUNNING_GC(rt, thread) \ |
271 |
((rt)->gcRunning && (rt)->gcThread == (thread)) |
272 |
|
273 |
#define CX_THREAD_IS_RUNNING_GC(cx) \ |
274 |
THREAD_IS_RUNNING_GC((cx)->runtime, (cx)->thread) |
275 |
|
276 |
#else /* !JS_THREADSAFE */ |
277 |
|
278 |
#define OBJ_GET_SLOT(cx,obj,slot) LOCKED_OBJ_GET_SLOT(obj,slot) |
279 |
#define OBJ_SET_SLOT(cx,obj,slot,value) LOCKED_OBJ_WRITE_BARRIER(cx,obj,slot, \ |
280 |
value) |
281 |
|
282 |
#endif /* !JS_THREADSAFE */ |
283 |
|
284 |
/* Thread-safe delegate, proto, parent, and class access macros. */ |
285 |
#define OBJ_IS_DELEGATE(cx,obj) STOBJ_IS_DELEGATE(obj) |
286 |
#define OBJ_SET_DELEGATE(cx,obj) STOBJ_SET_DELEGATE(obj) |
287 |
|
288 |
#define OBJ_GET_PROTO(cx,obj) STOBJ_GET_PROTO(obj) |
289 |
#define OBJ_SET_PROTO(cx,obj,proto) STOBJ_SET_PROTO(obj, proto) |
290 |
#define OBJ_CLEAR_PROTO(cx,obj) STOBJ_CLEAR_PROTO(obj) |
291 |
|
292 |
#define OBJ_GET_PARENT(cx,obj) STOBJ_GET_PARENT(obj) |
293 |
#define OBJ_SET_PARENT(cx,obj,parent) STOBJ_SET_PARENT(obj, parent) |
294 |
#define OBJ_CLEAR_PARENT(cx,obj) STOBJ_CLEAR_PARENT(obj) |
295 |
|
296 |
/* |
297 |
* Class is invariant and comes from the fixed clasp member. Thus no locking |
298 |
* is necessary to read it. Same for the private slot. |
299 |
*/ |
300 |
#define OBJ_GET_CLASS(cx,obj) STOBJ_GET_CLASS(obj) |
301 |
#define OBJ_GET_PRIVATE(cx,obj) STOBJ_GET_PRIVATE(obj) |
302 |
|
303 |
/* Test whether a map or object is native. */ |
304 |
#define MAP_IS_NATIVE(map) \ |
305 |
JS_LIKELY((map)->ops == &js_ObjectOps || \ |
306 |
(map)->ops->newObjectMap == js_ObjectOps.newObjectMap) |
307 |
|
308 |
#define OBJ_IS_NATIVE(obj) MAP_IS_NATIVE((obj)->map) |
309 |
|
310 |
extern JS_FRIEND_DATA(JSObjectOps) js_ObjectOps; |
311 |
extern JS_FRIEND_DATA(JSObjectOps) js_WithObjectOps; |
312 |
extern JSClass js_ObjectClass; |
313 |
extern JSClass js_WithClass; |
314 |
extern JSClass js_BlockClass; |
315 |
|
316 |
/* |
317 |
* Block scope object macros. The slots reserved by js_BlockClass are: |
318 |
* |
319 |
* JSSLOT_PRIVATE JSStackFrame * active frame pointer or null |
320 |
* JSSLOT_BLOCK_DEPTH int depth of block slots in frame |
321 |
* |
322 |
* After JSSLOT_BLOCK_DEPTH come one or more slots for the block locals. |
323 |
* |
324 |
* A With object is like a Block object, in that both have one reserved slot |
325 |
* telling the stack depth of the relevant slots (the slot whose value is the |
326 |
* object named in the with statement, the slots containing the block's local |
327 |
* variables); and both have a private slot referring to the JSStackFrame in |
328 |
* whose activation they were created (or null if the with or block object |
329 |
* outlives the frame). |
330 |
*/ |
331 |
#define JSSLOT_BLOCK_DEPTH (JSSLOT_PRIVATE + 1) |
332 |
|
333 |
#define OBJ_IS_CLONED_BLOCK(obj) \ |
334 |
(OBJ_SCOPE(obj)->object != (obj)) |
335 |
#define OBJ_BLOCK_COUNT(cx,obj) \ |
336 |
(OBJ_SCOPE(obj)->entryCount) |
337 |
#define OBJ_BLOCK_DEPTH(cx,obj) \ |
338 |
JSVAL_TO_INT(STOBJ_GET_SLOT(obj, JSSLOT_BLOCK_DEPTH)) |
339 |
#define OBJ_SET_BLOCK_DEPTH(cx,obj,depth) \ |
340 |
STOBJ_SET_SLOT(obj, JSSLOT_BLOCK_DEPTH, INT_TO_JSVAL(depth)) |
341 |
|
342 |
/* |
343 |
* To make sure this slot is well-defined, always call js_NewWithObject to |
344 |
* create a With object, don't call js_NewObject directly. When creating a |
345 |
* With object that does not correspond to a stack slot, pass -1 for depth. |
346 |
* |
347 |
* When popping the stack across this object's "with" statement, client code |
348 |
* must call JS_SetPrivate(cx, withobj, NULL). |
349 |
*/ |
350 |
extern JSObject * |
351 |
js_NewWithObject(JSContext *cx, JSObject *proto, JSObject *parent, jsint depth); |
352 |
|
353 |
/* |
354 |
* Create a new block scope object not linked to any proto or parent object. |
355 |
* Blocks are created by the compiler to reify let blocks and comprehensions. |
356 |
* Only when dynamic scope is captured do they need to be cloned and spliced |
357 |
* into an active scope chain. |
358 |
*/ |
359 |
extern JSObject * |
360 |
js_NewBlockObject(JSContext *cx); |
361 |
|
362 |
extern JSObject * |
363 |
js_CloneBlockObject(JSContext *cx, JSObject *proto, JSObject *parent, |
364 |
JSStackFrame *fp); |
365 |
|
366 |
extern JSBool |
367 |
js_PutBlockObject(JSContext *cx, JSBool normalUnwind); |
368 |
|
369 |
struct JSSharpObjectMap { |
370 |
jsrefcount depth; |
371 |
jsatomid sharpgen; |
372 |
JSHashTable *table; |
373 |
}; |
374 |
|
375 |
#define SHARP_BIT ((jsatomid) 1) |
376 |
#define BUSY_BIT ((jsatomid) 2) |
377 |
#define SHARP_ID_SHIFT 2 |
378 |
#define IS_SHARP(he) (JS_PTR_TO_UINT32((he)->value) & SHARP_BIT) |
379 |
#define MAKE_SHARP(he) ((he)->value = JS_UINT32_TO_PTR(JS_PTR_TO_UINT32((he)->value)|SHARP_BIT)) |
380 |
#define IS_BUSY(he) (JS_PTR_TO_UINT32((he)->value) & BUSY_BIT) |
381 |
#define MAKE_BUSY(he) ((he)->value = JS_UINT32_TO_PTR(JS_PTR_TO_UINT32((he)->value)|BUSY_BIT)) |
382 |
#define CLEAR_BUSY(he) ((he)->value = JS_UINT32_TO_PTR(JS_PTR_TO_UINT32((he)->value)&~BUSY_BIT)) |
383 |
|
384 |
extern JSHashEntry * |
385 |
js_EnterSharpObject(JSContext *cx, JSObject *obj, JSIdArray **idap, |
386 |
jschar **sp); |
387 |
|
388 |
extern void |
389 |
js_LeaveSharpObject(JSContext *cx, JSIdArray **idap); |
390 |
|
391 |
/* |
392 |
* Mark objects stored in map if GC happens between js_EnterSharpObject |
393 |
* and js_LeaveSharpObject. GC calls this when map->depth > 0. |
394 |
*/ |
395 |
extern void |
396 |
js_TraceSharpMap(JSTracer *trc, JSSharpObjectMap *map); |
397 |
|
398 |
extern JSBool |
399 |
js_obj_hasOwnProperty(JSContext *cx, uintN argc, jsval *vp); |
400 |
|
401 |
extern JSBool |
402 |
js_HasOwnPropertyHelper(JSContext *cx, JSLookupPropOp lookup, uintN argc, |
403 |
jsval *vp); |
404 |
|
405 |
extern JSBool |
406 |
js_HasOwnProperty(JSContext *cx, JSLookupPropOp lookup, JSObject *obj, jsid id, |
407 |
jsval *vp); |
408 |
|
409 |
extern JSBool |
410 |
js_obj_propertyIsEnumerable(JSContext *cx, uintN argc, jsval *vp); |
411 |
|
412 |
extern JSBool |
413 |
js_PropertyIsEnumerable(JSContext *cx, JSObject *obj, jsid id, jsval *vp); |
414 |
|
415 |
extern JSObject * |
416 |
js_InitBlockClass(JSContext *cx, JSObject* obj); |
417 |
|
418 |
extern JSObject * |
419 |
js_InitEval(JSContext *cx, JSObject *obj); |
420 |
|
421 |
extern JSObject * |
422 |
js_InitObjectClass(JSContext *cx, JSObject *obj); |
423 |
|
424 |
/* Select Object.prototype method names shared between jsapi.c and jsobj.c. */ |
425 |
extern const char js_watch_str[]; |
426 |
extern const char js_unwatch_str[]; |
427 |
extern const char js_hasOwnProperty_str[]; |
428 |
extern const char js_isPrototypeOf_str[]; |
429 |
extern const char js_propertyIsEnumerable_str[]; |
430 |
extern const char js_defineGetter_str[]; |
431 |
extern const char js_defineSetter_str[]; |
432 |
extern const char js_lookupGetter_str[]; |
433 |
extern const char js_lookupSetter_str[]; |
434 |
|
435 |
extern void |
436 |
js_InitObjectMap(JSObjectMap *map, jsrefcount nrefs, JSObjectOps *ops, |
437 |
JSClass *clasp); |
438 |
|
439 |
extern JSObjectMap * |
440 |
js_NewObjectMap(JSContext *cx, jsrefcount nrefs, JSObjectOps *ops, |
441 |
JSClass *clasp, JSObject *obj); |
442 |
|
443 |
extern void |
444 |
js_DestroyObjectMap(JSContext *cx, JSObjectMap *map); |
445 |
|
446 |
extern JSObjectMap * |
447 |
js_HoldObjectMap(JSContext *cx, JSObjectMap *map); |
448 |
|
449 |
extern JSObjectMap * |
450 |
js_DropObjectMap(JSContext *cx, JSObjectMap *map, JSObject *obj); |
451 |
|
452 |
extern JSBool |
453 |
js_GetClassId(JSContext *cx, JSClass *clasp, jsid *idp); |
454 |
|
455 |
extern JSObject * |
456 |
js_NewObject(JSContext *cx, JSClass *clasp, JSObject *proto, JSObject *parent, |
457 |
uintN objectSize); |
458 |
|
459 |
/* |
460 |
* See jsapi.h, JS_NewObjectWithGivenProto. |
461 |
* |
462 |
* objectSize is either the explicit size for the allocated object or 0 |
463 |
* indicating to use the default size based on object's class. |
464 |
*/ |
465 |
extern JSObject * |
466 |
js_NewObjectWithGivenProto(JSContext *cx, JSClass *clasp, JSObject *proto, |
467 |
JSObject *parent, uintN objectSize); |
468 |
|
469 |
/* |
470 |
* Fast access to immutable standard objects (constructors and prototypes). |
471 |
*/ |
472 |
extern JSBool |
473 |
js_GetClassObject(JSContext *cx, JSObject *obj, JSProtoKey key, |
474 |
JSObject **objp); |
475 |
|
476 |
extern JSBool |
477 |
js_SetClassObject(JSContext *cx, JSObject *obj, JSProtoKey key, JSObject *cobj); |
478 |
|
479 |
extern JSBool |
480 |
js_FindClassObject(JSContext *cx, JSObject *start, jsid id, jsval *vp); |
481 |
|
482 |
extern JSObject * |
483 |
js_ConstructObject(JSContext *cx, JSClass *clasp, JSObject *proto, |
484 |
JSObject *parent, uintN argc, jsval *argv); |
485 |
|
486 |
extern void |
487 |
js_FinalizeObject(JSContext *cx, JSObject *obj); |
488 |
|
489 |
extern JSBool |
490 |
js_AllocSlot(JSContext *cx, JSObject *obj, uint32 *slotp); |
491 |
|
492 |
extern void |
493 |
js_FreeSlot(JSContext *cx, JSObject *obj, uint32 slot); |
494 |
|
495 |
/* JSVAL_INT_MAX as a string */ |
496 |
#define JSVAL_INT_MAX_STRING "1073741823" |
497 |
|
498 |
#define CHECK_FOR_STRING_INDEX(id) \ |
499 |
JS_BEGIN_MACRO \ |
500 |
if (JSID_IS_ATOM(id)) { \ |
501 |
JSAtom *atom_ = JSID_TO_ATOM(id); \ |
502 |
JSString *str_ = ATOM_TO_STRING(atom_); \ |
503 |
const jschar *s_ = JSFLATSTR_CHARS(str_); \ |
504 |
JSBool negative_ = (*s_ == '-'); \ |
505 |
if (negative_) s_++; \ |
506 |
if (JS7_ISDEC(*s_)) { \ |
507 |
size_t n_ = JSFLATSTR_LENGTH(str_) - negative_; \ |
508 |
if (n_ <= sizeof(JSVAL_INT_MAX_STRING) - 1) \ |
509 |
id = js_CheckForStringIndex(id, s_, s_ + n_, negative_); \ |
510 |
} \ |
511 |
} \ |
512 |
JS_END_MACRO |
513 |
|
514 |
extern jsid |
515 |
js_CheckForStringIndex(jsid id, const jschar *cp, const jschar *end, |
516 |
JSBool negative); |
517 |
|
518 |
/* |
519 |
* Find or create a property named by id in obj's scope, with the given getter |
520 |
* and setter, slot, attributes, and other members. |
521 |
*/ |
522 |
extern JSScopeProperty * |
523 |
js_AddNativeProperty(JSContext *cx, JSObject *obj, jsid id, |
524 |
JSPropertyOp getter, JSPropertyOp setter, uint32 slot, |
525 |
uintN attrs, uintN flags, intN shortid); |
526 |
|
527 |
/* |
528 |
* Change sprop to have the given attrs, getter, and setter in scope, morphing |
529 |
* it into a potentially new JSScopeProperty. Return a pointer to the changed |
530 |
* or identical property. |
531 |
*/ |
532 |
extern JSScopeProperty * |
533 |
js_ChangeNativePropertyAttrs(JSContext *cx, JSObject *obj, |
534 |
JSScopeProperty *sprop, uintN attrs, uintN mask, |
535 |
JSPropertyOp getter, JSPropertyOp setter); |
536 |
|
537 |
/* |
538 |
* On error, return false. On success, if propp is non-null, return true with |
539 |
* obj locked and with a held property in *propp; if propp is null, return true |
540 |
* but release obj's lock first. Therefore all callers who pass non-null propp |
541 |
* result parameters must later call OBJ_DROP_PROPERTY(cx, obj, *propp) both to |
542 |
* drop the held property, and to release the lock on obj. |
543 |
*/ |
544 |
extern JSBool |
545 |
js_DefineProperty(JSContext *cx, JSObject *obj, jsid id, jsval value, |
546 |
JSPropertyOp getter, JSPropertyOp setter, uintN attrs, |
547 |
JSProperty **propp); |
548 |
|
549 |
extern JSBool |
550 |
js_DefineNativeProperty(JSContext *cx, JSObject *obj, jsid id, jsval value, |
551 |
JSPropertyOp getter, JSPropertyOp setter, uintN attrs, |
552 |
uintN flags, intN shortid, JSProperty **propp); |
553 |
|
554 |
/* |
555 |
* Unlike js_DefineProperty, propp must be non-null. On success, and if id was |
556 |
* found, return true with *objp non-null and locked, and with a held property |
557 |
* stored in *propp. If successful but id was not found, return true with both |
558 |
* *objp and *propp null. Therefore all callers who receive a non-null *propp |
559 |
* must later call OBJ_DROP_PROPERTY(cx, *objp, *propp). |
560 |
*/ |
561 |
extern JS_FRIEND_API(JSBool) |
562 |
js_LookupProperty(JSContext *cx, JSObject *obj, jsid id, JSObject **objp, |
563 |
JSProperty **propp); |
564 |
|
565 |
/* |
566 |
* Specialized subroutine that allows caller to preset JSRESOLVE_* flags and |
567 |
* returns the index along the prototype chain in which *propp was found, or |
568 |
* the last index if not found, or -1 on error. |
569 |
*/ |
570 |
extern int |
571 |
js_LookupPropertyWithFlags(JSContext *cx, JSObject *obj, jsid id, uintN flags, |
572 |
JSObject **objp, JSProperty **propp); |
573 |
|
574 |
extern int |
575 |
js_FindPropertyHelper(JSContext *cx, jsid id, JSObject **objp, |
576 |
JSObject **pobjp, JSProperty **propp, |
577 |
JSPropCacheEntry **entryp); |
578 |
|
579 |
/* |
580 |
* Return the index along the scope chain in which id was found, or the last |
581 |
* index if not found, or -1 on error. |
582 |
*/ |
583 |
extern JS_FRIEND_API(JSBool) |
584 |
js_FindProperty(JSContext *cx, jsid id, JSObject **objp, JSObject **pobjp, |
585 |
JSProperty **propp); |
586 |
|
587 |
extern JSObject * |
588 |
js_FindIdentifierBase(JSContext *cx, jsid id, JSPropCacheEntry *entry); |
589 |
|
590 |
extern JSObject * |
591 |
js_FindVariableScope(JSContext *cx, JSFunction **funp); |
592 |
|
593 |
/* |
594 |
* NB: js_NativeGet and js_NativeSet are called with the scope containing sprop |
595 |
* (pobj's scope for Get, obj's for Set) locked, and on successful return, that |
596 |
* scope is again locked. But on failure, both functions return false with the |
597 |
* scope containing sprop unlocked. |
598 |
*/ |
599 |
extern JSBool |
600 |
js_NativeGet(JSContext *cx, JSObject *obj, JSObject *pobj, |
601 |
JSScopeProperty *sprop, jsval *vp); |
602 |
|
603 |
extern JSBool |
604 |
js_NativeSet(JSContext *cx, JSObject *obj, JSScopeProperty *sprop, jsval *vp); |
605 |
|
606 |
extern JSBool |
607 |
js_GetPropertyHelper(JSContext *cx, JSObject *obj, jsid id, jsval *vp, |
608 |
JSPropCacheEntry **entryp); |
609 |
|
610 |
extern JSBool |
611 |
js_GetProperty(JSContext *cx, JSObject *obj, jsid id, jsval *vp); |
612 |
|
613 |
extern JSBool |
614 |
js_SetPropertyHelper(JSContext *cx, JSObject *obj, jsid id, jsval *vp, |
615 |
JSPropCacheEntry **entryp); |
616 |
|
617 |
extern JSBool |
618 |
js_SetProperty(JSContext *cx, JSObject *obj, jsid id, jsval *vp); |
619 |
|
620 |
extern JSBool |
621 |
js_GetAttributes(JSContext *cx, JSObject *obj, jsid id, JSProperty *prop, |
622 |
uintN *attrsp); |
623 |
|
624 |
extern JSBool |
625 |
js_SetAttributes(JSContext *cx, JSObject *obj, jsid id, JSProperty *prop, |
626 |
uintN *attrsp); |
627 |
|
628 |
extern JSBool |
629 |
js_DeleteProperty(JSContext *cx, JSObject *obj, jsid id, jsval *rval); |
630 |
|
631 |
extern JSBool |
632 |
js_DefaultValue(JSContext *cx, JSObject *obj, JSType hint, jsval *vp); |
633 |
|
634 |
extern JSBool |
635 |
js_Enumerate(JSContext *cx, JSObject *obj, JSIterateOp enum_op, |
636 |
jsval *statep, jsid *idp); |
637 |
|
638 |
extern void |
639 |
js_TraceNativeEnumerators(JSTracer *trc); |
640 |
|
641 |
extern JSBool |
642 |
js_CheckAccess(JSContext *cx, JSObject *obj, jsid id, JSAccessMode mode, |
643 |
jsval *vp, uintN *attrsp); |
644 |
|
645 |
extern JSBool |
646 |
js_Call(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval); |
647 |
|
648 |
extern JSBool |
649 |
js_Construct(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, |
650 |
jsval *rval); |
651 |
|
652 |
extern JSBool |
653 |
js_HasInstance(JSContext *cx, JSObject *obj, jsval v, JSBool *bp); |
654 |
|
655 |
extern JSBool |
656 |
js_SetProtoOrParent(JSContext *cx, JSObject *obj, uint32 slot, JSObject *pobj); |
657 |
|
658 |
extern JSBool |
659 |
js_IsDelegate(JSContext *cx, JSObject *obj, jsval v, JSBool *bp); |
660 |
|
661 |
extern JSBool |
662 |
js_GetClassPrototype(JSContext *cx, JSObject *scope, jsid id, |
663 |
JSObject **protop); |
664 |
|
665 |
extern JSBool |
666 |
js_SetClassPrototype(JSContext *cx, JSObject *ctor, JSObject *proto, |
667 |
uintN attrs); |
668 |
|
669 |
/* |
670 |
* Wrap boolean, number or string as Boolean, Number or String object. |
671 |
* *vp must not be an object, null or undefined. |
672 |
*/ |
673 |
extern JSBool |
674 |
js_PrimitiveToObject(JSContext *cx, jsval *vp); |
675 |
|
676 |
extern JSBool |
677 |
js_ValueToObject(JSContext *cx, jsval v, JSObject **objp); |
678 |
|
679 |
extern JSObject * |
680 |
js_ValueToNonNullObject(JSContext *cx, jsval v); |
681 |
|
682 |
extern JSBool |
683 |
js_TryValueOf(JSContext *cx, JSObject *obj, JSType type, jsval *rval); |
684 |
|
685 |
extern JSBool |
686 |
js_TryMethod(JSContext *cx, JSObject *obj, JSAtom *atom, |
687 |
uintN argc, jsval *argv, jsval *rval); |
688 |
|
689 |
extern JSBool |
690 |
js_XDRObject(JSXDRState *xdr, JSObject **objp); |
691 |
|
692 |
extern void |
693 |
js_TraceObject(JSTracer *trc, JSObject *obj); |
694 |
|
695 |
extern void |
696 |
js_PrintObjectSlotName(JSTracer *trc, char *buf, size_t bufsize); |
697 |
|
698 |
extern void |
699 |
js_Clear(JSContext *cx, JSObject *obj); |
700 |
|
701 |
extern jsval |
702 |
js_GetRequiredSlot(JSContext *cx, JSObject *obj, uint32 slot); |
703 |
|
704 |
extern JSBool |
705 |
js_SetRequiredSlot(JSContext *cx, JSObject *obj, uint32 slot, jsval v); |
706 |
|
707 |
/* |
708 |
* Precondition: obj must be locked. |
709 |
*/ |
710 |
extern JSBool |
711 |
js_ReallocSlots(JSContext *cx, JSObject *obj, uint32 nslots, |
712 |
JSBool exactAllocation); |
713 |
|
714 |
extern JSObject * |
715 |
js_CheckScopeChainValidity(JSContext *cx, JSObject *scopeobj, const char *caller); |
716 |
|
717 |
extern JSBool |
718 |
js_CheckPrincipalsAccess(JSContext *cx, JSObject *scopeobj, |
719 |
JSPrincipals *principals, JSAtom *caller); |
720 |
|
721 |
/* Infallible -- returns its argument if there is no wrapped object. */ |
722 |
extern JSObject * |
723 |
js_GetWrappedObject(JSContext *cx, JSObject *obj); |
724 |
|
725 |
/* NB: Infallible. */ |
726 |
extern const char * |
727 |
js_ComputeFilename(JSContext *cx, JSStackFrame *caller, |
728 |
JSPrincipals *principals, uintN *linenop); |
729 |
|
730 |
extern JSBool |
731 |
js_obj_eval(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval); |
732 |
|
733 |
#ifdef DEBUG |
734 |
JS_FRIEND_API(void) js_DumpChars(const jschar *s, size_t n); |
735 |
JS_FRIEND_API(void) js_DumpString(JSString *str); |
736 |
JS_FRIEND_API(void) js_DumpAtom(JSAtom *atom); |
737 |
JS_FRIEND_API(void) js_DumpValue(jsval val); |
738 |
JS_FRIEND_API(void) js_DumpId(jsid id); |
739 |
JS_FRIEND_API(void) js_DumpObject(JSObject *obj); |
740 |
#endif |
741 |
|
742 |
JS_END_EXTERN_C |
743 |
|
744 |
#endif /* jsobj_h___ */ |