2008-07-05 17:29:55 -07:00
|
|
|
/* -*- 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 *****
|
|
|
|
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
|
|
|
*
|
|
|
|
* The contents of this file are subject to the Mozilla Public License Version
|
|
|
|
* 1.1 (the "License"); you may not use this file except in compliance with
|
|
|
|
* the License. You may obtain a copy of the License at
|
|
|
|
* http://www.mozilla.org/MPL/
|
|
|
|
*
|
|
|
|
* Software distributed under the License is distributed on an "AS IS" basis,
|
|
|
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
|
|
|
* for the specific language governing rights and limitations under the
|
|
|
|
* License.
|
|
|
|
*
|
|
|
|
* The Original Code is Mozilla SpiderMonkey JavaScript 1.9 code, released
|
|
|
|
* May 28, 2008.
|
|
|
|
*
|
|
|
|
* The Initial Developer of the Original Code is
|
|
|
|
* Andreas Gal <gal@mozilla.com>
|
|
|
|
*
|
|
|
|
* Contributor(s):
|
|
|
|
* Brendan Eich <brendan@mozilla.org>
|
2008-07-15 15:05:16 -07:00
|
|
|
* Mike Shaver <shaver@mozilla.org>
|
|
|
|
* David Anderson <danderson@mozilla.com>
|
2008-07-05 17:29:55 -07:00
|
|
|
*
|
|
|
|
* Alternatively, the contents of this file may be used under the terms of
|
|
|
|
* either of the GNU General Public License Version 2 or later (the "GPL"),
|
|
|
|
* or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
|
|
|
* in which case the provisions of the GPL or the LGPL are applicable instead
|
|
|
|
* of those above. If you wish to allow use of your version of this file only
|
|
|
|
* under the terms of either the GPL or the LGPL, and not to allow others to
|
|
|
|
* use your version of this file under the terms of the MPL, indicate your
|
|
|
|
* decision by deleting the provisions above and replace them with the notice
|
|
|
|
* and other provisions required by the GPL or the LGPL. If you do not delete
|
|
|
|
* the provisions above, a recipient may use your version of this file under
|
|
|
|
* the terms of any one of the MPL, the GPL or the LGPL.
|
|
|
|
*
|
|
|
|
* ***** END LICENSE BLOCK ***** */
|
|
|
|
|
2008-08-06 13:36:29 -07:00
|
|
|
#include "jsstddef.h"
|
2008-07-05 17:29:55 -07:00
|
|
|
#include <math.h>
|
|
|
|
|
|
|
|
#include "jsapi.h"
|
2008-07-27 15:34:23 -07:00
|
|
|
#include "jsarray.h"
|
|
|
|
#include "jsbool.h"
|
2008-07-05 17:29:55 -07:00
|
|
|
#include "jscntxt.h"
|
2008-08-06 13:36:29 -07:00
|
|
|
#include "jsgc.h"
|
|
|
|
#include "jsiter.h"
|
2008-07-30 15:51:44 -07:00
|
|
|
#include "jsmath.h"
|
2008-08-06 13:36:29 -07:00
|
|
|
#include "jsnum.h"
|
2008-08-08 14:38:44 -07:00
|
|
|
#include "jsscope.h"
|
2008-07-29 07:32:18 -07:00
|
|
|
#include "jsstr.h"
|
2008-07-10 05:40:43 -07:00
|
|
|
#include "jstracer.h"
|
2008-07-05 17:29:55 -07:00
|
|
|
|
2008-08-06 13:36:29 -07:00
|
|
|
#include "nanojit/avmplus.h"
|
|
|
|
#include "nanojit/nanojit.h"
|
|
|
|
|
2008-08-06 15:56:31 -07:00
|
|
|
using namespace avmplus;
|
2008-07-08 23:48:06 -07:00
|
|
|
using namespace nanojit;
|
|
|
|
|
2008-08-10 00:39:18 -07:00
|
|
|
jsdouble FASTCALL
|
|
|
|
js_dmod(jsdouble a, jsdouble b)
|
2008-07-05 17:29:55 -07:00
|
|
|
{
|
|
|
|
if (b == 0.0) {
|
|
|
|
jsdpun u;
|
|
|
|
u.s.hi = JSDOUBLE_HI32_EXPMASK | JSDOUBLE_HI32_MANTMASK;
|
|
|
|
u.s.lo = 0xffffffff;
|
|
|
|
return u.d;
|
|
|
|
}
|
|
|
|
jsdouble r;
|
|
|
|
#ifdef XP_WIN
|
|
|
|
/* Workaround MS fmod bug where 42 % (1/0) => NaN, not 42. */
|
2008-07-31 13:42:03 -07:00
|
|
|
if (JSDOUBLE_IS_FINITE(a) && JSDOUBLE_IS_INFINITE(b))
|
2008-07-05 17:29:55 -07:00
|
|
|
r = a;
|
|
|
|
else
|
|
|
|
#endif
|
|
|
|
r = fmod(a, b);
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* The following boxing/unboxing primitives we can't emit inline because
|
|
|
|
they either interact with the GC and depend on Spidermonkey's 32-bit
|
|
|
|
integer representation. */
|
|
|
|
|
2008-08-10 00:39:18 -07:00
|
|
|
jsval FASTCALL
|
|
|
|
js_BoxDouble(JSContext* cx, jsdouble d)
|
2008-07-05 17:29:55 -07:00
|
|
|
{
|
2008-07-06 15:55:04 -07:00
|
|
|
jsint i;
|
|
|
|
if (JSDOUBLE_IS_INT(d, i))
|
|
|
|
return INT_TO_JSVAL(i);
|
2008-07-05 17:29:55 -07:00
|
|
|
if (!cx->doubleFreeList) /* we must be certain the GC won't kick in */
|
|
|
|
return JSVAL_ERROR_COOKIE;
|
|
|
|
jsval v; /* not rooted but ok here because we know GC won't run */
|
|
|
|
if (!js_NewDoubleInRootedValue(cx, d, &v))
|
|
|
|
return JSVAL_ERROR_COOKIE;
|
|
|
|
return v;
|
|
|
|
}
|
|
|
|
|
2008-08-10 00:39:18 -07:00
|
|
|
jsval FASTCALL
|
|
|
|
js_BoxInt32(JSContext* cx, jsint i)
|
2008-07-05 17:29:55 -07:00
|
|
|
{
|
|
|
|
if (JS_LIKELY(INT_FITS_IN_JSVAL(i)))
|
|
|
|
return INT_TO_JSVAL(i);
|
2008-07-06 15:55:04 -07:00
|
|
|
if (!cx->doubleFreeList) /* we must be certain the GC won't kick in */
|
|
|
|
return JSVAL_ERROR_COOKIE;
|
|
|
|
jsval v; /* not rooted but ok here because we know GC won't run */
|
|
|
|
jsdouble d = (jsdouble)i;
|
|
|
|
if (!js_NewDoubleInRootedValue(cx, d, &v))
|
|
|
|
return JSVAL_ERROR_COOKIE;
|
|
|
|
return v;
|
2008-07-05 17:29:55 -07:00
|
|
|
}
|
|
|
|
|
2008-08-10 00:39:18 -07:00
|
|
|
jsdouble FASTCALL
|
|
|
|
js_UnboxDouble(jsval v)
|
2008-07-06 15:55:04 -07:00
|
|
|
{
|
|
|
|
if (JS_LIKELY(JSVAL_IS_INT(v)))
|
|
|
|
return (jsdouble)JSVAL_TO_INT(v);
|
|
|
|
return *JSVAL_TO_DOUBLE(v);
|
|
|
|
}
|
|
|
|
|
2008-08-10 00:39:18 -07:00
|
|
|
jsint FASTCALL
|
|
|
|
js_UnboxInt32(jsval v)
|
2008-07-05 17:29:55 -07:00
|
|
|
{
|
|
|
|
if (JS_LIKELY(JSVAL_IS_INT(v)))
|
|
|
|
return JSVAL_TO_INT(v);
|
2008-07-27 14:55:26 -07:00
|
|
|
return js_DoubleToECMAInt32(*JSVAL_TO_DOUBLE(v));
|
2008-07-05 17:29:55 -07:00
|
|
|
}
|
2008-07-05 22:04:58 -07:00
|
|
|
|
2008-08-10 00:39:18 -07:00
|
|
|
int32 FASTCALL
|
|
|
|
js_DoubleToInt32(jsdouble d)
|
2008-07-05 22:04:58 -07:00
|
|
|
{
|
|
|
|
return js_DoubleToECMAInt32(d);
|
|
|
|
}
|
2008-07-06 10:59:55 -07:00
|
|
|
|
2008-08-10 00:39:18 -07:00
|
|
|
int32 FASTCALL
|
|
|
|
js_DoubleToUint32(jsdouble d)
|
2008-07-06 10:59:55 -07:00
|
|
|
{
|
|
|
|
return js_DoubleToECMAUint32(d);
|
|
|
|
}
|
2008-07-08 23:48:06 -07:00
|
|
|
|
2008-08-10 00:39:18 -07:00
|
|
|
jsdouble FASTCALL
|
|
|
|
js_Math_sin(jsdouble d)
|
2008-07-11 19:59:09 -07:00
|
|
|
{
|
|
|
|
return sin(d);
|
|
|
|
}
|
|
|
|
|
2008-08-10 00:39:18 -07:00
|
|
|
jsdouble FASTCALL
|
|
|
|
js_Math_cos(jsdouble d)
|
2008-07-11 21:03:33 -07:00
|
|
|
{
|
|
|
|
return cos(d);
|
|
|
|
}
|
|
|
|
|
2008-08-10 00:39:18 -07:00
|
|
|
jsdouble FASTCALL
|
|
|
|
js_Math_floor(jsdouble d)
|
2008-08-09 18:47:52 -07:00
|
|
|
{
|
|
|
|
return floor(d);
|
|
|
|
}
|
|
|
|
|
2008-08-10 00:39:18 -07:00
|
|
|
jsdouble FASTCALL
|
|
|
|
js_Math_pow(jsdouble d, jsdouble p)
|
2008-07-11 21:03:33 -07:00
|
|
|
{
|
|
|
|
#ifdef NOTYET
|
2008-07-13 21:28:31 -07:00
|
|
|
/* XXX Need to get a NaN here without parameterizing on context all the time. */
|
2008-07-11 21:03:33 -07:00
|
|
|
if (!JSDOUBLE_IS_FINITE(p) && (d == 1.0 || d == -1.0))
|
|
|
|
return NaN;
|
|
|
|
#endif
|
|
|
|
if (p == 0)
|
|
|
|
return 1.0;
|
|
|
|
return pow(d, p);
|
|
|
|
}
|
|
|
|
|
2008-08-10 00:39:18 -07:00
|
|
|
jsdouble FASTCALL
|
|
|
|
js_Math_sqrt(jsdouble d)
|
2008-07-14 15:22:05 -07:00
|
|
|
{
|
|
|
|
return sqrt(d);
|
|
|
|
}
|
|
|
|
|
2008-08-10 00:39:18 -07:00
|
|
|
bool FASTCALL
|
|
|
|
js_Array_dense_setelem(JSContext* cx, JSObject* obj, jsint i, jsval v)
|
2008-07-27 15:34:23 -07:00
|
|
|
{
|
|
|
|
JS_ASSERT(OBJ_IS_DENSE_ARRAY(cx, obj));
|
|
|
|
|
|
|
|
jsuint length = ARRAY_DENSE_LENGTH(obj);
|
|
|
|
if ((jsuint)i < length) {
|
|
|
|
if (obj->dslots[i] == JSVAL_HOLE) {
|
|
|
|
if (i >= obj->fslots[JSSLOT_ARRAY_LENGTH])
|
|
|
|
obj->fslots[JSSLOT_ARRAY_LENGTH] = i + 1;
|
|
|
|
obj->fslots[JSSLOT_ARRAY_COUNT]++;
|
|
|
|
}
|
|
|
|
obj->dslots[i] = v;
|
|
|
|
return true;
|
|
|
|
}
|
2008-07-29 17:19:51 -07:00
|
|
|
return OBJ_SET_PROPERTY(cx, obj, INT_TO_JSID(i), &v) ? true : false;
|
2008-07-27 15:34:23 -07:00
|
|
|
}
|
|
|
|
|
2008-08-10 14:50:31 -07:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2008-07-29 07:32:18 -07:00
|
|
|
JSString* FASTCALL
|
2008-08-10 00:39:18 -07:00
|
|
|
js_String_p_substring(JSContext* cx, JSString* str, jsint begin, jsint end)
|
2008-07-29 07:32:18 -07:00
|
|
|
{
|
|
|
|
JS_ASSERT(end >= begin);
|
|
|
|
return js_NewDependentString(cx, str, (size_t)begin, (size_t)(end - begin));
|
|
|
|
}
|
|
|
|
|
|
|
|
JSString* FASTCALL
|
2008-08-10 00:39:18 -07:00
|
|
|
js_String_p_substring_1(JSContext* cx, JSString* str, jsint begin)
|
2008-07-29 07:32:18 -07:00
|
|
|
{
|
|
|
|
jsint end = JSSTRING_LENGTH(str);
|
|
|
|
JS_ASSERT(end >= begin);
|
|
|
|
return js_NewDependentString(cx, str, (size_t)begin, (size_t)(end - begin));
|
|
|
|
}
|
|
|
|
|
2008-07-29 07:53:31 -07:00
|
|
|
JSString* FASTCALL
|
2008-08-10 00:39:18 -07:00
|
|
|
js_FastConcatStrings(JSContext* cx, JSString* left, JSString* right)
|
2008-07-29 07:53:31 -07:00
|
|
|
{
|
2008-08-10 00:39:18 -07:00
|
|
|
return js_ConcatStrings(cx, left, right, GCF_DONT_BLOCK);
|
2008-07-29 07:53:31 -07:00
|
|
|
}
|
|
|
|
|
2008-07-30 15:19:25 -07:00
|
|
|
JSString* FASTCALL
|
2008-08-10 00:39:18 -07:00
|
|
|
js_String_getelem(JSContext* cx, JSString* str, jsint i)
|
2008-07-30 15:19:25 -07:00
|
|
|
{
|
|
|
|
if ((size_t)i >= JSSTRING_LENGTH(str))
|
|
|
|
return NULL;
|
|
|
|
/* XXX check for string freelist space */
|
2008-08-06 13:36:29 -07:00
|
|
|
return js_GetUnitString(cx, str, (size_t)i);
|
2008-07-30 15:19:25 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
JSString* FASTCALL
|
2008-08-10 00:39:18 -07:00
|
|
|
js_String_fromCharCode(JSContext* cx, jsint i)
|
2008-07-30 15:19:25 -07:00
|
|
|
{
|
|
|
|
jschar c = (jschar)i;
|
|
|
|
/* XXX check for string freelist space */
|
2008-07-31 12:22:48 -07:00
|
|
|
if (c < UNIT_STRING_LIMIT)
|
|
|
|
return js_GetUnitStringForChar(cx, c);
|
2008-07-30 15:19:25 -07:00
|
|
|
return js_NewStringCopyN(cx, &c, 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
jsint FASTCALL
|
2008-08-10 00:39:18 -07:00
|
|
|
js_String_p_charCodeAt(JSString* str, jsint i)
|
2008-07-30 15:19:25 -07:00
|
|
|
{
|
|
|
|
if (i < 0 || (jsint)JSSTRING_LENGTH(str) <= i)
|
|
|
|
return -1;
|
|
|
|
return JSSTRING_CHARS(str)[i];
|
|
|
|
}
|
|
|
|
|
2008-07-30 15:51:44 -07:00
|
|
|
jsdouble FASTCALL
|
2008-08-10 00:39:18 -07:00
|
|
|
js_Math_random(JSRuntime* rt)
|
2008-07-30 15:51:44 -07:00
|
|
|
{
|
|
|
|
JS_LOCK_RUNTIME(rt);
|
|
|
|
js_random_init(rt);
|
|
|
|
jsdouble z = js_random_nextDouble(rt);
|
|
|
|
JS_UNLOCK_RUNTIME(rt);
|
|
|
|
return z;
|
|
|
|
}
|
|
|
|
|
2008-08-09 19:15:21 -07:00
|
|
|
JSString* FASTCALL
|
2008-08-10 00:39:18 -07:00
|
|
|
js_String_p_concat_1int(JSContext* cx, JSString* str, jsint i)
|
2008-08-09 19:15:21 -07:00
|
|
|
{
|
2008-08-10 00:39:18 -07:00
|
|
|
// FIXME: should be able to use stack buffer and avoid istr...
|
2008-08-09 19:15:21 -07:00
|
|
|
JSString* istr = js_NumberToString(cx, i);
|
|
|
|
if (!istr)
|
|
|
|
return NULL;
|
2008-08-10 00:39:18 -07:00
|
|
|
return js_ConcatStrings(cx, str, istr, GCF_DONT_BLOCK);
|
2008-08-09 18:50:52 -07:00
|
|
|
}
|
|
|
|
|
2008-07-31 07:41:58 -07:00
|
|
|
jsdouble FASTCALL
|
2008-08-10 00:39:18 -07:00
|
|
|
js_StringToNumber(JSContext* cx, JSString* str)
|
2008-07-31 07:41:58 -07:00
|
|
|
{
|
|
|
|
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) ||
|
|
|
|
js_SkipWhiteSpace(ep, end) != end) &&
|
|
|
|
(!js_strtointeger(cx, bp, end, &ep, 0, &d) ||
|
|
|
|
js_SkipWhiteSpace(ep, end) != end)) {
|
|
|
|
return *cx->runtime->jsNaN;
|
|
|
|
}
|
|
|
|
return d;
|
|
|
|
}
|
|
|
|
|
2008-07-31 11:35:08 -07:00
|
|
|
jsint FASTCALL
|
2008-08-10 00:39:18 -07:00
|
|
|
js_StringToInt32(JSContext* cx, JSString* str)
|
2008-07-31 11:35:08 -07:00
|
|
|
{
|
|
|
|
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) || js_SkipWhiteSpace(ep, end) != end)
|
|
|
|
return 0;
|
|
|
|
return (jsint)d;
|
|
|
|
}
|
|
|
|
|
2008-08-06 13:36:29 -07:00
|
|
|
jsval FASTCALL
|
2008-08-10 00:39:18 -07:00
|
|
|
js_Any_getelem(JSContext* cx, JSObject* obj, JSString* idstr)
|
2008-08-06 13:36:29 -07:00
|
|
|
{
|
|
|
|
jsval v;
|
|
|
|
if (!OBJ_GET_PROPERTY(cx, obj, ATOM_TO_JSID(STRING_TO_JSVAL(idstr)), &v))
|
|
|
|
return JSVAL_ERROR_COOKIE;
|
|
|
|
return v;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool FASTCALL
|
2008-08-10 00:39:18 -07:00
|
|
|
js_Any_setelem(JSContext* cx, JSObject* obj, JSString* idstr, jsval v)
|
2008-08-06 13:36:29 -07:00
|
|
|
{
|
|
|
|
return OBJ_SET_PROPERTY(cx, obj, ATOM_TO_JSID(STRING_TO_JSVAL(idstr)), &v);
|
|
|
|
}
|
|
|
|
|
|
|
|
JSObject* FASTCALL
|
2008-08-10 00:39:18 -07:00
|
|
|
js_ValueToEnumerator(JSContext* cx, jsval v)
|
2008-08-06 13:36:29 -07:00
|
|
|
{
|
|
|
|
if (!js_ValueToIterator(cx, JSITER_ENUMERATE, &v))
|
|
|
|
return NULL;
|
|
|
|
return JSVAL_TO_OBJECT(v);
|
|
|
|
}
|
|
|
|
|
2008-08-06 15:56:31 -07:00
|
|
|
GuardRecord* FASTCALL
|
2008-08-10 00:39:18 -07:00
|
|
|
js_CallTree(InterpState* state, Fragment* f)
|
2008-08-06 15:56:31 -07:00
|
|
|
{
|
2008-08-07 19:59:21 -07:00
|
|
|
/* current we can't deal with inner trees that have globals so report an error */
|
2008-08-08 15:26:31 -07:00
|
|
|
JS_ASSERT(!((TreeInfo*)f->vmprivate)->globalSlots.length());
|
2008-08-06 15:56:31 -07:00
|
|
|
union { NIns *code; GuardRecord* (FASTCALL *func)(InterpState*, Fragment*); } u;
|
|
|
|
u.code = f->code();
|
2008-08-08 15:26:31 -07:00
|
|
|
return u.func(state, NULL);
|
2008-08-06 15:56:31 -07:00
|
|
|
}
|
|
|
|
|
2008-08-11 10:24:47 -07:00
|
|
|
JS_STATIC_ASSERT(JSSLOT_PRIVATE == JSSLOT_ARRAY_LENGTH);
|
|
|
|
JS_STATIC_ASSERT(JSSLOT_ARRAY_LENGTH + 1 == JSSLOT_ARRAY_COUNT);
|
|
|
|
|
2008-08-08 14:38:44 -07:00
|
|
|
JSObject* FASTCALL
|
2008-08-10 00:39:18 -07:00
|
|
|
js_FastNewObject(JSContext* cx, JSObject* ctor)
|
2008-08-08 14:38:44 -07:00
|
|
|
{
|
|
|
|
JS_ASSERT(HAS_FUNCTION_CLASS(ctor));
|
2008-08-11 10:24:47 -07:00
|
|
|
JSFunction* fun = GET_FUNCTION_PRIVATE(cx, ctor);
|
2008-08-11 10:41:08 -07:00
|
|
|
JSClass* clasp = FUN_INTERPRETED(fun) ? &js_ObjectClass : fun->u.n.clasp;
|
2008-08-08 14:38:44 -07:00
|
|
|
|
|
|
|
JSObject* obj = (JSObject*) js_NewGCThing(cx, GCF_DONT_BLOCK | GCX_OBJECT, sizeof(JSObject));
|
|
|
|
if (!obj)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
JS_LOCK_OBJ(cx, ctor);
|
|
|
|
JSScope *scope = OBJ_SCOPE(ctor);
|
|
|
|
JS_ASSERT(scope->object == ctor);
|
|
|
|
JSAtom* atom = cx->runtime->atomState.classPrototypeAtom;
|
|
|
|
|
|
|
|
JSScopeProperty *sprop = SCOPE_GET_PROPERTY(scope, ATOM_TO_JSID(atom));
|
|
|
|
JS_ASSERT(SPROP_HAS_VALID_SLOT(sprop, scope));
|
|
|
|
jsval v = LOCKED_OBJ_GET_SLOT(ctor, sprop->slot);
|
|
|
|
JS_UNLOCK_SCOPE(cx, scope);
|
|
|
|
|
|
|
|
JS_ASSERT(!JSVAL_IS_PRIMITIVE(v));
|
|
|
|
JSObject* proto = JSVAL_TO_OBJECT(v);
|
|
|
|
|
|
|
|
obj->fslots[JSSLOT_PROTO] = OBJECT_TO_JSVAL(proto);
|
|
|
|
obj->fslots[JSSLOT_PARENT] = ctor->fslots[JSSLOT_PARENT];
|
2008-08-11 10:24:47 -07:00
|
|
|
obj->fslots[JSSLOT_CLASS] = PRIVATE_TO_JSVAL(clasp);
|
|
|
|
|
|
|
|
unsigned i = JSSLOT_PRIVATE;
|
|
|
|
if (clasp == &js_ArrayClass) {
|
|
|
|
obj->fslots[JSSLOT_ARRAY_LENGTH] = 0;
|
|
|
|
obj->fslots[JSSLOT_ARRAY_COUNT] = 0;
|
|
|
|
i += 2;
|
|
|
|
}
|
|
|
|
for (; i != JS_INITIAL_NSLOTS; ++i)
|
2008-08-08 14:38:44 -07:00
|
|
|
obj->fslots[i] = JSVAL_VOID;
|
|
|
|
|
|
|
|
obj->map = js_HoldObjectMap(cx, proto->map);
|
|
|
|
obj->dslots = NULL;
|
|
|
|
return obj;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool FASTCALL
|
2008-08-10 00:39:18 -07:00
|
|
|
js_AddProperty(JSContext* cx, JSObject* obj, JSScopeProperty* sprop)
|
2008-08-08 14:38:44 -07:00
|
|
|
{
|
|
|
|
JS_ASSERT(OBJ_IS_NATIVE(obj));
|
|
|
|
JS_ASSERT(SPROP_HAS_STUB_SETTER(sprop));
|
|
|
|
|
|
|
|
JS_LOCK_OBJ(cx, obj);
|
|
|
|
JSScope* scope = OBJ_SCOPE(obj);
|
|
|
|
if (scope->object == obj) {
|
|
|
|
JS_ASSERT(!SCOPE_HAS_PROPERTY(scope, sprop));
|
|
|
|
} else {
|
|
|
|
scope = js_GetMutableScope(cx, obj);
|
|
|
|
if (!scope) {
|
|
|
|
JS_UNLOCK_OBJ(cx, obj);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
uint32 slot = sprop->slot;
|
|
|
|
if (!scope->table && sprop->parent == scope->lastProp && slot == scope->map.freeslot) {
|
|
|
|
if (slot < STOBJ_NSLOTS(obj) && !OBJ_GET_CLASS(cx, obj)->reserveSlots) {
|
|
|
|
++scope->map.freeslot;
|
|
|
|
} else {
|
|
|
|
if (!js_AllocSlot(cx, obj, &slot)) {
|
|
|
|
JS_UNLOCK_SCOPE(cx, scope);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (slot != sprop->slot)
|
|
|
|
goto slot_changed;
|
|
|
|
}
|
|
|
|
|
|
|
|
SCOPE_EXTEND_SHAPE(cx, scope, sprop);
|
|
|
|
++scope->entryCount;
|
|
|
|
scope->lastProp = sprop;
|
|
|
|
JS_UNLOCK_SCOPE(cx, scope);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
JSScopeProperty* sprop2 = js_AddScopeProperty(cx, scope, sprop->id,
|
|
|
|
sprop->getter, sprop->setter, SPROP_INVALID_SLOT,
|
|
|
|
sprop->attrs, sprop->flags, sprop->shortid);
|
|
|
|
if (sprop2 == sprop) {
|
|
|
|
JS_UNLOCK_SCOPE(cx, scope);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
slot = sprop2->slot;
|
|
|
|
|
|
|
|
slot_changed:
|
|
|
|
js_FreeSlot(cx, obj, slot);
|
|
|
|
JS_UNLOCK_SCOPE(cx, scope);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2008-08-09 19:54:01 -07:00
|
|
|
JSString* FASTCALL
|
2008-08-10 00:39:18 -07:00
|
|
|
js_TypeOfObject(JSContext* cx, JSObject* obj)
|
2008-08-09 19:54:01 -07:00
|
|
|
{
|
|
|
|
JSType type = JS_TypeOfValue(cx, OBJECT_TO_JSVAL(obj));
|
|
|
|
return ATOM_TO_STRING(cx->runtime->atomState.typeAtoms[type]);
|
|
|
|
}
|
|
|
|
|
|
|
|
JSString* FASTCALL
|
2008-08-10 00:39:18 -07:00
|
|
|
js_TypeOfBoolean(JSContext* cx, jsint unboxed)
|
2008-08-09 19:54:01 -07:00
|
|
|
{
|
|
|
|
jsval boxed = BOOLEAN_TO_JSVAL(unboxed);
|
|
|
|
JS_ASSERT(JSVAL_IS_VOID(boxed) || JSVAL_IS_BOOLEAN(boxed));
|
|
|
|
JSType type = JS_TypeOfValue(cx, boxed);
|
|
|
|
return ATOM_TO_STRING(cx->runtime->atomState.typeAtoms[type]);
|
|
|
|
}
|
|
|
|
|
2008-07-08 23:48:06 -07:00
|
|
|
#define LO ARGSIZE_LO
|
|
|
|
#define F ARGSIZE_F
|
|
|
|
#define Q ARGSIZE_Q
|
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
#define NAME(op) ,#op
|
|
|
|
#else
|
|
|
|
#define NAME(op)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#define BUILTIN1(op, at0, atr, tr, t0, cse, fold) \
|
2008-08-10 00:39:18 -07:00
|
|
|
{ (intptr_t)&js_##op, (at0 << 2) | atr, cse, fold NAME(op) },
|
2008-07-08 23:48:06 -07:00
|
|
|
#define BUILTIN2(op, at0, at1, atr, tr, t0, t1, cse, fold) \
|
2008-08-10 00:39:18 -07:00
|
|
|
{ (intptr_t)&js_##op, (at0 << 4) | (at1 << 2) | atr, cse, fold NAME(op) },
|
2008-07-08 23:48:06 -07:00
|
|
|
#define BUILTIN3(op, at0, at1, at2, atr, tr, t0, t1, t2, cse, fold) \
|
2008-08-10 00:39:18 -07:00
|
|
|
{ (intptr_t)&js_##op, (at0 << 6) | (at1 << 4) | (at2 << 2) | atr, cse, fold NAME(op) },
|
2008-07-27 15:34:23 -07:00
|
|
|
#define BUILTIN4(op, at0, at1, at2, at3, atr, tr, t0, t1, t2, t3, cse, fold) \
|
2008-08-10 00:39:18 -07:00
|
|
|
{ (intptr_t)&js_##op, (at0 << 8) | (at1 << 6) | (at2 << 4) | (at3 << 2) | atr, cse, fold NAME(op) },
|
2008-07-08 23:48:06 -07:00
|
|
|
|
|
|
|
struct CallInfo builtins[] = {
|
|
|
|
#include "builtins.tbl"
|
|
|
|
};
|