MOZILLA_1_8_BRAN CH API compatibility restoration.

git-svn-id: svn://10.0.0.236/trunk@201687 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
brendan%mozilla.org 2006-07-06 18:40:03 +00:00
parent 1501a8135a
commit f4df6e1ae7
9 changed files with 107 additions and 22 deletions

View File

@ -3623,7 +3623,17 @@ JS_GetFunctionId(JSFunction *fun)
JS_PUBLIC_API(uintN)
JS_GetFunctionFlags(JSFunction *fun)
{
#ifdef MOZILLA_1_8_BRANCH
uintN flags = fun->flags;
return JSFUN_DISJOINT_FLAGS(flags) |
(JSFUN_GETTER_TEST(flags) ? JSFUN_GETTER : 0) |
(JSFUN_SETTER_TEST(flags) ? JSFUN_SETTER : 0) |
(JSFUN_BOUND_METHOD_TEST(flags) ? JSFUN_BOUND_METHOD : 0) |
(JSFUN_HEAVYWEIGHT_TEST(flags) ? JSFUN_HEAVYWEIGHT : 0);
#else
return fun->flags;
#endif
}
JS_PUBLIC_API(uint16)

View File

@ -132,14 +132,59 @@ JS_BEGIN_EXTERN_C
#define JSFUN_SETTER JSPROP_SETTER
#define JSFUN_BOUND_METHOD 0x40 /* bind this to fun->object's parent */
#define JSFUN_HEAVYWEIGHT 0x80 /* activation requires a Call object */
#define JSFUN_DISJOINT_FLAGS(f) ((f) & 0x0f)
#define JSFUN_GSFLAGS(f) ((f) & (JSFUN_GETTER | JSFUN_SETTER))
#ifdef MOZILLA_1_8_BRANCH
/*
* Squeeze three more bits into existing 8-bit flags by taking advantage of
* the invalid combination (JSFUN_GETTER | JSFUN_SETTER).
*/
#define JSFUN_GETTER_TEST(f) (JSFUN_GSFLAGS(f) == JSFUN_GETTER)
#define JSFUN_SETTER_TEST(f) (JSFUN_GSFLAGS(f) == JSFUN_SETTER)
#define JSFUN_FLAGS_TEST(f,t) (JSFUN_GSFLAGS(~(f)) ? 0 : (f) & (t))
#define JSFUN_BOUND_METHOD_TEST(f) JSFUN_FLAGS_TEST(f, JSFUN_BOUND_METHOD)
#define JSFUN_HEAVYWEIGHT_TEST(f) JSFUN_FLAGS_TEST(f, JSFUN_HEAVYWEIGHT)
#define JSFUN_GSFLAG2ATTR(f) (JSFUN_GETTER_TEST(f) ? JSPROP_GETTER : \
JSFUN_SETTER_TEST(f) ? JSPROP_SETTER : 0)
#define JSFUN_THISP_FLAGS(f) (JSFUN_GSFLAGS(~(f)) ? 0 : \
(f) & JSFUN_THISP_PRIMITIVE)
#define JSFUN_THISP_TEST(f,t) ((f) == (t))
#define JSFUN_THISP_STRING 0x30 /* |this| may be a primitive string */
#define JSFUN_THISP_NUMBER 0x70 /* |this| may be a primitive number */
#define JSFUN_THISP_BOOLEAN 0xb0 /* |this| may be a primitive boolean */
#define JSFUN_THISP_PRIMITIVE 0xf0 /* |this| may be any primitive value */
#define JSFUN_FLAGS_MASK 0xf8 /* overlay JSFUN_* attributes */
#else
#define JSFUN_GETTER_TEST(f) ((f) & JSFUN_GETTER)
#define JSFUN_SETTER_TEST(f) ((f) & JSFUN_SETTER)
#define JSFUN_BOUND_METHOD_TEST(f) ((f) & JSFUN_BOUND_METHOD)
#define JSFUN_HEAVYWEIGHT_TEST(f) ((f) & JSFUN_HEAVYWEIGHT)
#define JSFUN_GSFLAG2ATTR(f) JSFUN_GSFLAGS(f)
#define JSFUN_THISP_FLAGS(f) (f)
#define JSFUN_THISP_TEST(f,t) ((f) & t)
#define JSFUN_THISP_STRING 0x0100 /* |this| may be a primitive string */
#define JSFUN_THISP_NUMBER 0x0200 /* |this| may be a primitive number */
#define JSFUN_THISP_BOOLEAN 0x0400 /* |this| may be a primitive boolean */
#define JSFUN_THISP_PRIMITIVE 0x0700 /* |this| may be any primitive value */
#define JSFUN_FLAGS_MASK 0x07f8 /* overlay JSFUN_* attributes --
note that bit #15 is used internally
to flag interpreted functions */
#endif
/*
* Re-use JSFUN_LAMBDA, which applies only to scripted functions, for use in
* JSFunctionSpec arrays that specify generic native prototype methods, i.e.,
@ -1119,12 +1164,18 @@ struct JSPropertySpec {
struct JSFunctionSpec {
const char *name;
JSNative call;
#ifdef MOZILLA_1_8_BRANCH
uint8 nargs;
uint8 flags;
uint16 extra;
#else
uint16 nargs;
uint16 flags;
uint32 extra; /* extra & 0xFFFF:
number of arg slots for local GC roots
extra >> 16:
reserved, must be zero */
#endif
};
extern JS_PUBLIC_API(JSObject *)

