56 |
#include "jsarray.h" |
#include "jsarray.h" |
57 |
#include "jsatom.h" |
#include "jsatom.h" |
58 |
#include "jsbool.h" |
#include "jsbool.h" |
59 |
|
#include "jsbuiltins.h" |
60 |
#include "jscntxt.h" |
#include "jscntxt.h" |
61 |
#include "jsversion.h" |
#include "jsversion.h" |
62 |
#include "jsdate.h" |
#include "jsdate.h" |
550 |
return js_ValueToString(cx, v); |
return js_ValueToString(cx, v); |
551 |
} |
} |
552 |
|
|
553 |
|
JS_PUBLIC_API(JSString *) |
554 |
|
JS_ValueToSource(JSContext *cx, jsval v) |
555 |
|
{ |
556 |
|
CHECK_REQUEST(cx); |
557 |
|
return js_ValueToSource(cx, v); |
558 |
|
} |
559 |
|
|
560 |
JS_PUBLIC_API(JSBool) |
JS_PUBLIC_API(JSBool) |
561 |
JS_ValueToNumber(JSContext *cx, jsval v, jsdouble *dp) |
JS_ValueToNumber(JSContext *cx, jsval v, jsdouble *dp) |
562 |
{ |
{ |
670 |
|
|
671 |
if (!OBJ_GET_PROPERTY(cx, obj, |
if (!OBJ_GET_PROPERTY(cx, obj, |
672 |
ATOM_TO_JSID(cx->runtime->atomState |
ATOM_TO_JSID(cx->runtime->atomState |
673 |
.callAtom), |
.__call__Atom), |
674 |
&v)) { |
&v)) { |
675 |
JS_ClearPendingException(cx); |
JS_ClearPendingException(cx); |
676 |
} else if (VALUE_IS_FUNCTION(cx, v)) { |
} else if (VALUE_IS_FUNCTION(cx, v)) { |
2792 |
* we know to create an object of this class when we call the |
* we know to create an object of this class when we call the |
2793 |
* constructor. |
* constructor. |
2794 |
*/ |
*/ |
2795 |
fun->u.n.clasp = clasp; |
FUN_CLASP(fun) = clasp; |
2796 |
|
|
2797 |
/* |
/* |
2798 |
* Optionally construct the prototype object, before the class has |
* Optionally construct the prototype object, before the class has |
3120 |
} |
} |
3121 |
|
|
3122 |
static JSBool |
static JSBool |
3123 |
|
DefinePropertyById(JSContext *cx, JSObject *obj, jsid id, jsval value, |
3124 |
|
JSPropertyOp getter, JSPropertyOp setter, uintN attrs, |
3125 |
|
uintN flags, intN tinyid) |
3126 |
|
{ |
3127 |
|
if (flags != 0 && OBJ_IS_NATIVE(obj)) { |
3128 |
|
JSAutoResolveFlags rf(cx, JSRESOLVE_QUALIFIED | JSRESOLVE_DECLARING); |
3129 |
|
return js_DefineNativeProperty(cx, obj, id, value, getter, setter, |
3130 |
|
attrs, flags, tinyid, NULL); |
3131 |
|
} |
3132 |
|
return OBJ_DEFINE_PROPERTY(cx, obj, id, value, getter, setter, attrs, |
3133 |
|
NULL); |
3134 |
|
} |
3135 |
|
|
3136 |
|
static JSBool |
3137 |
DefineProperty(JSContext *cx, JSObject *obj, const char *name, jsval value, |
DefineProperty(JSContext *cx, JSObject *obj, const char *name, jsval value, |
3138 |
JSPropertyOp getter, JSPropertyOp setter, uintN attrs, |
JSPropertyOp getter, JSPropertyOp setter, uintN attrs, |
3139 |
uintN flags, intN tinyid) |
uintN flags, intN tinyid) |
3151 |
return JS_FALSE; |
return JS_FALSE; |
3152 |
id = ATOM_TO_JSID(atom); |
id = ATOM_TO_JSID(atom); |
3153 |
} |
} |
3154 |
if (flags != 0 && OBJ_IS_NATIVE(obj)) { |
return DefinePropertyById(cx, obj, id, value, getter, setter, attrs, |
3155 |
JSAutoResolveFlags rf(cx, JSRESOLVE_QUALIFIED | JSRESOLVE_DECLARING); |
flags, tinyid); |
|
return js_DefineNativeProperty(cx, obj, id, value, getter, setter, |
|
|
attrs, flags, tinyid, NULL); |
|
|
} |
|
|
return OBJ_DEFINE_PROPERTY(cx, obj, id, value, getter, setter, attrs, |
|
|
NULL); |
|
3156 |
} |
} |
3157 |
|
|
3158 |
#define AUTO_NAMELEN(s,n) (((n) == (size_t)-1) ? js_strlen(s) : (n)) |
#define AUTO_NAMELEN(s,n) (((n) == (size_t)-1) ? js_strlen(s) : (n)) |
3245 |
} |
} |
3246 |
|
|
3247 |
JS_PUBLIC_API(JSBool) |
JS_PUBLIC_API(JSBool) |
3248 |
|
JS_DefinePropertyById(JSContext *cx, JSObject *obj, jsid id, jsval value, |
3249 |
|
JSPropertyOp getter, JSPropertyOp setter, uintN attrs) |
3250 |
|
{ |
3251 |
|
CHECK_REQUEST(cx); |
3252 |
|
return DefinePropertyById(cx, obj, id, value, getter, setter, attrs, 0, 0); |
3253 |
|
} |
3254 |
|
|
3255 |
|
JS_PUBLIC_API(JSBool) |
3256 |
JS_DefinePropertyWithTinyId(JSContext *cx, JSObject *obj, const char *name, |
JS_DefinePropertyWithTinyId(JSContext *cx, JSObject *obj, const char *name, |
3257 |
int8 tinyid, jsval value, |
int8 tinyid, jsval value, |
3258 |
JSPropertyOp getter, JSPropertyOp setter, |
JSPropertyOp getter, JSPropertyOp setter, |
3502 |
} |
} |
3503 |
|
|
3504 |
JS_PUBLIC_API(JSBool) |
JS_PUBLIC_API(JSBool) |
3505 |
|
JS_AlreadyHasOwnPropertyById(JSContext *cx, JSObject *obj, jsid id, |
3506 |
|
JSBool *foundp) |
3507 |
|
{ |
3508 |
|
CHECK_REQUEST(cx); |
3509 |
|
return AlreadyHasOwnPropertyHelper(cx, obj, id, foundp); |
3510 |
|
} |
3511 |
|
|
3512 |
|
JS_PUBLIC_API(JSBool) |
3513 |
JS_HasProperty(JSContext *cx, JSObject *obj, const char *name, JSBool *foundp) |
JS_HasProperty(JSContext *cx, JSObject *obj, const char *name, JSBool *foundp) |
3514 |
{ |
{ |
3515 |
JSBool ok; |
JSBool ok; |
3529 |
} |
} |
3530 |
|
|
3531 |
JS_PUBLIC_API(JSBool) |
JS_PUBLIC_API(JSBool) |
3532 |
|
JS_HasPropertyById(JSContext *cx, JSObject *obj, jsid id, JSBool *foundp) |
3533 |
|
{ |
3534 |
|
JSBool ok; |
3535 |
|
JSObject *obj2; |
3536 |
|
JSProperty *prop; |
3537 |
|
|
3538 |
|
CHECK_REQUEST(cx); |
3539 |
|
ok = LookupPropertyById(cx, obj, id, |
3540 |
|
JSRESOLVE_QUALIFIED | JSRESOLVE_DETECTING, |
3541 |
|
&obj2, &prop); |
3542 |
|
if (ok) { |
3543 |
|
*foundp = (prop != NULL); |
3544 |
|
if (prop) |
3545 |
|
OBJ_DROP_PROPERTY(cx, obj2, prop); |
3546 |
|
} |
3547 |
|
return ok; |
3548 |
|
} |
3549 |
|
|
3550 |
|
JS_PUBLIC_API(JSBool) |
3551 |
JS_LookupProperty(JSContext *cx, JSObject *obj, const char *name, jsval *vp) |
JS_LookupProperty(JSContext *cx, JSObject *obj, const char *name, jsval *vp) |
3552 |
{ |
{ |
3553 |
JSBool ok; |
JSBool ok; |
3562 |
} |
} |
3563 |
|
|
3564 |
JS_PUBLIC_API(JSBool) |
JS_PUBLIC_API(JSBool) |
3565 |
|
JS_LookupPropertyById(JSContext *cx, JSObject *obj, jsid id, jsval *vp) |
3566 |
|
{ |
3567 |
|
JSBool ok; |
3568 |
|
JSObject *obj2; |
3569 |
|
JSProperty *prop; |
3570 |
|
|
3571 |
|
CHECK_REQUEST(cx); |
3572 |
|
ok = LookupPropertyById(cx, obj, id, JSRESOLVE_QUALIFIED, &obj2, &prop); |
3573 |
|
if (ok) |
3574 |
|
*vp = LookupResult(cx, obj, obj2, prop); |
3575 |
|
return ok; |
3576 |
|
} |
3577 |
|
|
3578 |
|
JS_PUBLIC_API(JSBool) |
3579 |
JS_LookupPropertyWithFlags(JSContext *cx, JSObject *obj, const char *name, |
JS_LookupPropertyWithFlags(JSContext *cx, JSObject *obj, const char *name, |
3580 |
uintN flags, jsval *vp) |
uintN flags, jsval *vp) |
3581 |
{ |
{ |
3584 |
|
|
3585 |
atom = js_Atomize(cx, name, strlen(name), 0); |
atom = js_Atomize(cx, name, strlen(name), 0); |
3586 |
return atom && |
return atom && |
3587 |
JS_LookupPropertyByIdWithFlags(cx, obj, ATOM_TO_JSID(atom), flags, |
JS_LookupPropertyWithFlagsById(cx, obj, ATOM_TO_JSID(atom), flags, |
3588 |
&obj2, vp); |
&obj2, vp); |
3589 |
} |
} |
3590 |
|
|
3591 |
JS_PUBLIC_API(JSBool) |
JS_PUBLIC_API(JSBool) |
3592 |
JS_LookupPropertyByIdWithFlags(JSContext *cx, JSObject *obj, jsid id, |
JS_LookupPropertyWithFlagsById(JSContext *cx, JSObject *obj, jsid id, |
3593 |
uintN flags, JSObject **objp, jsval *vp) |
uintN flags, JSObject **objp, jsval *vp) |
3594 |
{ |
{ |
3595 |
JSBool ok; |
JSBool ok; |
3619 |
} |
} |
3620 |
|
|
3621 |
JS_PUBLIC_API(JSBool) |
JS_PUBLIC_API(JSBool) |
3622 |
|
JS_GetPropertyById(JSContext *cx, JSObject *obj, jsid id, jsval *vp) |
3623 |
|
{ |
3624 |
|
CHECK_REQUEST(cx); |
3625 |
|
JSAutoResolveFlags rf(cx, JSRESOLVE_QUALIFIED); |
3626 |
|
return OBJ_GET_PROPERTY(cx, obj, id, vp); |
3627 |
|
} |
3628 |
|
|
3629 |
|
JS_PUBLIC_API(JSBool) |
3630 |
JS_GetMethodById(JSContext *cx, JSObject *obj, jsid id, JSObject **objp, |
JS_GetMethodById(JSContext *cx, JSObject *obj, jsid id, JSObject **objp, |
3631 |
jsval *vp) |
jsval *vp) |
3632 |
{ |
{ |
3679 |
} |
} |
3680 |
|
|
3681 |
JS_PUBLIC_API(JSBool) |
JS_PUBLIC_API(JSBool) |
3682 |
|
JS_SetPropertyById(JSContext *cx, JSObject *obj, jsid id, jsval *vp) |
3683 |
|
{ |
3684 |
|
CHECK_REQUEST(cx); |
3685 |
|
JSAutoResolveFlags rf(cx, JSRESOLVE_QUALIFIED | JSRESOLVE_ASSIGNING); |
3686 |
|
return OBJ_SET_PROPERTY(cx, obj, id, vp); |
3687 |
|
} |
3688 |
|
|
3689 |
|
JS_PUBLIC_API(JSBool) |
3690 |
JS_DeleteProperty(JSContext *cx, JSObject *obj, const char *name) |
JS_DeleteProperty(JSContext *cx, JSObject *obj, const char *name) |
3691 |
{ |
{ |
3692 |
jsval junk; |
jsval junk; |
3693 |
|
|
|
CHECK_REQUEST(cx); |
|
3694 |
return JS_DeleteProperty2(cx, obj, name, &junk); |
return JS_DeleteProperty2(cx, obj, name, &junk); |
3695 |
} |
} |
3696 |
|
|
3710 |
} |
} |
3711 |
|
|
3712 |
JS_PUBLIC_API(JSBool) |
JS_PUBLIC_API(JSBool) |
3713 |
|
JS_DeletePropertyById(JSContext *cx, JSObject *obj, jsid id) |
3714 |
|
{ |
3715 |
|
jsval junk; |
3716 |
|
|
3717 |
|
return JS_DeletePropertyById2(cx, obj, id, &junk); |
3718 |
|
} |
3719 |
|
|
3720 |
|
JS_PUBLIC_API(JSBool) |
3721 |
|
JS_DeletePropertyById2(JSContext *cx, JSObject *obj, jsid id, jsval *rval) |
3722 |
|
{ |
3723 |
|
CHECK_REQUEST(cx); |
3724 |
|
JSAutoResolveFlags rf(cx, JSRESOLVE_QUALIFIED); |
3725 |
|
return OBJ_DELETE_PROPERTY(cx, obj, id, rval); |
3726 |
|
} |
3727 |
|
|
3728 |
|
JS_PUBLIC_API(JSBool) |
3729 |
JS_DefineUCProperty(JSContext *cx, JSObject *obj, |
JS_DefineUCProperty(JSContext *cx, JSObject *obj, |
3730 |
const jschar *name, size_t namelen, jsval value, |
const jschar *name, size_t namelen, jsval value, |
3731 |
JSPropertyOp getter, JSPropertyOp setter, |
JSPropertyOp getter, JSPropertyOp setter, |
4477 |
jsval fsv; |
jsval fsv; |
4478 |
JSFunctionSpec *fs; |
JSFunctionSpec *fs; |
4479 |
JSObject *tmp; |
JSObject *tmp; |
4480 |
|
JSFastNative native; |
4481 |
|
|
4482 |
if (!JS_GetReservedSlot(cx, JSVAL_TO_OBJECT(*vp), 0, &fsv)) |
if (!JS_GetReservedSlot(cx, JSVAL_TO_OBJECT(*vp), 0, &fsv)) |
4483 |
return JS_FALSE; |
return JS_FALSE; |
4522 |
if (argc != 0) |
if (argc != 0) |
4523 |
--argc; |
--argc; |
4524 |
|
|
4525 |
return ((JSFastNative) fs->call)(cx, argc, vp); |
native = |
4526 |
|
#ifdef JS_TRACER |
4527 |
|
(fs->flags & JSFUN_TRACEABLE) |
4528 |
|
? ((JSTraceableNative *) fs->call)->native |
4529 |
|
: |
4530 |
|
#endif |
4531 |
|
(JSFastNative) fs->call; |
4532 |
|
return native(cx, argc, vp); |
4533 |
} |
} |
4534 |
|
|
4535 |
static JSBool |
static JSBool |
4620 |
? (JSNative) |
? (JSNative) |
4621 |
js_generic_fast_native_method_dispatcher |
js_generic_fast_native_method_dispatcher |
4622 |
: js_generic_native_method_dispatcher, |
: js_generic_native_method_dispatcher, |
4623 |
fs->nargs + 1, flags); |
fs->nargs + 1, |
4624 |
|
flags & ~JSFUN_TRACEABLE); |
4625 |
if (!fun) |
if (!fun) |
4626 |
return JS_FALSE; |
return JS_FALSE; |
4627 |
fun->u.n.extra = (uint16)fs->extra; |
fun->u.n.extra = (uint16)fs->extra; |
5633 |
} |
} |
5634 |
|
|
5635 |
JS_PUBLIC_API(JSBool) |
JS_PUBLIC_API(JSBool) |
5636 |
JS_Stringify(JSContext *cx, jsval *vp, JSObject *replacer, |
JS_Stringify(JSContext *cx, jsval *vp, JSObject *replacer, |
5637 |
JSONWriteCallback callback, void *data) |
JSONWriteCallback callback, void *data) |
5638 |
{ |
{ |
5639 |
CHECK_REQUEST(cx); |
CHECK_REQUEST(cx); |