Bug 458735 - Improve internal API for traceable natives (r=brendan, nanojit r=edwsmith)
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4; -*-
|
||||
* vim: set ts=8 sw=4 et tw=99:
|
||||
*
|
||||
* ***** BEGIN LICENSE BLOCK *****
|
||||
@@ -55,14 +55,15 @@
|
||||
#include "jsdate.h"
|
||||
#include "jsscope.h"
|
||||
#include "jsstr.h"
|
||||
#include "jstracer.h"
|
||||
#include "jsbuiltins.h"
|
||||
|
||||
#include "nanojit/avmplus.h"
|
||||
#include "nanojit/nanojit.h"
|
||||
#include "nanojit.h"
|
||||
|
||||
using namespace avmplus;
|
||||
using namespace nanojit;
|
||||
|
||||
extern jsdouble js_NaN;
|
||||
|
||||
/*
|
||||
* NB: bool FASTCALL is not compatible with Nanojit's calling convention usage.
|
||||
* Do not use bool FASTCALL, use JSBool only!
|
||||
@@ -88,8 +89,8 @@ js_dmod(jsdouble a, jsdouble b)
|
||||
return r;
|
||||
}
|
||||
|
||||
jsint FASTCALL
|
||||
js_imod(jsint a, jsint b)
|
||||
int32 FASTCALL
|
||||
js_imod(int32 a, int32 b)
|
||||
{
|
||||
if (a < 0 || b <= 0)
|
||||
return -1;
|
||||
@@ -104,7 +105,7 @@ js_imod(jsint a, jsint b)
|
||||
jsval FASTCALL
|
||||
js_BoxDouble(JSContext* cx, jsdouble d)
|
||||
{
|
||||
jsint i;
|
||||
int32 i;
|
||||
if (JSDOUBLE_IS_INT(d, i))
|
||||
return INT_TO_JSVAL(i);
|
||||
JS_ASSERT(JS_ON_TRACE(cx));
|
||||
@@ -115,7 +116,7 @@ js_BoxDouble(JSContext* cx, jsdouble d)
|
||||
}
|
||||
|
||||
jsval FASTCALL
|
||||
js_BoxInt32(JSContext* cx, jsint i)
|
||||
js_BoxInt32(JSContext* cx, int32 i)
|
||||
{
|
||||
if (JS_LIKELY(INT_FITS_IN_JSVAL(i)))
|
||||
return INT_TO_JSVAL(i);
|
||||
@@ -135,7 +136,7 @@ js_UnboxDouble(jsval v)
|
||||
return *JSVAL_TO_DOUBLE(v);
|
||||
}
|
||||
|
||||
jsint FASTCALL
|
||||
int32 FASTCALL
|
||||
js_UnboxInt32(jsval v)
|
||||
{
|
||||
if (JS_LIKELY(JSVAL_IS_INT(v)))
|
||||
@@ -149,291 +150,12 @@ js_DoubleToInt32(jsdouble d)
|
||||
return js_DoubleToECMAInt32(d);
|
||||
}
|
||||
|
||||
int32 FASTCALL
|
||||
uint32 FASTCALL
|
||||
js_DoubleToUint32(jsdouble d)
|
||||
{
|
||||
return js_DoubleToECMAUint32(d);
|
||||
}
|
||||
|
||||
jsdouble FASTCALL
|
||||
js_Math_sin(jsdouble d)
|
||||
{
|
||||
return sin(d);
|
||||
}
|
||||
|
||||
jsdouble FASTCALL
|
||||
js_Math_cos(jsdouble d)
|
||||
{
|
||||
return cos(d);
|
||||
}
|
||||
|
||||
jsdouble FASTCALL
|
||||
js_Math_floor(jsdouble d)
|
||||
{
|
||||
return floor(d);
|
||||
}
|
||||
|
||||
jsdouble FASTCALL
|
||||
js_Math_ceil(jsdouble d)
|
||||
{
|
||||
return ceil(d);
|
||||
}
|
||||
|
||||
extern jsdouble js_NaN;
|
||||
|
||||
jsdouble FASTCALL
|
||||
js_Math_pow(jsdouble d, jsdouble p)
|
||||
{
|
||||
if (!JSDOUBLE_IS_FINITE(p) && (d == 1.0 || d == -1.0))
|
||||
return js_NaN;
|
||||
if (p == 0)
|
||||
return 1.0;
|
||||
return pow(d, p);
|
||||
}
|
||||
|
||||
jsdouble FASTCALL
|
||||
js_Math_sqrt(jsdouble d)
|
||||
{
|
||||
return sqrt(d);
|
||||
}
|
||||
|
||||
jsdouble FASTCALL
|
||||
js_Math_log(jsdouble d)
|
||||
{
|
||||
#if !JS_USE_FDLIBM_MATH && defined(SOLARIS) && defined(__GNUC__)
|
||||
if (d < 0)
|
||||
return js_NaN;
|
||||
#endif
|
||||
return log(d);
|
||||
}
|
||||
|
||||
jsdouble FASTCALL
|
||||
js_Math_max(jsdouble d, jsdouble p)
|
||||
{
|
||||
if (JSDOUBLE_IS_NaN(d) || JSDOUBLE_IS_NaN(p))
|
||||
return js_NaN;
|
||||
|
||||
if (p == 0 && p == d && fd_copysign(1.0, d) == -1)
|
||||
return p;
|
||||
/*
|
||||
* Note: it is essential that you write the ternary expression here such
|
||||
* that the false branch produces d not p, as the case of p=-0, d=0, for
|
||||
* which we wind up in this expression but evaluate either > order as
|
||||
* false, whether we do p>d *or* d>p.
|
||||
*/
|
||||
return (p > d) ? p : d;
|
||||
}
|
||||
|
||||
JSBool FASTCALL
|
||||
js_Array_dense_setelem(JSContext* cx, JSObject* obj, jsint i, jsval v)
|
||||
{
|
||||
JS_ASSERT(OBJ_IS_DENSE_ARRAY(cx, obj));
|
||||
|
||||
do {
|
||||
jsuint length = ARRAY_DENSE_LENGTH(obj);
|
||||
if ((jsuint)i < length) {
|
||||
if (obj->dslots[i] == JSVAL_HOLE) {
|
||||
if (cx->runtime->anyArrayProtoHasElement)
|
||||
break;
|
||||
if (i >= obj->fslots[JSSLOT_ARRAY_LENGTH])
|
||||
obj->fslots[JSSLOT_ARRAY_LENGTH] = i + 1;
|
||||
obj->fslots[JSSLOT_ARRAY_COUNT]++;
|
||||
}
|
||||
obj->dslots[i] = v;
|
||||
return JS_TRUE;
|
||||
}
|
||||
} while (0);
|
||||
return OBJ_SET_PROPERTY(cx, obj, INT_TO_JSID(i), &v);
|
||||
}
|
||||
|
||||
JSString* FASTCALL
|
||||
js_Array_p_join(JSContext* cx, JSObject* obj, JSString *str)
|
||||
{
|
||||
jsval v;
|
||||
if (!js_array_join_sub(cx, obj, TO_STRING, str, &v))
|
||||
return NULL;
|
||||
JS_ASSERT(JSVAL_IS_STRING(v));
|
||||
return JSVAL_TO_STRING(v);
|
||||
}
|
||||
|
||||
jsval FASTCALL
|
||||
js_Array_p_push1(JSContext* cx, JSObject* obj, jsval v)
|
||||
{
|
||||
if (!(OBJ_IS_DENSE_ARRAY(cx, obj)
|
||||
? js_array_push1_dense(cx, obj, v, &v)
|
||||
: js_array_push_slowly(cx, obj, 1, &v, &v))) {
|
||||
return JSVAL_ERROR_COOKIE;
|
||||
}
|
||||
return v;
|
||||
}
|
||||
|
||||
jsval FASTCALL
|
||||
js_Array_p_pop(JSContext* cx, JSObject* obj)
|
||||
{
|
||||
jsval v;
|
||||
if (!(OBJ_IS_DENSE_ARRAY(cx, obj)
|
||||
? js_array_pop_dense(cx, obj, &v)
|
||||
: js_array_pop_slowly(cx, obj, &v))) {
|
||||
return JSVAL_ERROR_COOKIE;
|
||||
}
|
||||
return v;
|
||||
}
|
||||
|
||||
JSString* FASTCALL
|
||||
js_String_p_substring(JSContext* cx, JSString* str, jsint begin, jsint end)
|
||||
{
|
||||
JS_ASSERT(end >= begin);
|
||||
JS_ASSERT(JS_ON_TRACE(cx));
|
||||
return js_NewDependentString(cx, str, (size_t)begin, (size_t)(end - begin));
|
||||
}
|
||||
|
||||
JSString* FASTCALL
|
||||
js_String_p_substring_1(JSContext* cx, JSString* str, jsint begin)
|
||||
{
|
||||
jsint end = JSSTRING_LENGTH(str);
|
||||
JS_ASSERT(end >= begin);
|
||||
JS_ASSERT(JS_ON_TRACE(cx));
|
||||
return js_NewDependentString(cx, str, (size_t)begin, (size_t)(end - begin));
|
||||
}
|
||||
|
||||
JSString* FASTCALL
|
||||
js_String_getelem(JSContext* cx, JSString* str, jsint i)
|
||||
{
|
||||
if ((size_t)i >= JSSTRING_LENGTH(str))
|
||||
return NULL;
|
||||
return js_GetUnitString(cx, str, (size_t)i);
|
||||
}
|
||||
|
||||
JSString* FASTCALL
|
||||
js_String_fromCharCode(JSContext* cx, jsint i)
|
||||
{
|
||||
JS_ASSERT(JS_ON_TRACE(cx));
|
||||
jschar c = (jschar)i;
|
||||
if (c < UNIT_STRING_LIMIT)
|
||||
return js_GetUnitStringForChar(cx, c);
|
||||
return js_NewStringCopyN(cx, &c, 1);
|
||||
}
|
||||
|
||||
jsint FASTCALL
|
||||
js_String_p_charCodeAt(JSString* str, jsint i)
|
||||
{
|
||||
if (i < 0 || (jsint)JSSTRING_LENGTH(str) <= i)
|
||||
return -1;
|
||||
return JSSTRING_CHARS(str)[i];
|
||||
}
|
||||
|
||||
jsdouble FASTCALL
|
||||
js_Math_random(JSRuntime* rt)
|
||||
{
|
||||
JS_LOCK_RUNTIME(rt);
|
||||
js_random_init(rt);
|
||||
jsdouble z = js_random_nextDouble(rt);
|
||||
JS_UNLOCK_RUNTIME(rt);
|
||||
return z;
|
||||
}
|
||||
|
||||
JSString* FASTCALL
|
||||
js_String_p_concat_1int(JSContext* cx, JSString* str, jsint i)
|
||||
{
|
||||
// FIXME: should be able to use stack buffer and avoid istr...
|
||||
JSString* istr = js_NumberToString(cx, i);
|
||||
if (!istr)
|
||||
return NULL;
|
||||
return js_ConcatStrings(cx, str, istr);
|
||||
}
|
||||
|
||||
JSString* FASTCALL
|
||||
js_String_p_concat_2str(JSContext* cx, JSString* str, JSString* a, JSString* b)
|
||||
{
|
||||
str = js_ConcatStrings(cx, str, a);
|
||||
if (str)
|
||||
return js_ConcatStrings(cx, str, b);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
JSString* FASTCALL
|
||||
js_String_p_concat_3str(JSContext* cx, JSString* str, JSString* a, JSString* b, JSString* c)
|
||||
{
|
||||
str = js_ConcatStrings(cx, str, a);
|
||||
if (str) {
|
||||
str = js_ConcatStrings(cx, str, b);
|
||||
if (str)
|
||||
return js_ConcatStrings(cx, str, c);
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
JSObject* FASTCALL
|
||||
js_String_p_match(JSContext* cx, JSString* str, jsbytecode *pc, JSObject* regexp)
|
||||
{
|
||||
jsval vp[3] = { JSVAL_NULL, STRING_TO_JSVAL(str), OBJECT_TO_JSVAL(regexp) };
|
||||
if (!js_StringMatchHelper(cx, 1, vp, pc))
|
||||
return (JSObject*) JSVAL_TO_BOOLEAN(JSVAL_VOID);
|
||||
JS_ASSERT(JSVAL_IS_NULL(vp[0]) ||
|
||||
(!JSVAL_IS_PRIMITIVE(vp[0]) && OBJ_IS_ARRAY(cx, JSVAL_TO_OBJECT(vp[0]))));
|
||||
return JSVAL_TO_OBJECT(vp[0]);
|
||||
}
|
||||
|
||||
JSObject* FASTCALL
|
||||
js_String_p_match_obj(JSContext* cx, JSObject* str, jsbytecode *pc, JSObject* regexp)
|
||||
{
|
||||
jsval vp[3] = { JSVAL_NULL, OBJECT_TO_JSVAL(str), OBJECT_TO_JSVAL(regexp) };
|
||||
if (!js_StringMatchHelper(cx, 1, vp, pc))
|
||||
return (JSObject*) JSVAL_TO_BOOLEAN(JSVAL_VOID);
|
||||
JS_ASSERT(JSVAL_IS_NULL(vp[0]) ||
|
||||
(!JSVAL_IS_PRIMITIVE(vp[0]) && OBJ_IS_ARRAY(cx, JSVAL_TO_OBJECT(vp[0]))));
|
||||
return JSVAL_TO_OBJECT(vp[0]);
|
||||
}
|
||||
|
||||
JSString* FASTCALL
|
||||
js_String_p_replace_str(JSContext* cx, JSString* str, JSObject* regexp, JSString* repstr)
|
||||
{
|
||||
jsval vp[4] = {
|
||||
JSVAL_NULL, STRING_TO_JSVAL(str), OBJECT_TO_JSVAL(regexp), STRING_TO_JSVAL(repstr)
|
||||
};
|
||||
if (!js_StringReplaceHelper(cx, 2, NULL, repstr, vp))
|
||||
return NULL;
|
||||
JS_ASSERT(JSVAL_IS_STRING(vp[0]));
|
||||
return JSVAL_TO_STRING(vp[0]);
|
||||
}
|
||||
|
||||
JSString* FASTCALL
|
||||
js_String_p_replace_str2(JSContext* cx, JSString* str, JSString* patstr, JSString* repstr)
|
||||
{
|
||||
jsval vp[4] = {
|
||||
JSVAL_NULL, STRING_TO_JSVAL(str), STRING_TO_JSVAL(patstr), STRING_TO_JSVAL(repstr)
|
||||
};
|
||||
if (!js_StringReplaceHelper(cx, 2, NULL, repstr, vp))
|
||||
return NULL;
|
||||
JS_ASSERT(JSVAL_IS_STRING(vp[0]));
|
||||
return JSVAL_TO_STRING(vp[0]);
|
||||
}
|
||||
|
||||
JSString* FASTCALL
|
||||
js_String_p_replace_str3(JSContext* cx, JSString* str, JSString* patstr, JSString* repstr,
|
||||
JSString* flagstr)
|
||||
{
|
||||
jsval vp[5] = {
|
||||
JSVAL_NULL, STRING_TO_JSVAL(str), STRING_TO_JSVAL(patstr), STRING_TO_JSVAL(repstr),
|
||||
STRING_TO_JSVAL(flagstr)
|
||||
};
|
||||
if (!js_StringReplaceHelper(cx, 3, NULL, repstr, vp))
|
||||
return NULL;
|
||||
JS_ASSERT(JSVAL_IS_STRING(vp[0]));
|
||||
return JSVAL_TO_STRING(vp[0]);
|
||||
}
|
||||
|
||||
JSObject* FASTCALL
|
||||
js_String_p_split(JSContext* cx, JSString* str, JSString* sepstr)
|
||||
{
|
||||
// FIXME: optimize by calling into a lower level exported from jsstr.cpp.
|
||||
jsval vp[4] = { JSVAL_NULL, STRING_TO_JSVAL(str), STRING_TO_JSVAL(sepstr), JSVAL_VOID };
|
||||
if (!js_str_split(cx, 2, vp))
|
||||
return NULL;
|
||||
JS_ASSERT(JSVAL_IS_OBJECT(vp[0]));
|
||||
return JSVAL_TO_OBJECT(vp[0]);
|
||||
}
|
||||
|
||||
jsdouble FASTCALL
|
||||
js_StringToNumber(JSContext* cx, JSString* str)
|
||||
{
|
||||
@@ -452,7 +174,7 @@ js_StringToNumber(JSContext* cx, JSString* str)
|
||||
return d;
|
||||
}
|
||||
|
||||
jsint FASTCALL
|
||||
int32 FASTCALL
|
||||
js_StringToInt32(JSContext* cx, JSString* str)
|
||||
{
|
||||
const jschar* bp;
|
||||
@@ -463,43 +185,7 @@ js_StringToInt32(JSContext* cx, JSString* str)
|
||||
JSSTRING_CHARS_AND_END(str, bp, end);
|
||||
if (!js_strtod(cx, bp, end, &ep, &d) || js_SkipWhiteSpace(ep, end) != end)
|
||||
return 0;
|
||||
return (jsint)d;
|
||||
}
|
||||
|
||||
jsdouble FASTCALL
|
||||
js_ParseFloat(JSContext* cx, JSString* str)
|
||||
{
|
||||
const jschar* bp;
|
||||
const jschar* end;
|
||||
const jschar* ep;
|
||||
jsdouble d;
|
||||
|
||||
JSSTRING_CHARS_AND_END(str, bp, end);
|
||||
if (!js_strtod(cx, bp, end, &ep, &d) || ep == bp)
|
||||
return js_NaN;
|
||||
return d;
|
||||
}
|
||||
|
||||
jsdouble FASTCALL
|
||||
js_ParseInt(JSContext* cx, JSString* str)
|
||||
{
|
||||
const jschar* bp;
|
||||
const jschar* end;
|
||||
const jschar* ep;
|
||||
jsdouble d;
|
||||
|
||||
JSSTRING_CHARS_AND_END(str, bp, end);
|
||||
if (!js_strtointeger(cx, bp, end, &ep, 0, &d) || ep == bp)
|
||||
return js_NaN;
|
||||
return d;
|
||||
}
|
||||
|
||||
jsdouble FASTCALL
|
||||
js_ParseIntDouble(jsdouble d)
|
||||
{
|
||||
if (!JSDOUBLE_IS_FINITE(d))
|
||||
return js_NaN;
|
||||
return floor(d);
|
||||
return (int32)d;
|
||||
}
|
||||
|
||||
jsval FASTCALL
|
||||
@@ -525,7 +211,7 @@ js_Any_setprop(JSContext* cx, JSObject* obj, JSString* idstr, jsval v)
|
||||
}
|
||||
|
||||
jsval FASTCALL
|
||||
js_Any_getelem(JSContext* cx, JSObject* obj, jsint index)
|
||||
js_Any_getelem(JSContext* cx, JSObject* obj, uint32 index)
|
||||
{
|
||||
jsval v;
|
||||
jsid id;
|
||||
@@ -539,7 +225,7 @@ js_Any_getelem(JSContext* cx, JSObject* obj, jsint index)
|
||||
}
|
||||
|
||||
JSBool FASTCALL
|
||||
js_Any_setelem(JSContext* cx, JSObject* obj, jsint index, jsval v)
|
||||
js_Any_setelem(JSContext* cx, JSObject* obj, uint32 index, jsval v)
|
||||
{
|
||||
jsid id;
|
||||
if (index < 0)
|
||||
@@ -597,44 +283,14 @@ js_CallTree(InterpState* state, Fragment* f)
|
||||
return lr;
|
||||
}
|
||||
|
||||
JS_STATIC_ASSERT(JSSLOT_PRIVATE == JSSLOT_ARRAY_LENGTH);
|
||||
JS_STATIC_ASSERT(JSSLOT_ARRAY_LENGTH + 1 == JSSLOT_ARRAY_COUNT);
|
||||
|
||||
JSObject* FASTCALL
|
||||
js_FastNewArray(JSContext* cx, JSObject* proto)
|
||||
{
|
||||
JS_ASSERT(OBJ_IS_ARRAY(cx, proto));
|
||||
|
||||
JS_ASSERT(JS_ON_TRACE(cx));
|
||||
JSObject* obj = (JSObject*) js_NewGCThing(cx, GCX_OBJECT, sizeof(JSObject));
|
||||
if (!obj)
|
||||
return NULL;
|
||||
|
||||
JSClass* clasp = &js_ArrayClass;
|
||||
obj->classword = jsuword(clasp);
|
||||
|
||||
obj->fslots[JSSLOT_PROTO] = OBJECT_TO_JSVAL(proto);
|
||||
obj->fslots[JSSLOT_PARENT] = proto->fslots[JSSLOT_PARENT];
|
||||
|
||||
obj->fslots[JSSLOT_ARRAY_LENGTH] = 0;
|
||||
obj->fslots[JSSLOT_ARRAY_COUNT] = 0;
|
||||
for (unsigned i = JSSLOT_ARRAY_COUNT + 1; i != JS_INITIAL_NSLOTS; ++i)
|
||||
obj->fslots[i] = JSVAL_VOID;
|
||||
|
||||
JSObjectOps* ops = clasp->getObjectOps(cx, clasp);
|
||||
obj->map = ops->newObjectMap(cx, 1, ops, clasp, obj);
|
||||
if (!obj->map)
|
||||
return NULL;
|
||||
obj->dslots = NULL;
|
||||
return obj;
|
||||
}
|
||||
|
||||
JSObject* FASTCALL
|
||||
js_FastNewObject(JSContext* cx, JSObject* ctor)
|
||||
{
|
||||
JS_ASSERT(HAS_FUNCTION_CLASS(ctor));
|
||||
JSFunction* fun = GET_FUNCTION_PRIVATE(cx, ctor);
|
||||
JSClass* clasp = FUN_INTERPRETED(fun) ? &js_ObjectClass : fun->u.n.clasp;
|
||||
JSClass* clasp = (FUN_INTERPRETED(fun) || (fun->flags & JSFUN_TRACEABLE))
|
||||
? &js_ObjectClass
|
||||
: FUN_CLASP(fun);
|
||||
JS_ASSERT(clasp != &js_ArrayClass);
|
||||
|
||||
JS_LOCK_OBJ(cx, ctor);
|
||||
@@ -764,7 +420,7 @@ js_TypeOfObject(JSContext* cx, JSObject* obj)
|
||||
}
|
||||
|
||||
JSString* FASTCALL
|
||||
js_TypeOfBoolean(JSContext* cx, jsint unboxed)
|
||||
js_TypeOfBoolean(JSContext* cx, int32 unboxed)
|
||||
{
|
||||
jsval boxed = BOOLEAN_TO_JSVAL(unboxed);
|
||||
JS_ASSERT(JSVAL_IS_VOID(boxed) || JSVAL_IS_BOOLEAN(boxed));
|
||||
@@ -772,30 +428,8 @@ js_TypeOfBoolean(JSContext* cx, jsint unboxed)
|
||||
return ATOM_TO_STRING(cx->runtime->atomState.typeAtoms[type]);
|
||||
}
|
||||
|
||||
jsint FASTCALL
|
||||
js_Object_p_hasOwnProperty(JSContext* cx, JSObject* obj, JSString *str)
|
||||
{
|
||||
jsid id = ATOM_TO_JSID(STRING_TO_JSVAL(str));
|
||||
jsval v;
|
||||
if (!js_HasOwnProperty(cx, obj->map->ops->lookupProperty, obj, id, &v))
|
||||
return JSVAL_TO_BOOLEAN(JSVAL_VOID);
|
||||
JS_ASSERT(JSVAL_IS_BOOLEAN(v));
|
||||
return JSVAL_TO_BOOLEAN(v);
|
||||
}
|
||||
|
||||
jsint FASTCALL
|
||||
js_Object_p_propertyIsEnumerable(JSContext* cx, JSObject* obj, JSString *str)
|
||||
{
|
||||
jsid id = ATOM_TO_JSID(STRING_TO_JSVAL(str));
|
||||
jsval v;
|
||||
if (!js_PropertyIsEnumerable(cx, obj, id, &v))
|
||||
return JSVAL_TO_BOOLEAN(JSVAL_VOID);
|
||||
JS_ASSERT(JSVAL_IS_BOOLEAN(v));
|
||||
return JSVAL_TO_BOOLEAN(v);
|
||||
}
|
||||
|
||||
jsdouble FASTCALL
|
||||
js_BooleanToNumber(JSContext* cx, jsint unboxed)
|
||||
js_BooleanToNumber(JSContext* cx, int32 unboxed)
|
||||
{
|
||||
if (unboxed == JSVAL_TO_BOOLEAN(JSVAL_VOID))
|
||||
return js_NaN;
|
||||
@@ -814,103 +448,12 @@ js_ObjectToString(JSContext* cx, JSObject* obj)
|
||||
return JSVAL_TO_STRING(v);
|
||||
}
|
||||
|
||||
JSObject* FASTCALL
|
||||
js_Array_1int(JSContext* cx, JSObject* proto, jsint i)
|
||||
{
|
||||
JS_ASSERT(JS_ON_TRACE(cx));
|
||||
JSObject* obj = js_FastNewArray(cx, proto);
|
||||
if (obj)
|
||||
obj->fslots[JSSLOT_ARRAY_LENGTH] = i;
|
||||
return obj;
|
||||
}
|
||||
|
||||
#define ARRAY_CTOR_GUTS(exact_len, newslots_code) \
|
||||
JS_ASSERT(JS_ON_TRACE(cx)); \
|
||||
JSObject* obj = js_FastNewArray(cx, proto); \
|
||||
if (obj) { \
|
||||
const uint32 len = ARRAY_GROWBY; \
|
||||
jsval* newslots = (jsval*) JS_malloc(cx, sizeof (jsval) * (len + 1)); \
|
||||
if (newslots) { \
|
||||
obj->dslots = newslots + 1; \
|
||||
ARRAY_SET_DENSE_LENGTH(obj, len); \
|
||||
{newslots_code} \
|
||||
while (++newslots < obj->dslots + len) \
|
||||
*newslots = JSVAL_HOLE; \
|
||||
obj->fslots[JSSLOT_ARRAY_LENGTH] = (exact_len); \
|
||||
return obj; \
|
||||
} \
|
||||
} \
|
||||
return NULL;
|
||||
|
||||
JSObject* FASTCALL
|
||||
js_Array_1str(JSContext* cx, JSObject* proto, JSString *str)
|
||||
{
|
||||
ARRAY_CTOR_GUTS(1, *++newslots = STRING_TO_JSVAL(str);)
|
||||
}
|
||||
|
||||
JSObject* FASTCALL
|
||||
js_Array_2obj(JSContext* cx, JSObject* proto, JSObject *obj1, JSObject* obj2)
|
||||
{
|
||||
ARRAY_CTOR_GUTS(2,
|
||||
*++newslots = OBJECT_TO_JSVAL(obj1);
|
||||
*++newslots = OBJECT_TO_JSVAL(obj2);)
|
||||
}
|
||||
|
||||
JSObject* FASTCALL
|
||||
js_Array_3num(JSContext* cx, JSObject* proto, jsdouble n1, jsdouble n2, jsdouble n3)
|
||||
{
|
||||
ARRAY_CTOR_GUTS(3,
|
||||
if (!js_NewDoubleInRootedValue(cx, n1, ++newslots))
|
||||
return NULL;
|
||||
if (!js_NewDoubleInRootedValue(cx, n2, ++newslots))
|
||||
return NULL;
|
||||
if (!js_NewDoubleInRootedValue(cx, n3, ++newslots))
|
||||
return NULL;)
|
||||
}
|
||||
|
||||
JSObject* FASTCALL
|
||||
js_Arguments(JSContext* cx)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
jsdouble FASTCALL
|
||||
js_Date_now(JSContext*)
|
||||
{
|
||||
return PRMJ_Now() / PRMJ_USEC_PER_MSEC;
|
||||
}
|
||||
|
||||
JS_STATIC_ASSERT(JSSLOT_PRIVATE == JSSLOT_UTC_TIME);
|
||||
JS_STATIC_ASSERT(JSSLOT_UTC_TIME + 1 == JSSLOT_LOCAL_TIME);
|
||||
|
||||
JSObject* FASTCALL
|
||||
js_FastNewDate(JSContext* cx, JSObject* proto)
|
||||
{
|
||||
JS_ASSERT(JS_ON_TRACE(cx));
|
||||
JSObject* obj = (JSObject*) js_NewGCThing(cx, GCX_OBJECT, sizeof(JSObject));
|
||||
if (!obj)
|
||||
return NULL;
|
||||
|
||||
JSClass* clasp = &js_DateClass;
|
||||
obj->classword = jsuword(clasp);
|
||||
|
||||
obj->fslots[JSSLOT_PROTO] = OBJECT_TO_JSVAL(proto);
|
||||
obj->fslots[JSSLOT_PARENT] = proto->fslots[JSSLOT_PARENT];
|
||||
|
||||
jsdouble* date = js_NewWeaklyRootedDouble(cx, 0.0);
|
||||
if (!date)
|
||||
return NULL;
|
||||
*date = js_Date_now(cx);
|
||||
obj->fslots[JSSLOT_UTC_TIME] = DOUBLE_TO_JSVAL(date);
|
||||
obj->fslots[JSSLOT_LOCAL_TIME] = DOUBLE_TO_JSVAL(cx->runtime->jsNaN);;
|
||||
|
||||
JS_ASSERT(!clasp->getObjectOps);
|
||||
JS_ASSERT(proto->map->ops == &js_ObjectOps);
|
||||
obj->map = js_HoldObjectMap(cx, proto->map);
|
||||
obj->dslots = NULL;
|
||||
return obj;
|
||||
}
|
||||
|
||||
/* soft float */
|
||||
|
||||
jsdouble FASTCALL
|
||||
@@ -920,7 +463,7 @@ js_fneg(jsdouble x)
|
||||
}
|
||||
|
||||
jsdouble FASTCALL
|
||||
js_i2f(jsint i)
|
||||
js_i2f(int32 i)
|
||||
{
|
||||
return i;
|
||||
}
|
||||
@@ -931,31 +474,31 @@ js_u2f(jsuint u)
|
||||
return u;
|
||||
}
|
||||
|
||||
jsint FASTCALL
|
||||
int32 FASTCALL
|
||||
js_fcmpeq(jsdouble x, jsdouble y)
|
||||
{
|
||||
return x==y;
|
||||
}
|
||||
|
||||
jsint FASTCALL
|
||||
int32 FASTCALL
|
||||
js_fcmplt(jsdouble x, jsdouble y)
|
||||
{
|
||||
return x < y;
|
||||
}
|
||||
|
||||
jsint FASTCALL
|
||||
int32 FASTCALL
|
||||
js_fcmple(jsdouble x, jsdouble y)
|
||||
{
|
||||
return x <= y;
|
||||
}
|
||||
|
||||
jsint FASTCALL
|
||||
int32 FASTCALL
|
||||
js_fcmpgt(jsdouble x, jsdouble y)
|
||||
{
|
||||
return x > y;
|
||||
}
|
||||
|
||||
jsint FASTCALL
|
||||
int32 FASTCALL
|
||||
js_fcmpge(jsdouble x, jsdouble y)
|
||||
{
|
||||
return x >= y;
|
||||
@@ -984,33 +527,9 @@ js_fsub(jsdouble x, jsdouble y)
|
||||
return x - y;
|
||||
}
|
||||
|
||||
#define LO ARGSIZE_LO
|
||||
#define F ARGSIZE_F
|
||||
#define Q ARGSIZE_Q
|
||||
|
||||
#if defined AVMPLUS_64BIT
|
||||
#define P ARGSIZE_Q
|
||||
#else
|
||||
#define P ARGSIZE_LO
|
||||
#endif
|
||||
|
||||
#ifdef DEBUG
|
||||
#define NAME(op) ,#op
|
||||
#else
|
||||
#define NAME(op)
|
||||
#endif
|
||||
|
||||
#define BUILTIN1(op, at0, atr, tr, t0, cse, fold) \
|
||||
{ (intptr_t)&js_##op, (at0 << 2) | atr, cse, fold NAME(op) },
|
||||
#define BUILTIN2(op, at0, at1, atr, tr, t0, t1, cse, fold) \
|
||||
{ (intptr_t)&js_##op, (at0 << 4) | (at1 << 2) | atr, cse, fold NAME(op) },
|
||||
#define BUILTIN3(op, at0, at1, at2, atr, tr, t0, t1, t2, cse, fold) \
|
||||
{ (intptr_t)&js_##op, (at0 << 6) | (at1 << 4) | (at2 << 2) | atr, cse, fold NAME(op) },
|
||||
#define BUILTIN4(op, at0, at1, at2, at3, atr, tr, t0, t1, t2, t3, cse, fold) \
|
||||
{ (intptr_t)&js_##op, (at0 << 8) | (at1 << 6) | (at2 << 4) | (at3 << 2) | atr, cse, fold NAME(op) },
|
||||
#define BUILTIN5(op, at0, at1, at2, at3, at4, atr, tr, t0, t1, t2, t3, t4, cse, fold) \
|
||||
{ (intptr_t)&js_##op, (at0 << 10) | (at1 << 8) | (at2 << 6) | (at3 << 4) | (at4 << 2) | atr, cse, fold NAME(op) },
|
||||
|
||||
struct CallInfo builtins[] = {
|
||||
#define BUILTIN1 JS_DEFINE_CALLINFO_1
|
||||
#define BUILTIN2 JS_DEFINE_CALLINFO_2
|
||||
#define BUILTIN3 JS_DEFINE_CALLINFO_3
|
||||
#define BUILTIN4 JS_DEFINE_CALLINFO_4
|
||||
#define BUILTIN5 JS_DEFINE_CALLINFO_5
|
||||
#include "builtins.tbl"
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user