View File

@ -1303,6 +1303,22 @@ JS_GetScriptFilenameFlags(JSScript *script)
return js_GetScriptFilenameFlags(script->filename);
}
JS_PUBLIC_API(uint32)
JS_GetTopScriptFilenameFlags(JSContext *cx, JSStackFrame *fp)
{
if (!fp)
fp = cx->fp;
while (fp) {
if (fp->script) {
if (!fp->script->filename)
return JSFILENAME_NULL;
return js_GetScriptFilenameFlags(fp->script->filename);
}
fp = fp->down;
}
return 0;
}
JS_PUBLIC_API(JSBool)
JS_FlagScriptFilenamePrefix(JSRuntime *rt, const char *prefix, uint32 flags)
{

View File

@ -357,6 +357,12 @@ JS_GetScriptTotalSize(JSContext *cx, JSScript *script);
extern JS_PUBLIC_API(uint32)
JS_GetScriptFilenameFlags(JSScript *script);
/*
* Get the filename flags for the top-most active script on cx.
*/
extern JS_PUBLIC_API(uint32)
JS_GetTopScriptFilenameFlags(JSContext *cx, JSStackFrame *fp);
/*
* Associate flags with a script filename prefix in rt, so that any subsequent
* script compilation will inherit those flags if the script's filename is the

View File

@ -2273,7 +2273,7 @@ js_MarkStackFrame(JSContext *cx, JSStackFrame *fp)
}
}
JS_ASSERT(JSVAL_IS_OBJECT((jsval)fp->thisp) ||
(fp->fun && (fp->fun->flags & JSFUN_THISP_PRIMITIVE)));
(fp->fun && JSFUN_THISP_FLAGS(fp->fun->flags)));
if (JSVAL_IS_GCTHING((jsval)fp->thisp))
GC_MARK(cx, fp->thisp, "this");
if (fp->argv) {

View File

@ -1152,34 +1152,36 @@ have_fun:
nslots += fun->u.n.extra;
}
if (fun->flags & JSFUN_BOUND_METHOD) {
if (JSFUN_BOUND_METHOD_TEST(fun->flags)) {
/* Handle bound method special case. */
thisp = parent;
} else if (JSVAL_IS_OBJECT(thisv)) {
thisp = JSVAL_TO_OBJECT(thisv);
} else {
uintN thispflags = JSFUN_THISP_FLAGS(fun->flags);
JS_ASSERT(!(flags & JSINVOKE_CONSTRUCT));
if (JSVAL_IS_STRING(thisv)) {
if (fun->flags & JSFUN_THISP_STRING) {
if (JSFUN_THISP_TEST(thispflags, JSFUN_THISP_STRING)) {
thisp = (JSObject *) thisv;
goto init_frame;
}
thisp = js_StringToObject(cx, JSVAL_TO_STRING(thisv));
} else if (JSVAL_IS_INT(thisv)) {
if (fun->flags & JSFUN_THISP_NUMBER) {
if (JSFUN_THISP_TEST(thispflags, JSFUN_THISP_NUMBER)) {
thisp = (JSObject *) thisv;
goto init_frame;
}
thisp = js_NumberToObject(cx, (jsdouble)JSVAL_TO_INT(thisv));
} else if (JSVAL_IS_DOUBLE(thisv)) {
if (fun->flags & JSFUN_THISP_NUMBER) {
if (JSFUN_THISP_TEST(thispflags, JSFUN_THISP_NUMBER)) {
thisp = (JSObject *) thisv;
goto init_frame;
}
thisp = js_NumberToObject(cx, *JSVAL_TO_DOUBLE(thisv));
} else {
JS_ASSERT(JSVAL_IS_BOOLEAN(thisv));
if (fun->flags & JSFUN_THISP_BOOLEAN) {
if (JSFUN_THISP_TEST(thispflags, JSFUN_THISP_BOOLEAN)) {
thisp = (JSObject *) thisv;
goto init_frame;
}
@ -1337,7 +1339,7 @@ have_fun:
#endif
/* Use parent scope so js_GetCallObject can find the right "Call". */
frame.scopeChain = parent;
if (fun->flags & JSFUN_HEAVYWEIGHT) {
if (JSFUN_HEAVYWEIGHT_TEST(fun->flags)) {
/* Scope with a call object parented by the callee's parent. */
if (!js_GetCallObject(cx, &frame, parent)) {
ok = JS_FALSE;
@ -3975,7 +3977,7 @@ interrupt:
}
newifp->frame.thisp =
js_ComputeThis(cx,
(fun->flags & JSFUN_BOUND_METHOD)
JSFUN_BOUND_METHOD_TEST(fun->flags)
? parent
: JSVAL_TO_OBJECT(vp[1]),
newifp->frame.argv);
@ -4007,7 +4009,7 @@ interrupt:
}
/* Scope with a call object parented by the callee's parent. */
if ((fun->flags & JSFUN_HEAVYWEIGHT) &&
if (JSFUN_HEAVYWEIGHT_TEST(fun->flags) &&
!js_GetCallObject(cx, &newifp->frame, parent)) {
ok = JS_FALSE;
goto out;
@ -4937,7 +4939,7 @@ interrupt:
* and setters do not need a slot, their value is stored elsewhere
* in the property itself, not in obj->slots.
*/
flags = fun->flags & (JSFUN_GETTER | JSFUN_SETTER);
flags = JSFUN_GSFLAG2ATTR(fun->flags);
if (flags) {
attrs |= flags | JSPROP_SHARED;
rval = JSVAL_VOID;
@ -4954,10 +4956,10 @@ interrupt:
ok = js_CheckRedeclaration(cx, parent, id, attrs, NULL, NULL);
if (ok) {
ok = OBJ_DEFINE_PROPERTY(cx, parent, id, rval,
(flags & JSFUN_GETTER)
(flags & JSPROP_GETTER)
? (JSPropertyOp) obj
: NULL,
(flags & JSFUN_SETTER)
(flags & JSPROP_SETTER)
? (JSPropertyOp) obj
: NULL,
attrs,
@ -5092,16 +5094,16 @@ interrupt:
* value is Result(3), and attributes are { DontDelete, ReadOnly }.
*/
fun = (JSFunction *) JS_GetPrivate(cx, obj);
attrs = fun->flags & (JSFUN_GETTER | JSFUN_SETTER);
attrs = JSFUN_GSFLAG2ATTR(fun->flags);
if (attrs) {
attrs |= JSPROP_SHARED;
rval = JSVAL_VOID;
}
ok = OBJ_DEFINE_PROPERTY(cx, parent, ATOM_TO_JSID(fun->atom), rval,
(attrs & JSFUN_GETTER)
(attrs & JSPROP_GETTER)
? (JSPropertyOp) obj
: NULL,
(attrs & JSFUN_SETTER)
(attrs & JSPROP_SETTER)
? (JSPropertyOp) obj
: NULL,
attrs |
@ -5171,17 +5173,17 @@ interrupt:
* a JSPropertyOp and passed accordingly).
*/
fun = (JSFunction *) JS_GetPrivate(cx, obj);
attrs = fun->flags & (JSFUN_GETTER | JSFUN_SETTER);
attrs = JSFUN_GSFLAG2ATTR(fun->flags);
if (attrs) {
attrs |= JSPROP_SHARED;
rval = JSVAL_VOID;
}
parent = fp->varobj;
ok = OBJ_DEFINE_PROPERTY(cx, parent, ATOM_TO_JSID(fun->atom), rval,
(attrs & JSFUN_GETTER)
(attrs & JSPROP_GETTER)
? (JSPropertyOp) obj
: NULL,
(attrs & JSFUN_SETTER)
(attrs & JSPROP_SETTER)
? (JSPropertyOp) obj
: NULL,
attrs | JSPROP_ENUMERATE

View File

@ -3126,9 +3126,9 @@ js_DecompileFunction(JSPrinter *jp, JSFunction *fun)
if (!jp->grouped && (fun->flags & JSFUN_LAMBDA))
js_puts(jp, "(");
}
if (fun->flags & JSFUN_GETTER)
if (JSFUN_GETTER_TEST(fun->flags))
js_printf(jp, "%s ", js_getter_str);
else if (fun->flags & JSFUN_SETTER)
else if (JSFUN_SETTER_TEST(fun->flags))
js_printf(jp, "%s ", js_setter_str);
js_printf(jp, "%s ", js_function_str);

View File

@ -284,7 +284,7 @@ script_exec(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
caller = JS_GetScriptedCaller(cx, fp);
if (caller && !caller->varobj) {
/* Called from a lightweight function. */
JS_ASSERT(caller->fun && !(caller->fun->flags & JSFUN_HEAVYWEIGHT));
JS_ASSERT(caller->fun && !JSFUN_HEAVYWEIGHT_TEST(caller->fun->flags));
/* Scope chain links from Call object to callee's parent. */
parent = OBJ_GET_PARENT(cx, JSVAL_TO_OBJECT(caller->argv[-2]));

View File

@ -7652,7 +7652,7 @@ js_SetDefaultXMLNamespace(JSContext *cx, jsval v)
return JS_FALSE;
}
} else {
JS_ASSERT(fp->fun && !(fp->fun->flags & JSFUN_HEAVYWEIGHT));
JS_ASSERT(fp->fun && !JSFUN_HEAVYWEIGHT_TEST(fp->fun->flags));
}
fp->xmlNamespace = JSVAL_TO_OBJECT(v);
return JS_TRUE;