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-09-08 20:06:58 -07:00
|
|
|
#include "jslibmath.h"
|
2008-07-30 15:51:44 -07:00
|
|
|
#include "jsmath.h"
|
2008-08-06 13:36:29 -07:00
|
|
|
#include "jsnum.h"
|
2008-09-26 11:37:50 -07:00
|
|
|
#include "prmjtime.h"
|
2008-10-06 17:28:22 -07:00
|
|
|
#include "jsdate.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-09-02 15:37:22 -07:00
|
|
|
/*
|
|
|
|
* NB: bool FASTCALL is not compatible with Nanojit's calling convention usage.
|
|
|
|
* Do not use bool FASTCALL, use JSBool only!
|
|
|
|
*/
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2008-09-15 19:59:06 -07:00
|
|
|
jsint FASTCALL
|
|
|
|
js_imod(jsint a, jsint b)
|
|
|
|
{
|
2008-09-24 23:28:56 -07:00
|
|
|
if (a < 0 || b <= 0)
|
|
|
|
return -1;
|
|
|
|
int r = a % b;
|
|
|
|
return r;
|
2008-09-15 19:59:06 -07:00
|
|
|
}
|
|
|
|
|
2008-07-05 17:29:55 -07:00
|
|
|
/* 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-09-03 00:38:24 -07:00
|
|
|
JS_ASSERT(JS_ON_TRACE(cx));
|
2008-07-05 17:29:55 -07:00
|
|
|
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-09-03 00:38:24 -07:00
|
|
|
JS_ASSERT(JS_ON_TRACE(cx));
|
2008-07-06 15:55:04 -07:00
|
|
|
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-25 16:54:02 -07:00
|
|
|
jsdouble FASTCALL
|
|
|
|
js_Math_ceil(jsdouble d)
|
|
|
|
{
|
|
|
|
return ceil(d);
|
|
|
|
}
|
|
|
|
|
2008-09-04 22:30:04 -07:00
|
|
|
extern jsdouble js_NaN;
|
|
|
|
|
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
|
|
|
{
|
|
|
|
if (!JSDOUBLE_IS_FINITE(p) && (d == 1.0 || d == -1.0))
|
2008-09-04 22:30:04 -07:00
|
|
|
return js_NaN;
|
2008-07-11 21:03:33 -07:00
|
|
|
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-09-05 14:25:01 -07:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2008-09-08 20:06:58 -07:00
|
|
|
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;
|
2008-10-03 14:07:33 -07:00
|
|
|
/*
|
|
|
|
* 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;
|
2008-09-08 20:06:58 -07:00
|
|
|
}
|
|
|
|
|
2008-09-02 15:37:22 -07:00
|
|
|
JSBool FASTCALL
|
2008-08-10 00:39:18 -07:00
|
|
|
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));
|
|
|
|
|
2008-10-06 22:30:36 -07:00
|
|
|
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;
|
2008-07-27 15:34:23 -07:00
|
|
|
}
|
2008-10-06 22:30:36 -07:00
|
|
|
} while (0);
|
2008-09-02 15:37:22 -07:00
|
|
|
return OBJ_SET_PROPERTY(cx, obj, INT_TO_JSID(i), &v);
|
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-09-16 17:07:59 -07:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
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);
|
2008-09-03 00:38:24 -07:00
|
|
|
JS_ASSERT(JS_ON_TRACE(cx));
|
2008-07-29 07:32:18 -07:00
|
|
|
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);
|
2008-09-03 00:38:24 -07:00
|
|
|
JS_ASSERT(JS_ON_TRACE(cx));
|
2008-07-29 07:32:18 -07:00
|
|
|
return js_NewDependentString(cx, str, (size_t)begin, (size_t)(end - begin));
|
|
|
|
}
|
|
|
|
|
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;
|
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
|
|
|
{
|
2008-09-03 00:38:24 -07:00
|
|
|
JS_ASSERT(JS_ON_TRACE(cx));
|
2008-07-30 15:19:25 -07:00
|
|
|
jschar c = (jschar)i;
|
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-11 11:03:54 -07:00
|
|
|
return js_ConcatStrings(cx, str, istr);
|
2008-08-09 18:50:52 -07:00
|
|
|
}
|
|
|
|
|
2008-09-15 14:30:05 -07:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2008-08-12 18:52:28 -07:00
|
|
|
JSObject* FASTCALL
|
2008-08-15 09:29:03 -07:00
|
|
|
js_String_p_match(JSContext* cx, JSString* str, jsbytecode *pc, JSObject* regexp)
|
2008-08-12 18:52:28 -07:00
|
|
|
{
|
2008-08-15 09:29:03 -07:00
|
|
|
jsval vp[3] = { JSVAL_NULL, STRING_TO_JSVAL(str), OBJECT_TO_JSVAL(regexp) };
|
|
|
|
if (!js_StringMatchHelper(cx, 1, vp, pc))
|
2008-08-12 18:52:28 -07:00
|
|
|
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]);
|
|
|
|
}
|
|
|
|
|
2008-09-23 17:18:40 -07:00
|
|
|
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]);
|
|
|
|
}
|
|
|
|
|
2008-08-12 18:52:28 -07:00
|
|
|
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]);
|
|
|
|
}
|
|
|
|
|
2008-08-29 17:35:00 -07:00
|
|
|
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]);
|
|
|
|
}
|
|
|
|
|
2008-08-12 18:52:28 -07:00
|
|
|
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]);
|
|
|
|
}
|
|
|
|
|
2008-08-21 11:06:42 -07:00
|
|
|
JSObject* FASTCALL
|
2008-08-21 04:13:07 -07:00
|
|
|
js_String_p_split(JSContext* cx, JSString* str, JSString* sepstr)
|
|
|
|
{
|
|
|
|
// FIXME: optimize by calling into a lower level exported from jsstr.cpp.
|
2008-08-21 15:17:47 -07:00
|
|
|
jsval vp[4] = { JSVAL_NULL, STRING_TO_JSVAL(str), STRING_TO_JSVAL(sepstr), JSVAL_VOID };
|
2008-08-21 04:13:07 -07:00
|
|
|
if (!js_str_split(cx, 2, vp))
|
|
|
|
return NULL;
|
2008-08-21 11:06:42 -07:00
|
|
|
JS_ASSERT(JSVAL_IS_OBJECT(vp[0]));
|
|
|
|
return JSVAL_TO_OBJECT(vp[0]);
|
2008-08-21 04:13:07 -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)) {
|
2008-09-04 22:30:04 -07:00
|
|
|
return js_NaN;
|
2008-07-31 07:41:58 -07:00
|
|
|
}
|
|
|
|
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-14 15:13:39 -07:00
|
|
|
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)
|
2008-09-04 22:30:04 -07:00
|
|
|
return js_NaN;
|
2008-08-14 15:13:39 -07:00
|
|
|
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)
|
2008-09-04 22:30:04 -07:00
|
|
|
return js_NaN;
|
2008-08-14 15:13:39 -07:00
|
|
|
return d;
|
|
|
|
}
|
|
|
|
|
2008-09-07 00:41:10 -07:00
|
|
|
jsdouble FASTCALL
|
|
|
|
js_ParseIntDouble(jsdouble d)
|
|
|
|
{
|
|
|
|
if (!JSDOUBLE_IS_FINITE(d))
|
|
|
|
return js_NaN;
|
|
|
|
return floor(d);
|
|
|
|
}
|
|
|
|
|
2008-08-06 13:36:29 -07:00
|
|
|
jsval FASTCALL
|
2008-09-15 00:54:28 -07:00
|
|
|
js_Any_getprop(JSContext* cx, JSObject* obj, JSString* idstr)
|
2008-08-06 13:36:29 -07:00
|
|
|
{
|
|
|
|
jsval v;
|
2008-08-14 17:31:39 -07:00
|
|
|
jsid id;
|
|
|
|
|
|
|
|
if (!js_ValueToStringId(cx, STRING_TO_JSVAL(idstr), &id))
|
2008-08-11 16:12:52 -07:00
|
|
|
return JSVAL_ERROR_COOKIE;
|
2008-08-14 17:31:39 -07:00
|
|
|
if (!OBJ_GET_PROPERTY(cx, obj, id, &v))
|
2008-08-06 13:36:29 -07:00
|
|
|
return JSVAL_ERROR_COOKIE;
|
|
|
|
return v;
|
|
|
|
}
|
|
|
|
|
2008-09-02 15:37:22 -07:00
|
|
|
JSBool FASTCALL
|
2008-09-15 00:54:28 -07:00
|
|
|
js_Any_setprop(JSContext* cx, JSObject* obj, JSString* idstr, jsval v)
|
2008-08-06 13:36:29 -07:00
|
|
|
{
|
2008-08-14 17:31:39 -07:00
|
|
|
jsid id;
|
|
|
|
if (!js_ValueToStringId(cx, STRING_TO_JSVAL(idstr), &id))
|
2008-09-02 15:37:22 -07:00
|
|
|
return JS_FALSE;
|
2008-08-14 17:31:39 -07:00
|
|
|
return OBJ_SET_PROPERTY(cx, obj, id, &v);
|
2008-08-06 13:36:29 -07:00
|
|
|
}
|
|
|
|
|
2008-09-15 00:54:28 -07:00
|
|
|
jsval FASTCALL
|
2008-09-25 11:31:40 -07:00
|
|
|
js_Any_getelem(JSContext* cx, JSObject* obj, jsint index)
|
2008-09-15 15:00:40 -07:00
|
|
|
{
|
|
|
|
jsval v;
|
|
|
|
jsid id;
|
2008-09-25 11:31:40 -07:00
|
|
|
if (index < 0)
|
2008-09-15 15:00:40 -07:00
|
|
|
return JSVAL_ERROR_COOKIE;
|
2008-09-15 00:54:28 -07:00
|
|
|
if (!js_IndexToId(cx, index, &id))
|
|
|
|
return JSVAL_ERROR_COOKIE;
|
|
|
|
if (!OBJ_GET_PROPERTY(cx, obj, id, &v))
|
|
|
|
return JSVAL_ERROR_COOKIE;
|
|
|
|
return v;
|
|
|
|
}
|
|
|
|
|
|
|
|
JSBool FASTCALL
|
2008-09-25 11:31:40 -07:00
|
|
|
js_Any_setelem(JSContext* cx, JSObject* obj, jsint index, jsval v)
|
2008-09-15 00:54:28 -07:00
|
|
|
{
|
|
|
|
jsid id;
|
2008-09-25 11:31:40 -07:00
|
|
|
if (index < 0)
|
|
|
|
return JSVAL_ERROR_COOKIE;
|
2008-09-15 00:54:28 -07:00
|
|
|
if (!js_IndexToId(cx, index, &id))
|
|
|
|
return JS_FALSE;
|
|
|
|
return OBJ_SET_PROPERTY(cx, obj, id, &v);
|
|
|
|
}
|
|
|
|
|
2008-08-06 13:36:29 -07:00
|
|
|
JSObject* FASTCALL
|
2008-08-13 14:02:35 -07:00
|
|
|
js_FastValueToIterator(JSContext* cx, jsuint flags, jsval v)
|
2008-08-06 13:36:29 -07:00
|
|
|
{
|
2008-08-13 14:02:35 -07:00
|
|
|
if (!js_ValueToIterator(cx, flags, &v))
|
2008-08-06 13:36:29 -07:00
|
|
|
return NULL;
|
|
|
|
return JSVAL_TO_OBJECT(v);
|
|
|
|
}
|
|
|
|
|
2008-08-13 14:02:35 -07:00
|
|
|
jsval FASTCALL
|
|
|
|
js_FastCallIteratorNext(JSContext* cx, JSObject* iterobj)
|
|
|
|
{
|
|
|
|
jsval v;
|
|
|
|
if (!js_CallIteratorNext(cx, iterobj, &v))
|
|
|
|
return JSVAL_ERROR_COOKIE;
|
|
|
|
return 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-09-02 11:43:55 -07:00
|
|
|
GuardRecord* lr;
|
2008-08-06 15:56:31 -07:00
|
|
|
union { NIns *code; GuardRecord* (FASTCALL *func)(InterpState*, Fragment*); } u;
|
2008-09-02 11:43:55 -07:00
|
|
|
|
2008-08-06 15:56:31 -07:00
|
|
|
u.code = f->code();
|
2008-08-27 17:25:56 -07:00
|
|
|
JS_ASSERT(u.code);
|
2008-09-02 11:43:55 -07:00
|
|
|
|
|
|
|
#if defined(JS_NO_FASTCALL) && defined(NANOJIT_IA32)
|
|
|
|
SIMULATE_FASTCALL(lr, state, NULL, u.func);
|
|
|
|
#else
|
|
|
|
lr = u.func(state, NULL);
|
|
|
|
#endif
|
|
|
|
|
2008-09-19 18:45:57 -07:00
|
|
|
if (lr->exit->exitType == NESTED_EXIT) {
|
|
|
|
/* This only occurs once a tree call guard mismatches and we unwind the tree call stack.
|
|
|
|
We store the first (innermost) tree call guard in state and we will try to grow
|
|
|
|
the outer tree the failing call was in starting at that guard. */
|
|
|
|
if (!state->lastTreeCallGuard)
|
|
|
|
state->lastTreeCallGuard = lr;
|
|
|
|
} else {
|
|
|
|
/* If the tree exits on a regular (non-nested) guard, keep updating lastTreeExitGuard
|
|
|
|
with that guard. If we mismatch on a tree call guard, this will contain the last
|
|
|
|
non-nested guard we encountered, which is the innermost loop or branch guard. */
|
|
|
|
state->lastTreeExitGuard = lr;
|
|
|
|
}
|
|
|
|
|
2008-08-28 14:24:58 -07:00
|
|
|
return lr;
|
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);
|
|
|
|
|
Kind of an Array initialiser tour-de-force for bug 452878:
1. Split FastNewArray from FastNewObject built-in for greater speed/specialization and further splitting into Array_1str, etc.
2. Add Array_1str, Array_2obj, and Array_3num builtins for benchmarked new Array(...) constructions.
3. Export ARRAY_SET_DENSE_LENGTH and ARRAY_GROWBY via jsarray.h to jstracer.cpp.
4. Tweaked SetArrayElement to make common/best case code be the predicted/prefetched path.
5. js_MakeArraySlow now preserves the pre-slow length in JSSLOT_ARRAY_COUTN as a jsval-tagged int if possible -- this will help the tracer avoid aborting on dense arrays that turned slow but not sparse by addition of a named property.
6. Export js_fun_apply and js_Object from their respective .cpp files, in these cases just to jstracer.cpp via local prototypes (no .h files involved).
7. More INS_CONSTPTR and INS_CONST macrology for better names in trace debug spew.
8. Fix TraceRecorder::test_property_cache to avoid aborting on JSOP_SETNAME that creates a new global, by setting it to undefined so it can be lazily imported. This helps 3d-raytrace.js, which has an unintended global loop control variable in a function.
9. JSTraceableNative loses its premature-deadwood tclasp member (my bad).
10. TraceRecorder::record_JSOP_NEW() handles 'new Object' now along with the 'new Array' variations. I also cut down the copy-paste code from JSOP_CALL's record method to mostly what is needed now.
11. Add KNOWN_NATIVE_DECL macro for concise prototype of library-private js_* native functions, and alphabetized the lists (too long for any other order to be winning).
12. Big honking special case for foo.apply(obj, [str]), which we can generalize as needed. Helps string-tagcloud.js. What's cool is how tracing allows us to rewrite this to foo(str) with this set to obj, eliminating the Function.prototype.apply. This requires some rewriting in JSOP_ENDINIT's record method.
2008-09-01 01:24:58 -07:00
|
|
|
JSObject* FASTCALL
|
|
|
|
js_FastNewArray(JSContext* cx, JSObject* proto)
|
|
|
|
{
|
|
|
|
JS_ASSERT(OBJ_IS_ARRAY(cx, proto));
|
|
|
|
|
2008-09-03 00:38:24 -07:00
|
|
|
JS_ASSERT(JS_ON_TRACE(cx));
|
Kind of an Array initialiser tour-de-force for bug 452878:
1. Split FastNewArray from FastNewObject built-in for greater speed/specialization and further splitting into Array_1str, etc.
2. Add Array_1str, Array_2obj, and Array_3num builtins for benchmarked new Array(...) constructions.
3. Export ARRAY_SET_DENSE_LENGTH and ARRAY_GROWBY via jsarray.h to jstracer.cpp.
4. Tweaked SetArrayElement to make common/best case code be the predicted/prefetched path.
5. js_MakeArraySlow now preserves the pre-slow length in JSSLOT_ARRAY_COUTN as a jsval-tagged int if possible -- this will help the tracer avoid aborting on dense arrays that turned slow but not sparse by addition of a named property.
6. Export js_fun_apply and js_Object from their respective .cpp files, in these cases just to jstracer.cpp via local prototypes (no .h files involved).
7. More INS_CONSTPTR and INS_CONST macrology for better names in trace debug spew.
8. Fix TraceRecorder::test_property_cache to avoid aborting on JSOP_SETNAME that creates a new global, by setting it to undefined so it can be lazily imported. This helps 3d-raytrace.js, which has an unintended global loop control variable in a function.
9. JSTraceableNative loses its premature-deadwood tclasp member (my bad).
10. TraceRecorder::record_JSOP_NEW() handles 'new Object' now along with the 'new Array' variations. I also cut down the copy-paste code from JSOP_CALL's record method to mostly what is needed now.
11. Add KNOWN_NATIVE_DECL macro for concise prototype of library-private js_* native functions, and alphabetized the lists (too long for any other order to be winning).
12. Big honking special case for foo.apply(obj, [str]), which we can generalize as needed. Helps string-tagcloud.js. What's cool is how tracing allows us to rewrite this to foo(str) with this set to obj, eliminating the Function.prototype.apply. This requires some rewriting in JSOP_ENDINIT's record method.
2008-09-01 01:24:58 -07:00
|
|
|
JSObject* obj = (JSObject*) js_NewGCThing(cx, GCX_OBJECT, sizeof(JSObject));
|
|
|
|
if (!obj)
|
|
|
|
return NULL;
|
|
|
|
|
2008-09-09 09:57:10 -07:00
|
|
|
JSClass* clasp = &js_ArrayClass;
|
|
|
|
obj->classword = jsuword(clasp);
|
|
|
|
|
Kind of an Array initialiser tour-de-force for bug 452878:
1. Split FastNewArray from FastNewObject built-in for greater speed/specialization and further splitting into Array_1str, etc.
2. Add Array_1str, Array_2obj, and Array_3num builtins for benchmarked new Array(...) constructions.
3. Export ARRAY_SET_DENSE_LENGTH and ARRAY_GROWBY via jsarray.h to jstracer.cpp.
4. Tweaked SetArrayElement to make common/best case code be the predicted/prefetched path.
5. js_MakeArraySlow now preserves the pre-slow length in JSSLOT_ARRAY_COUTN as a jsval-tagged int if possible -- this will help the tracer avoid aborting on dense arrays that turned slow but not sparse by addition of a named property.
6. Export js_fun_apply and js_Object from their respective .cpp files, in these cases just to jstracer.cpp via local prototypes (no .h files involved).
7. More INS_CONSTPTR and INS_CONST macrology for better names in trace debug spew.
8. Fix TraceRecorder::test_property_cache to avoid aborting on JSOP_SETNAME that creates a new global, by setting it to undefined so it can be lazily imported. This helps 3d-raytrace.js, which has an unintended global loop control variable in a function.
9. JSTraceableNative loses its premature-deadwood tclasp member (my bad).
10. TraceRecorder::record_JSOP_NEW() handles 'new Object' now along with the 'new Array' variations. I also cut down the copy-paste code from JSOP_CALL's record method to mostly what is needed now.
11. Add KNOWN_NATIVE_DECL macro for concise prototype of library-private js_* native functions, and alphabetized the lists (too long for any other order to be winning).
12. Big honking special case for foo.apply(obj, [str]), which we can generalize as needed. Helps string-tagcloud.js. What's cool is how tracing allows us to rewrite this to foo(str) with this set to obj, eliminating the Function.prototype.apply. This requires some rewriting in JSOP_ENDINIT's record method.
2008-09-01 01:24:58 -07:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
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;
|
Kind of an Array initialiser tour-de-force for bug 452878:
1. Split FastNewArray from FastNewObject built-in for greater speed/specialization and further splitting into Array_1str, etc.
2. Add Array_1str, Array_2obj, and Array_3num builtins for benchmarked new Array(...) constructions.
3. Export ARRAY_SET_DENSE_LENGTH and ARRAY_GROWBY via jsarray.h to jstracer.cpp.
4. Tweaked SetArrayElement to make common/best case code be the predicted/prefetched path.
5. js_MakeArraySlow now preserves the pre-slow length in JSSLOT_ARRAY_COUTN as a jsval-tagged int if possible -- this will help the tracer avoid aborting on dense arrays that turned slow but not sparse by addition of a named property.
6. Export js_fun_apply and js_Object from their respective .cpp files, in these cases just to jstracer.cpp via local prototypes (no .h files involved).
7. More INS_CONSTPTR and INS_CONST macrology for better names in trace debug spew.
8. Fix TraceRecorder::test_property_cache to avoid aborting on JSOP_SETNAME that creates a new global, by setting it to undefined so it can be lazily imported. This helps 3d-raytrace.js, which has an unintended global loop control variable in a function.
9. JSTraceableNative loses its premature-deadwood tclasp member (my bad).
10. TraceRecorder::record_JSOP_NEW() handles 'new Object' now along with the 'new Array' variations. I also cut down the copy-paste code from JSOP_CALL's record method to mostly what is needed now.
11. Add KNOWN_NATIVE_DECL macro for concise prototype of library-private js_* native functions, and alphabetized the lists (too long for any other order to be winning).
12. Big honking special case for foo.apply(obj, [str]), which we can generalize as needed. Helps string-tagcloud.js. What's cool is how tracing allows us to rewrite this to foo(str) with this set to obj, eliminating the Function.prototype.apply. This requires some rewriting in JSOP_ENDINIT's record method.
2008-09-01 01:24:58 -07:00
|
|
|
JS_ASSERT(clasp != &js_ArrayClass);
|
2008-08-08 14:38:44 -07:00
|
|
|
|
|
|
|
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);
|
|
|
|
|
2008-09-16 18:49:27 -07:00
|
|
|
JSObject* proto;
|
|
|
|
if (JSVAL_IS_PRIMITIVE(v)) {
|
|
|
|
if (!js_GetClassPrototype(cx, JSVAL_TO_OBJECT(ctor->fslots[JSSLOT_PARENT]),
|
|
|
|
INT_TO_JSID(JSProto_Object), &proto)) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
proto = JSVAL_TO_OBJECT(v);
|
|
|
|
}
|
|
|
|
|
|
|
|
JS_ASSERT(JS_ON_TRACE(cx));
|
|
|
|
JSObject* obj = (JSObject*) js_NewGCThing(cx, GCX_OBJECT, sizeof(JSObject));
|
|
|
|
if (!obj)
|
|
|
|
return NULL;
|
2008-08-08 14:38:44 -07:00
|
|
|
|
2008-09-09 09:57:10 -07:00
|
|
|
obj->classword = jsuword(clasp);
|
2008-08-08 14:38:44 -07:00
|
|
|
obj->fslots[JSSLOT_PROTO] = OBJECT_TO_JSVAL(proto);
|
|
|
|
obj->fslots[JSSLOT_PARENT] = ctor->fslots[JSSLOT_PARENT];
|
Kind of an Array initialiser tour-de-force for bug 452878:
1. Split FastNewArray from FastNewObject built-in for greater speed/specialization and further splitting into Array_1str, etc.
2. Add Array_1str, Array_2obj, and Array_3num builtins for benchmarked new Array(...) constructions.
3. Export ARRAY_SET_DENSE_LENGTH and ARRAY_GROWBY via jsarray.h to jstracer.cpp.
4. Tweaked SetArrayElement to make common/best case code be the predicted/prefetched path.
5. js_MakeArraySlow now preserves the pre-slow length in JSSLOT_ARRAY_COUTN as a jsval-tagged int if possible -- this will help the tracer avoid aborting on dense arrays that turned slow but not sparse by addition of a named property.
6. Export js_fun_apply and js_Object from their respective .cpp files, in these cases just to jstracer.cpp via local prototypes (no .h files involved).
7. More INS_CONSTPTR and INS_CONST macrology for better names in trace debug spew.
8. Fix TraceRecorder::test_property_cache to avoid aborting on JSOP_SETNAME that creates a new global, by setting it to undefined so it can be lazily imported. This helps 3d-raytrace.js, which has an unintended global loop control variable in a function.
9. JSTraceableNative loses its premature-deadwood tclasp member (my bad).
10. TraceRecorder::record_JSOP_NEW() handles 'new Object' now along with the 'new Array' variations. I also cut down the copy-paste code from JSOP_CALL's record method to mostly what is needed now.
11. Add KNOWN_NATIVE_DECL macro for concise prototype of library-private js_* native functions, and alphabetized the lists (too long for any other order to be winning).
12. Big honking special case for foo.apply(obj, [str]), which we can generalize as needed. Helps string-tagcloud.js. What's cool is how tracing allows us to rewrite this to foo(str) with this set to obj, eliminating the Function.prototype.apply. This requires some rewriting in JSOP_ENDINIT's record method.
2008-09-01 01:24:58 -07:00
|
|
|
for (unsigned i = JSSLOT_PRIVATE; i != JS_INITIAL_NSLOTS; ++i)
|
2008-08-08 14:38:44 -07:00
|
|
|
obj->fslots[i] = JSVAL_VOID;
|
|
|
|
|
Kind of an Array initialiser tour-de-force for bug 452878:
1. Split FastNewArray from FastNewObject built-in for greater speed/specialization and further splitting into Array_1str, etc.
2. Add Array_1str, Array_2obj, and Array_3num builtins for benchmarked new Array(...) constructions.
3. Export ARRAY_SET_DENSE_LENGTH and ARRAY_GROWBY via jsarray.h to jstracer.cpp.
4. Tweaked SetArrayElement to make common/best case code be the predicted/prefetched path.
5. js_MakeArraySlow now preserves the pre-slow length in JSSLOT_ARRAY_COUTN as a jsval-tagged int if possible -- this will help the tracer avoid aborting on dense arrays that turned slow but not sparse by addition of a named property.
6. Export js_fun_apply and js_Object from their respective .cpp files, in these cases just to jstracer.cpp via local prototypes (no .h files involved).
7. More INS_CONSTPTR and INS_CONST macrology for better names in trace debug spew.
8. Fix TraceRecorder::test_property_cache to avoid aborting on JSOP_SETNAME that creates a new global, by setting it to undefined so it can be lazily imported. This helps 3d-raytrace.js, which has an unintended global loop control variable in a function.
9. JSTraceableNative loses its premature-deadwood tclasp member (my bad).
10. TraceRecorder::record_JSOP_NEW() handles 'new Object' now along with the 'new Array' variations. I also cut down the copy-paste code from JSOP_CALL's record method to mostly what is needed now.
11. Add KNOWN_NATIVE_DECL macro for concise prototype of library-private js_* native functions, and alphabetized the lists (too long for any other order to be winning).
12. Big honking special case for foo.apply(obj, [str]), which we can generalize as needed. Helps string-tagcloud.js. What's cool is how tracing allows us to rewrite this to foo(str) with this set to obj, eliminating the Function.prototype.apply. This requires some rewriting in JSOP_ENDINIT's record method.
2008-09-01 01:24:58 -07:00
|
|
|
obj->map = js_HoldObjectMap(cx, proto->map);
|
2008-08-08 14:38:44 -07:00
|
|
|
obj->dslots = NULL;
|
|
|
|
return obj;
|
|
|
|
}
|
|
|
|
|
2008-09-02 15:37:22 -07:00
|
|
|
JSBool 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
|
|
|
{
|
2008-08-11 11:43:40 -07:00
|
|
|
JSScopeProperty* sprop2 = NULL; // initialize early to make MSVC happy
|
|
|
|
|
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);
|
2008-09-02 15:37:22 -07:00
|
|
|
return JS_FALSE;
|
2008-08-08 14:38:44 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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) {
|
2008-09-11 15:53:00 -07:00
|
|
|
JS_ASSERT(JSVAL_IS_VOID(STOBJ_GET_SLOT(obj, scope->map.freeslot)));
|
2008-08-08 14:38:44 -07:00
|
|
|
++scope->map.freeslot;
|
|
|
|
} else {
|
|
|
|
if (!js_AllocSlot(cx, obj, &slot)) {
|
|
|
|
JS_UNLOCK_SCOPE(cx, scope);
|
2008-09-02 15:37:22 -07:00
|
|
|
return JS_FALSE;
|
2008-08-08 14:38:44 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
if (slot != sprop->slot)
|
|
|
|
goto slot_changed;
|
|
|
|
}
|
|
|
|
|
|
|
|
SCOPE_EXTEND_SHAPE(cx, scope, sprop);
|
|
|
|
++scope->entryCount;
|
|
|
|
scope->lastProp = sprop;
|
|
|
|
JS_UNLOCK_SCOPE(cx, scope);
|
2008-09-02 15:37:22 -07:00
|
|
|
return JS_TRUE;
|
2008-08-08 14:38:44 -07:00
|
|
|
}
|
|
|
|
|
2008-08-11 11:43:40 -07:00
|
|
|
sprop2 = js_AddScopeProperty(cx, scope, sprop->id,
|
|
|
|
sprop->getter, sprop->setter, SPROP_INVALID_SLOT,
|
|
|
|
sprop->attrs, sprop->flags, sprop->shortid);
|
2008-08-08 14:38:44 -07:00
|
|
|
if (sprop2 == sprop) {
|
|
|
|
JS_UNLOCK_SCOPE(cx, scope);
|
2008-09-02 15:37:22 -07:00
|
|
|
return JS_TRUE;
|
2008-08-08 14:38:44 -07:00
|
|
|
}
|
|
|
|
slot = sprop2->slot;
|
|
|
|
|
|
|
|
slot_changed:
|
|
|
|
js_FreeSlot(cx, obj, slot);
|
|
|
|
JS_UNLOCK_SCOPE(cx, scope);
|
2008-09-02 15:37:22 -07:00
|
|
|
return JS_FALSE;
|
2008-08-08 14:38:44 -07:00
|
|
|
}
|
|
|
|
|
2008-09-02 15:37:22 -07:00
|
|
|
JSBool FASTCALL
|
2008-08-27 23:00:43 -07:00
|
|
|
js_HasNamedProperty(JSContext* cx, JSObject* obj, JSString* idstr)
|
|
|
|
{
|
|
|
|
jsid id;
|
|
|
|
if (!js_ValueToStringId(cx, STRING_TO_JSVAL(idstr), &id))
|
2008-09-02 15:37:22 -07:00
|
|
|
return JS_FALSE;
|
2008-08-27 23:00:43 -07:00
|
|
|
|
|
|
|
JSObject* obj2;
|
|
|
|
JSProperty* prop;
|
|
|
|
if (!OBJ_LOOKUP_PROPERTY(cx, obj, id, &obj2, &prop))
|
|
|
|
return JSVAL_TO_BOOLEAN(JSVAL_VOID);
|
|
|
|
if (prop)
|
|
|
|
OBJ_DROP_PROPERTY(cx, obj2, prop);
|
|
|
|
return prop != NULL;
|
|
|
|
}
|
|
|
|
|
2008-08-12 18:52:28 -07:00
|
|
|
jsval FASTCALL
|
|
|
|
js_CallGetter(JSContext* cx, JSObject* obj, JSScopeProperty* sprop)
|
|
|
|
{
|
|
|
|
JS_ASSERT(!SPROP_HAS_STUB_GETTER(sprop));
|
|
|
|
jsval v;
|
|
|
|
if (!SPROP_GET(cx, sprop, obj, obj, &v))
|
|
|
|
return JSVAL_ERROR_COOKIE;
|
|
|
|
return v;
|
|
|
|
}
|
|
|
|
|
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-08-11 17:47:05 -07:00
|
|
|
jsint FASTCALL
|
|
|
|
js_Object_p_hasOwnProperty(JSContext* cx, JSObject* obj, JSString *str)
|
|
|
|
{
|
2008-08-13 17:20:16 -07:00
|
|
|
jsid id = ATOM_TO_JSID(STRING_TO_JSVAL(str));
|
2008-08-11 17:47:05 -07:00
|
|
|
jsval v;
|
2008-08-13 17:20:16 -07:00
|
|
|
if (!js_HasOwnProperty(cx, obj->map->ops->lookupProperty, obj, id, &v))
|
2008-08-12 14:28:15 -07:00
|
|
|
return JSVAL_TO_BOOLEAN(JSVAL_VOID);
|
2008-08-11 17:47:05 -07:00
|
|
|
JS_ASSERT(JSVAL_IS_BOOLEAN(v));
|
|
|
|
return JSVAL_TO_BOOLEAN(v);
|
|
|
|
}
|
|
|
|
|
|
|
|
jsint FASTCALL
|
|
|
|
js_Object_p_propertyIsEnumerable(JSContext* cx, JSObject* obj, JSString *str)
|
|
|
|
{
|
2008-08-13 17:20:16 -07:00
|
|
|
jsid id = ATOM_TO_JSID(STRING_TO_JSVAL(str));
|
2008-08-11 17:47:05 -07:00
|
|
|
jsval v;
|
2008-08-13 17:20:16 -07:00
|
|
|
if (!js_PropertyIsEnumerable(cx, obj, id, &v))
|
2008-08-13 17:44:26 -07:00
|
|
|
return JSVAL_TO_BOOLEAN(JSVAL_VOID);
|
2008-08-11 17:47:05 -07:00
|
|
|
JS_ASSERT(JSVAL_IS_BOOLEAN(v));
|
|
|
|
return JSVAL_TO_BOOLEAN(v);
|
|
|
|
}
|
|
|
|
|
2008-08-11 22:05:33 -07:00
|
|
|
jsdouble FASTCALL
|
|
|
|
js_BooleanToNumber(JSContext* cx, jsint unboxed)
|
|
|
|
{
|
|
|
|
if (unboxed == JSVAL_TO_BOOLEAN(JSVAL_VOID))
|
2008-09-04 22:30:04 -07:00
|
|
|
return js_NaN;
|
2008-08-11 22:05:33 -07:00
|
|
|
return unboxed;
|
|
|
|
}
|
|
|
|
|
2008-08-20 02:35:17 -07:00
|
|
|
JSString* FASTCALL
|
|
|
|
js_ObjectToString(JSContext* cx, JSObject* obj)
|
|
|
|
{
|
|
|
|
if (!obj)
|
|
|
|
return ATOM_TO_STRING(cx->runtime->atomState.nullAtom);
|
|
|
|
jsval v;
|
|
|
|
if (!OBJ_DEFAULT_VALUE(cx, obj, JSTYPE_STRING, &v))
|
|
|
|
return NULL;
|
|
|
|
JS_ASSERT(JSVAL_IS_STRING(v));
|
|
|
|
return JSVAL_TO_STRING(v);
|
|
|
|
}
|
|
|
|
|
2008-08-21 00:50:20 -07:00
|
|
|
JSObject* FASTCALL
|
Kind of an Array initialiser tour-de-force for bug 452878:
1. Split FastNewArray from FastNewObject built-in for greater speed/specialization and further splitting into Array_1str, etc.
2. Add Array_1str, Array_2obj, and Array_3num builtins for benchmarked new Array(...) constructions.
3. Export ARRAY_SET_DENSE_LENGTH and ARRAY_GROWBY via jsarray.h to jstracer.cpp.
4. Tweaked SetArrayElement to make common/best case code be the predicted/prefetched path.
5. js_MakeArraySlow now preserves the pre-slow length in JSSLOT_ARRAY_COUTN as a jsval-tagged int if possible -- this will help the tracer avoid aborting on dense arrays that turned slow but not sparse by addition of a named property.
6. Export js_fun_apply and js_Object from their respective .cpp files, in these cases just to jstracer.cpp via local prototypes (no .h files involved).
7. More INS_CONSTPTR and INS_CONST macrology for better names in trace debug spew.
8. Fix TraceRecorder::test_property_cache to avoid aborting on JSOP_SETNAME that creates a new global, by setting it to undefined so it can be lazily imported. This helps 3d-raytrace.js, which has an unintended global loop control variable in a function.
9. JSTraceableNative loses its premature-deadwood tclasp member (my bad).
10. TraceRecorder::record_JSOP_NEW() handles 'new Object' now along with the 'new Array' variations. I also cut down the copy-paste code from JSOP_CALL's record method to mostly what is needed now.
11. Add KNOWN_NATIVE_DECL macro for concise prototype of library-private js_* native functions, and alphabetized the lists (too long for any other order to be winning).
12. Big honking special case for foo.apply(obj, [str]), which we can generalize as needed. Helps string-tagcloud.js. What's cool is how tracing allows us to rewrite this to foo(str) with this set to obj, eliminating the Function.prototype.apply. This requires some rewriting in JSOP_ENDINIT's record method.
2008-09-01 01:24:58 -07:00
|
|
|
js_Array_1int(JSContext* cx, JSObject* proto, jsint i)
|
2008-08-21 00:50:20 -07:00
|
|
|
{
|
2008-09-03 00:38:24 -07:00
|
|
|
JS_ASSERT(JS_ON_TRACE(cx));
|
Kind of an Array initialiser tour-de-force for bug 452878:
1. Split FastNewArray from FastNewObject built-in for greater speed/specialization and further splitting into Array_1str, etc.
2. Add Array_1str, Array_2obj, and Array_3num builtins for benchmarked new Array(...) constructions.
3. Export ARRAY_SET_DENSE_LENGTH and ARRAY_GROWBY via jsarray.h to jstracer.cpp.
4. Tweaked SetArrayElement to make common/best case code be the predicted/prefetched path.
5. js_MakeArraySlow now preserves the pre-slow length in JSSLOT_ARRAY_COUTN as a jsval-tagged int if possible -- this will help the tracer avoid aborting on dense arrays that turned slow but not sparse by addition of a named property.
6. Export js_fun_apply and js_Object from their respective .cpp files, in these cases just to jstracer.cpp via local prototypes (no .h files involved).
7. More INS_CONSTPTR and INS_CONST macrology for better names in trace debug spew.
8. Fix TraceRecorder::test_property_cache to avoid aborting on JSOP_SETNAME that creates a new global, by setting it to undefined so it can be lazily imported. This helps 3d-raytrace.js, which has an unintended global loop control variable in a function.
9. JSTraceableNative loses its premature-deadwood tclasp member (my bad).
10. TraceRecorder::record_JSOP_NEW() handles 'new Object' now along with the 'new Array' variations. I also cut down the copy-paste code from JSOP_CALL's record method to mostly what is needed now.
11. Add KNOWN_NATIVE_DECL macro for concise prototype of library-private js_* native functions, and alphabetized the lists (too long for any other order to be winning).
12. Big honking special case for foo.apply(obj, [str]), which we can generalize as needed. Helps string-tagcloud.js. What's cool is how tracing allows us to rewrite this to foo(str) with this set to obj, eliminating the Function.prototype.apply. This requires some rewriting in JSOP_ENDINIT's record method.
2008-09-01 01:24:58 -07:00
|
|
|
JSObject* obj = js_FastNewArray(cx, proto);
|
2008-08-21 00:50:20 -07:00
|
|
|
if (obj)
|
|
|
|
obj->fslots[JSSLOT_ARRAY_LENGTH] = i;
|
|
|
|
return obj;
|
|
|
|
}
|
|
|
|
|
Kind of an Array initialiser tour-de-force for bug 452878:
1. Split FastNewArray from FastNewObject built-in for greater speed/specialization and further splitting into Array_1str, etc.
2. Add Array_1str, Array_2obj, and Array_3num builtins for benchmarked new Array(...) constructions.
3. Export ARRAY_SET_DENSE_LENGTH and ARRAY_GROWBY via jsarray.h to jstracer.cpp.
4. Tweaked SetArrayElement to make common/best case code be the predicted/prefetched path.
5. js_MakeArraySlow now preserves the pre-slow length in JSSLOT_ARRAY_COUTN as a jsval-tagged int if possible -- this will help the tracer avoid aborting on dense arrays that turned slow but not sparse by addition of a named property.
6. Export js_fun_apply and js_Object from their respective .cpp files, in these cases just to jstracer.cpp via local prototypes (no .h files involved).
7. More INS_CONSTPTR and INS_CONST macrology for better names in trace debug spew.
8. Fix TraceRecorder::test_property_cache to avoid aborting on JSOP_SETNAME that creates a new global, by setting it to undefined so it can be lazily imported. This helps 3d-raytrace.js, which has an unintended global loop control variable in a function.
9. JSTraceableNative loses its premature-deadwood tclasp member (my bad).
10. TraceRecorder::record_JSOP_NEW() handles 'new Object' now along with the 'new Array' variations. I also cut down the copy-paste code from JSOP_CALL's record method to mostly what is needed now.
11. Add KNOWN_NATIVE_DECL macro for concise prototype of library-private js_* native functions, and alphabetized the lists (too long for any other order to be winning).
12. Big honking special case for foo.apply(obj, [str]), which we can generalize as needed. Helps string-tagcloud.js. What's cool is how tracing allows us to rewrite this to foo(str) with this set to obj, eliminating the Function.prototype.apply. This requires some rewriting in JSOP_ENDINIT's record method.
2008-09-01 01:24:58 -07:00
|
|
|
#define ARRAY_CTOR_GUTS(exact_len, newslots_code) \
|
2008-09-03 00:38:24 -07:00
|
|
|
JS_ASSERT(JS_ON_TRACE(cx)); \
|
Kind of an Array initialiser tour-de-force for bug 452878:
1. Split FastNewArray from FastNewObject built-in for greater speed/specialization and further splitting into Array_1str, etc.
2. Add Array_1str, Array_2obj, and Array_3num builtins for benchmarked new Array(...) constructions.
3. Export ARRAY_SET_DENSE_LENGTH and ARRAY_GROWBY via jsarray.h to jstracer.cpp.
4. Tweaked SetArrayElement to make common/best case code be the predicted/prefetched path.
5. js_MakeArraySlow now preserves the pre-slow length in JSSLOT_ARRAY_COUTN as a jsval-tagged int if possible -- this will help the tracer avoid aborting on dense arrays that turned slow but not sparse by addition of a named property.
6. Export js_fun_apply and js_Object from their respective .cpp files, in these cases just to jstracer.cpp via local prototypes (no .h files involved).
7. More INS_CONSTPTR and INS_CONST macrology for better names in trace debug spew.
8. Fix TraceRecorder::test_property_cache to avoid aborting on JSOP_SETNAME that creates a new global, by setting it to undefined so it can be lazily imported. This helps 3d-raytrace.js, which has an unintended global loop control variable in a function.
9. JSTraceableNative loses its premature-deadwood tclasp member (my bad).
10. TraceRecorder::record_JSOP_NEW() handles 'new Object' now along with the 'new Array' variations. I also cut down the copy-paste code from JSOP_CALL's record method to mostly what is needed now.
11. Add KNOWN_NATIVE_DECL macro for concise prototype of library-private js_* native functions, and alphabetized the lists (too long for any other order to be winning).
12. Big honking special case for foo.apply(obj, [str]), which we can generalize as needed. Helps string-tagcloud.js. What's cool is how tracing allows us to rewrite this to foo(str) with this set to obj, eliminating the Function.prototype.apply. This requires some rewriting in JSOP_ENDINIT's record method.
2008-09-01 01:24:58 -07:00
|
|
|
JSObject* obj = js_FastNewArray(cx, proto); \
|
|
|
|
if (obj) { \
|
2008-09-15 00:54:28 -07:00
|
|
|
const uint32 len = ARRAY_GROWBY; \
|
Kind of an Array initialiser tour-de-force for bug 452878:
1. Split FastNewArray from FastNewObject built-in for greater speed/specialization and further splitting into Array_1str, etc.
2. Add Array_1str, Array_2obj, and Array_3num builtins for benchmarked new Array(...) constructions.
3. Export ARRAY_SET_DENSE_LENGTH and ARRAY_GROWBY via jsarray.h to jstracer.cpp.
4. Tweaked SetArrayElement to make common/best case code be the predicted/prefetched path.
5. js_MakeArraySlow now preserves the pre-slow length in JSSLOT_ARRAY_COUTN as a jsval-tagged int if possible -- this will help the tracer avoid aborting on dense arrays that turned slow but not sparse by addition of a named property.
6. Export js_fun_apply and js_Object from their respective .cpp files, in these cases just to jstracer.cpp via local prototypes (no .h files involved).
7. More INS_CONSTPTR and INS_CONST macrology for better names in trace debug spew.
8. Fix TraceRecorder::test_property_cache to avoid aborting on JSOP_SETNAME that creates a new global, by setting it to undefined so it can be lazily imported. This helps 3d-raytrace.js, which has an unintended global loop control variable in a function.
9. JSTraceableNative loses its premature-deadwood tclasp member (my bad).
10. TraceRecorder::record_JSOP_NEW() handles 'new Object' now along with the 'new Array' variations. I also cut down the copy-paste code from JSOP_CALL's record method to mostly what is needed now.
11. Add KNOWN_NATIVE_DECL macro for concise prototype of library-private js_* native functions, and alphabetized the lists (too long for any other order to be winning).
12. Big honking special case for foo.apply(obj, [str]), which we can generalize as needed. Helps string-tagcloud.js. What's cool is how tracing allows us to rewrite this to foo(str) with this set to obj, eliminating the Function.prototype.apply. This requires some rewriting in JSOP_ENDINIT's record method.
2008-09-01 01:24:58 -07:00
|
|
|
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;)
|
|
|
|
}
|
|
|
|
|
2008-09-05 18:29:08 -07:00
|
|
|
JSObject* FASTCALL
|
|
|
|
js_Arguments(JSContext* cx)
|
|
|
|
{
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2008-09-26 11:37:50 -07:00
|
|
|
jsdouble FASTCALL
|
|
|
|
js_Date_now(JSContext*)
|
|
|
|
{
|
|
|
|
return PRMJ_Now() / PRMJ_USEC_PER_MSEC;
|
|
|
|
}
|
|
|
|
|
2008-10-06 17:28:22 -07:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2008-09-02 22:29:23 -07:00
|
|
|
/* soft float */
|
|
|
|
|
|
|
|
jsdouble FASTCALL
|
|
|
|
js_fneg(jsdouble x)
|
|
|
|
{
|
|
|
|
return -x;
|
|
|
|
}
|
|
|
|
|
|
|
|
jsdouble FASTCALL
|
|
|
|
js_i2f(jsint i)
|
|
|
|
{
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
|
|
|
|
jsdouble FASTCALL
|
|
|
|
js_u2f(jsuint u)
|
|
|
|
{
|
|
|
|
return u;
|
|
|
|
}
|
|
|
|
|
|
|
|
jsint FASTCALL
|
|
|
|
js_fcmpeq(jsdouble x, jsdouble y)
|
|
|
|
{
|
|
|
|
return x==y;
|
|
|
|
}
|
|
|
|
|
|
|
|
jsint FASTCALL
|
|
|
|
js_fcmplt(jsdouble x, jsdouble y)
|
|
|
|
{
|
|
|
|
return x < y;
|
|
|
|
}
|
|
|
|
|
|
|
|
jsint FASTCALL
|
|
|
|
js_fcmple(jsdouble x, jsdouble y)
|
|
|
|
{
|
|
|
|
return x <= y;
|
|
|
|
}
|
|
|
|
|
|
|
|
jsint FASTCALL
|
|
|
|
js_fcmpgt(jsdouble x, jsdouble y)
|
|
|
|
{
|
|
|
|
return x > y;
|
|
|
|
}
|
|
|
|
|
|
|
|
jsint FASTCALL
|
|
|
|
js_fcmpge(jsdouble x, jsdouble y)
|
|
|
|
{
|
|
|
|
return x >= y;
|
|
|
|
}
|
|
|
|
|
|
|
|
jsdouble FASTCALL
|
|
|
|
js_fmul(jsdouble x, jsdouble y)
|
|
|
|
{
|
|
|
|
return x * y;
|
|
|
|
}
|
|
|
|
jsdouble FASTCALL
|
|
|
|
js_fadd(jsdouble x, jsdouble y)
|
|
|
|
{
|
|
|
|
return x + y;
|
|
|
|
}
|
|
|
|
|
|
|
|
jsdouble FASTCALL
|
|
|
|
js_fdiv(jsdouble x, jsdouble y)
|
|
|
|
{
|
|
|
|
return x / y;
|
|
|
|
}
|
|
|
|
|
|
|
|
jsdouble FASTCALL
|
|
|
|
js_fsub(jsdouble x, jsdouble y)
|
|
|
|
{
|
|
|
|
return x - y;
|
|
|
|
}
|
|
|
|
|
2008-07-08 23:48:06 -07:00
|
|
|
#define LO ARGSIZE_LO
|
|
|
|
#define F ARGSIZE_F
|
|
|
|
#define Q ARGSIZE_Q
|
|
|
|
|
2008-08-19 17:19:19 -07:00
|
|
|
#if defined AVMPLUS_64BIT
|
|
|
|
#define P ARGSIZE_Q
|
|
|
|
#else
|
|
|
|
#define P ARGSIZE_LO
|
|
|
|
#endif
|
|
|
|
|
2008-07-08 23:48:06 -07:00
|
|
|
#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-08-12 18:52:28 -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-08-12 18:52:28 -07:00
|
|
|
#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) },
|
2008-07-08 23:48:06 -07:00
|
|
|
|
|
|
|
struct CallInfo builtins[] = {
|
|
|
|
#include "builtins.tbl"
|
|
|
|
};
|