2009-06-10 18:29:44 -07:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4; -*-
|
2008-07-05 17:29:55 -07:00
|
|
|
* 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 ***** */
|
|
|
|
|
|
|
|
#include <math.h>
|
|
|
|
|
|
|
|
#include "jsapi.h"
|
2009-03-18 11:38:16 -07:00
|
|
|
#include "jsstdint.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-10-08 15:08:33 -07:00
|
|
|
#include "jsbuiltins.h"
|
2008-10-12 15:39:32 -07:00
|
|
|
#include "jstracer.h"
|
2008-08-06 13:36:29 -07:00
|
|
|
|
2008-08-06 15:56:31 -07:00
|
|
|
using namespace avmplus;
|
2008-07-08 23:48:06 -07:00
|
|
|
using namespace nanojit;
|
|
|
|
|
2008-10-08 15:08:33 -07:00
|
|
|
extern jsdouble js_NaN;
|
|
|
|
|
2009-04-09 16:07:00 -07:00
|
|
|
JS_FRIEND_API(void)
|
|
|
|
js_SetTraceableNativeFailed(JSContext *cx)
|
|
|
|
{
|
|
|
|
js_SetBuiltinError(cx);
|
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
}
|
2009-05-05 17:36:26 -07:00
|
|
|
JS_DEFINE_CALLINFO_2(extern, DOUBLE, js_dmod, DOUBLE, DOUBLE, 1, 1)
|
2008-07-05 17:29:55 -07:00
|
|
|
|
2008-10-08 15:08:33 -07:00
|
|
|
int32 FASTCALL
|
|
|
|
js_imod(int32 a, int32 b)
|
2008-09-15 19:59:06 -07:00
|
|
|
{
|
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
|
|
|
}
|
2009-05-05 17:36:26 -07:00
|
|
|
JS_DEFINE_CALLINFO_2(extern, INT32, js_imod, INT32, INT32, 1, 1)
|
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-10-08 15:08:33 -07:00
|
|
|
int32 i;
|
2008-11-15 16:42:35 -08:00
|
|
|
if (JSDOUBLE_IS_INT(d, i) && INT_FITS_IN_JSVAL(i))
|
2008-07-06 15:55:04 -07:00
|
|
|
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;
|
|
|
|
}
|
2009-05-05 17:36:26 -07:00
|
|
|
JS_DEFINE_CALLINFO_2(extern, JSVAL, js_BoxDouble, CONTEXT, DOUBLE, 1, 1)
|
2008-07-05 17:29:55 -07:00
|
|
|
|
2008-08-10 00:39:18 -07:00
|
|
|
jsval FASTCALL
|
2008-10-08 15:08:33 -07:00
|
|
|
js_BoxInt32(JSContext* cx, int32 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
|
|
|
}
|
2009-05-05 17:36:26 -07:00
|
|
|
JS_DEFINE_CALLINFO_2(extern, JSVAL, js_BoxInt32, CONTEXT, INT32, 1, 1)
|
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);
|
|
|
|
}
|
2009-05-05 17:36:26 -07:00
|
|
|
JS_DEFINE_CALLINFO_1(extern, DOUBLE, js_UnboxDouble, JSVAL, 1, 1)
|
2008-07-06 15:55:04 -07:00
|
|
|
|
2008-10-08 15:08:33 -07:00
|
|
|
int32 FASTCALL
|
2008-08-10 00:39:18 -07:00
|
|
|
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
|
|
|
}
|
2009-05-05 17:36:26 -07:00
|
|
|
JS_DEFINE_CALLINFO_1(extern, INT32, js_UnboxInt32, JSVAL, 1, 1)
|
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);
|
|
|
|
}
|
2009-05-05 17:36:26 -07:00
|
|
|
JS_DEFINE_CALLINFO_1(extern, INT32, js_DoubleToInt32, DOUBLE, 1, 1)
|
2008-07-06 10:59:55 -07:00
|
|
|
|
2008-10-08 15:08:33 -07:00
|
|
|
uint32 FASTCALL
|
2008-08-10 00:39:18 -07:00
|
|
|
js_DoubleToUint32(jsdouble d)
|
2008-07-06 10:59:55 -07:00
|
|
|
{
|
|
|
|
return js_DoubleToECMAUint32(d);
|
|
|
|
}
|
2009-05-05 17:36:26 -07:00
|
|
|
JS_DEFINE_CALLINFO_1(extern, UINT32, js_DoubleToUint32, DOUBLE, 1, 1)
|
2008-07-08 23:48:06 -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;
|
|
|
|
|
2009-06-10 18:29:44 -07:00
|
|
|
str->getCharsAndEnd(bp, end);
|
2008-07-31 07:41:58 -07:00
|
|
|
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;
|
|
|
|
}
|
2009-05-05 17:36:26 -07:00
|
|
|
JS_DEFINE_CALLINFO_2(extern, DOUBLE, js_StringToNumber, CONTEXT, STRING, 1, 1)
|
2008-07-31 07:41:58 -07:00
|
|
|
|
2008-10-08 15:08:33 -07:00
|
|
|
int32 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;
|
|
|
|
|
2009-06-10 18:29:44 -07:00
|
|
|
str->getCharsAndEnd(bp, end);
|
2008-07-31 11:35:08 -07:00
|
|
|
if (!js_strtod(cx, bp, end, &ep, &d) || js_SkipWhiteSpace(ep, end) != end)
|
|
|
|
return 0;
|
2008-11-16 20:43:13 -08:00
|
|
|
return js_DoubleToECMAInt32(d);
|
2008-09-07 00:41:10 -07:00
|
|
|
}
|
2009-05-05 17:36:26 -07:00
|
|
|
JS_DEFINE_CALLINFO_2(extern, INT32, js_StringToInt32, CONTEXT, STRING, 1, 1)
|
2008-09-07 00:41:10 -07:00
|
|
|
|
2008-10-21 17:50:32 -07:00
|
|
|
SideExit* FASTCALL
|
2008-08-10 00:39:18 -07:00
|
|
|
js_CallTree(InterpState* state, Fragment* f)
|
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
|
|
|
|
2008-10-21 17:50:32 -07:00
|
|
|
GuardRecord* rec;
|
2008-09-02 11:43:55 -07:00
|
|
|
#if defined(JS_NO_FASTCALL) && defined(NANOJIT_IA32)
|
2008-10-21 17:50:32 -07:00
|
|
|
SIMULATE_FASTCALL(rec, state, NULL, u.func);
|
2008-09-02 11:43:55 -07:00
|
|
|
#else
|
2008-10-21 17:50:32 -07:00
|
|
|
rec = u.func(state, NULL);
|
2008-09-02 11:43:55 -07:00
|
|
|
#endif
|
2008-11-07 15:23:43 -08:00
|
|
|
VMSideExit* lr = (VMSideExit*)rec->exit;
|
2008-09-02 11:43:55 -07:00
|
|
|
|
2008-10-21 17:50:32 -07:00
|
|
|
if (lr->exitType == NESTED_EXIT) {
|
2008-09-19 18:45:57 -07:00
|
|
|
/* 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. */
|
2008-10-12 15:39:32 -07:00
|
|
|
if (!state->lastTreeCallGuard) {
|
2008-09-19 18:45:57 -07:00
|
|
|
state->lastTreeCallGuard = lr;
|
2009-01-01 17:55:43 -08:00
|
|
|
FrameInfo** rp = (FrameInfo**)state->rp;
|
2008-10-12 15:39:32 -07:00
|
|
|
state->rpAtLastTreeCall = rp + lr->calldepth;
|
|
|
|
}
|
2008-09-19 18:45:57 -07:00
|
|
|
} 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
|
|
|
}
|
2009-05-05 17:36:26 -07:00
|
|
|
JS_DEFINE_CALLINFO_2(extern, SIDEEXIT, js_CallTree, INTERPSTATE, FRAGMENT, 0, 0)
|
2008-08-06 15:56:31 -07:00
|
|
|
|
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
|
|
|
{
|
|
|
|
JS_ASSERT(OBJ_IS_NATIVE(obj));
|
|
|
|
JS_ASSERT(SPROP_HAS_STUB_SETTER(sprop));
|
|
|
|
|
|
|
|
JS_LOCK_OBJ(cx, obj);
|
2009-04-20 03:10:29 -07:00
|
|
|
|
2008-08-08 14:38:44 -07:00
|
|
|
JSScope* scope = OBJ_SCOPE(obj);
|
2009-04-20 03:10:29 -07:00
|
|
|
uint32 slot;
|
2008-08-08 14:38:44 -07:00
|
|
|
if (scope->object == obj) {
|
|
|
|
JS_ASSERT(!SCOPE_HAS_PROPERTY(scope, sprop));
|
|
|
|
} else {
|
|
|
|
scope = js_GetMutableScope(cx, obj);
|
2009-04-20 03:10:29 -07:00
|
|
|
if (!scope)
|
|
|
|
goto exit_trace;
|
2008-08-08 14:38:44 -07:00
|
|
|
}
|
|
|
|
|
2009-04-20 03:10:29 -07:00
|
|
|
slot = sprop->slot;
|
2009-05-14 03:35:23 -07:00
|
|
|
if (!scope->table && sprop->parent == scope->lastProp && slot == scope->freeslot) {
|
2008-08-08 14:38:44 -07:00
|
|
|
if (slot < STOBJ_NSLOTS(obj) && !OBJ_GET_CLASS(cx, obj)->reserveSlots) {
|
2009-05-14 03:35:23 -07:00
|
|
|
JS_ASSERT(JSVAL_IS_VOID(STOBJ_GET_SLOT(obj, scope->freeslot)));
|
|
|
|
++scope->freeslot;
|
2008-08-08 14:38:44 -07:00
|
|
|
} else {
|
2009-04-20 03:10:29 -07:00
|
|
|
if (!js_AllocSlot(cx, obj, &slot))
|
|
|
|
goto exit_trace;
|
2008-08-08 14:38:44 -07:00
|
|
|
|
2009-04-05 21:17:22 -07:00
|
|
|
if (slot != sprop->slot) {
|
|
|
|
js_FreeSlot(cx, obj, slot);
|
2009-04-20 03:10:29 -07:00
|
|
|
goto exit_trace;
|
2009-04-05 21:17:22 -07:00
|
|
|
}
|
2008-08-08 14:38:44 -07:00
|
|
|
}
|
|
|
|
|
2009-04-24 17:47:32 -07:00
|
|
|
js_ExtendScopeShape(cx, scope, sprop);
|
2008-08-08 14:38:44 -07:00
|
|
|
++scope->entryCount;
|
|
|
|
scope->lastProp = sprop;
|
2009-04-20 03:10:29 -07:00
|
|
|
} else {
|
|
|
|
JSScopeProperty *sprop2 = js_AddScopeProperty(cx, scope, sprop->id,
|
|
|
|
sprop->getter,
|
|
|
|
sprop->setter,
|
|
|
|
SPROP_INVALID_SLOT,
|
|
|
|
sprop->attrs,
|
|
|
|
sprop->flags,
|
|
|
|
sprop->shortid);
|
|
|
|
if (sprop2 != sprop)
|
|
|
|
goto exit_trace;
|
2008-08-08 14:38:44 -07:00
|
|
|
}
|
|
|
|
|
2009-04-20 03:10:29 -07:00
|
|
|
if (js_IsPropertyCacheDisabled(cx))
|
|
|
|
goto exit_trace;
|
|
|
|
|
|
|
|
JS_UNLOCK_SCOPE(cx, scope);
|
|
|
|
return JS_TRUE;
|
2008-08-08 14:38:44 -07:00
|
|
|
|
2009-04-20 03:10:29 -07:00
|
|
|
exit_trace:
|
2008-08-08 14:38:44 -07:00
|
|
|
JS_UNLOCK_SCOPE(cx, scope);
|
2008-09-02 15:37:22 -07:00
|
|
|
return JS_FALSE;
|
2008-08-08 14:38:44 -07:00
|
|
|
}
|
2009-05-05 17:36:26 -07:00
|
|
|
JS_DEFINE_CALLINFO_3(extern, BOOL, js_AddProperty, CONTEXT, OBJECT, SCOPEPROP, 0, 0)
|
2008-08-08 14:38:44 -07:00
|
|
|
|
2009-01-08 21:59:24 -08:00
|
|
|
static JSBool
|
|
|
|
HasProperty(JSContext* cx, JSObject* obj, jsid id)
|
2008-08-27 23:00:43 -07:00
|
|
|
{
|
2009-02-05 17:49:54 -08:00
|
|
|
// Check that we know how the lookup op will behave.
|
2009-04-14 14:59:55 -07:00
|
|
|
for (JSObject* pobj = obj; pobj; pobj = OBJ_GET_PROTO(cx, pobj)) {
|
|
|
|
if (pobj->map->ops->lookupProperty != js_LookupProperty)
|
|
|
|
return JSVAL_TO_PSEUDO_BOOLEAN(JSVAL_VOID);
|
|
|
|
JSClass* clasp = OBJ_GET_CLASS(cx, pobj);
|
|
|
|
if (clasp->resolve != JS_ResolveStub && clasp != &js_StringClass)
|
|
|
|
return JSVAL_TO_PSEUDO_BOOLEAN(JSVAL_VOID);
|
|
|
|
}
|
2008-08-27 23:00:43 -07:00
|
|
|
|
|
|
|
JSObject* obj2;
|
|
|
|
JSProperty* prop;
|
2009-02-05 17:49:54 -08:00
|
|
|
if (!js_LookupPropertyWithFlags(cx, obj, id, JSRESOLVE_QUALIFIED, &obj2, &prop))
|
|
|
|
return JSVAL_TO_PSEUDO_BOOLEAN(JSVAL_VOID);
|
2008-08-27 23:00:43 -07:00
|
|
|
if (prop)
|
|
|
|
OBJ_DROP_PROPERTY(cx, obj2, prop);
|
|
|
|
return prop != NULL;
|
|
|
|
}
|
|
|
|
|
2009-01-08 21:59:24 -08:00
|
|
|
JSBool FASTCALL
|
|
|
|
js_HasNamedProperty(JSContext* cx, JSObject* obj, JSString* idstr)
|
|
|
|
{
|
|
|
|
jsid id;
|
|
|
|
if (!js_ValueToStringId(cx, STRING_TO_JSVAL(idstr), &id))
|
|
|
|
return JSVAL_TO_BOOLEAN(JSVAL_VOID);
|
|
|
|
|
|
|
|
return HasProperty(cx, obj, id);
|
|
|
|
}
|
2009-05-05 17:36:26 -07:00
|
|
|
JS_DEFINE_CALLINFO_3(extern, BOOL, js_HasNamedProperty, CONTEXT, OBJECT, STRING, 0, 0)
|
2009-01-08 21:59:24 -08:00
|
|
|
|
2008-11-16 22:13:13 -08:00
|
|
|
JSBool FASTCALL
|
|
|
|
js_HasNamedPropertyInt32(JSContext* cx, JSObject* obj, int32 index)
|
|
|
|
{
|
|
|
|
jsid id;
|
2008-12-16 19:03:42 -08:00
|
|
|
if (!js_Int32ToId(cx, index, &id))
|
2008-11-16 22:13:13 -08:00
|
|
|
return JSVAL_TO_BOOLEAN(JSVAL_VOID);
|
2008-11-17 16:29:40 -08:00
|
|
|
|
2009-01-08 21:59:24 -08:00
|
|
|
return HasProperty(cx, obj, id);
|
2008-11-16 22:13:13 -08:00
|
|
|
}
|
2009-05-05 17:36:26 -07:00
|
|
|
JS_DEFINE_CALLINFO_3(extern, BOOL, js_HasNamedPropertyInt32, CONTEXT, OBJECT, INT32, 0, 0)
|
2008-11-16 22:13:13 -08:00
|
|
|
|
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;
|
2009-02-26 00:49:39 -08:00
|
|
|
if (!js_GetSprop(cx, sprop, obj, &v))
|
2008-08-12 18:52:28 -07:00
|
|
|
return JSVAL_ERROR_COOKIE;
|
|
|
|
return v;
|
|
|
|
}
|
2009-05-05 17:36:26 -07:00
|
|
|
JS_DEFINE_CALLINFO_3(extern, JSVAL, js_CallGetter, CONTEXT, OBJECT, SCOPEPROP, 0, 0)
|
2008-08-12 18:52:28 -07:00
|
|
|
|
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]);
|
|
|
|
}
|
2009-05-05 17:36:26 -07:00
|
|
|
JS_DEFINE_CALLINFO_2(extern, STRING, js_TypeOfObject, CONTEXT, OBJECT, 1, 1)
|
2008-08-09 19:54:01 -07:00
|
|
|
|
|
|
|
JSString* FASTCALL
|
2008-10-08 15:08:33 -07:00
|
|
|
js_TypeOfBoolean(JSContext* cx, int32 unboxed)
|
2008-08-09 19:54:01 -07:00
|
|
|
{
|
2009-02-03 13:56:25 -08:00
|
|
|
/* Watch out for pseudo-booleans. */
|
|
|
|
jsval boxed = PSEUDO_BOOLEAN_TO_JSVAL(unboxed);
|
2008-08-09 19:54:01 -07:00
|
|
|
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]);
|
|
|
|
}
|
2009-05-05 17:36:26 -07:00
|
|
|
JS_DEFINE_CALLINFO_2(extern, STRING, js_TypeOfBoolean, CONTEXT, INT32, 1, 1)
|
2008-08-09 19:54:01 -07:00
|
|
|
|
2008-08-11 22:05:33 -07:00
|
|
|
jsdouble FASTCALL
|
2008-10-29 00:14:30 -07:00
|
|
|
js_BooleanOrUndefinedToNumber(JSContext* cx, int32 unboxed)
|
2008-08-11 22:05:33 -07:00
|
|
|
{
|
2009-02-03 13:56:25 -08:00
|
|
|
if (unboxed == JSVAL_TO_PSEUDO_BOOLEAN(JSVAL_VOID))
|
2008-09-04 22:30:04 -07:00
|
|
|
return js_NaN;
|
2009-02-03 13:56:25 -08:00
|
|
|
JS_ASSERT(unboxed == JS_TRUE || unboxed == JS_FALSE);
|
2008-08-11 22:05:33 -07:00
|
|
|
return unboxed;
|
|
|
|
}
|
2009-05-05 17:36:26 -07:00
|
|
|
JS_DEFINE_CALLINFO_2(extern, DOUBLE, js_BooleanOrUndefinedToNumber, CONTEXT, INT32, 1, 1)
|
2008-08-11 22:05:33 -07:00
|
|
|
|
2008-10-29 00:14:30 -07:00
|
|
|
JSString* FASTCALL
|
|
|
|
js_BooleanOrUndefinedToString(JSContext *cx, int32 unboxed)
|
|
|
|
{
|
|
|
|
JS_ASSERT(uint32(unboxed) <= 2);
|
|
|
|
return ATOM_TO_STRING(cx->runtime->atomState.booleanAtoms[unboxed]);
|
|
|
|
}
|
2009-05-05 17:36:26 -07:00
|
|
|
JS_DEFINE_CALLINFO_2(extern, STRING, js_BooleanOrUndefinedToString, CONTEXT, INT32, 1, 1)
|
2008-10-29 00:14:30 -07:00
|
|
|
|
2008-09-05 18:29:08 -07:00
|
|
|
JSObject* FASTCALL
|
|
|
|
js_Arguments(JSContext* cx)
|
|
|
|
{
|
|
|
|
return NULL;
|
|
|
|
}
|
2009-05-05 17:36:26 -07:00
|
|
|
JS_DEFINE_CALLINFO_1(extern, OBJECT, js_Arguments, CONTEXT, 0, 0)
|
2008-09-05 18:29:08 -07:00
|
|
|
|
2009-04-05 21:17:22 -07:00
|
|
|
JSObject* FASTCALL
|
2009-05-14 03:35:23 -07:00
|
|
|
js_NewNullClosure(JSContext* cx, JSObject* funobj, JSObject* proto, JSObject* parent)
|
2009-04-05 21:17:22 -07:00
|
|
|
{
|
|
|
|
JS_ASSERT(HAS_FUNCTION_CLASS(funobj));
|
2009-05-14 03:35:23 -07:00
|
|
|
JS_ASSERT(HAS_FUNCTION_CLASS(proto));
|
|
|
|
JS_ASSERT(JS_ON_TRACE(cx));
|
2009-04-05 21:17:22 -07:00
|
|
|
|
|
|
|
JSFunction *fun = (JSFunction*) funobj;
|
|
|
|
JS_ASSERT(GET_FUNCTION_PRIVATE(cx, funobj) == fun);
|
|
|
|
|
|
|
|
JSObject* closure = (JSObject*) js_NewGCThing(cx, GCX_OBJECT, sizeof(JSObject));
|
|
|
|
if (!closure)
|
|
|
|
return NULL;
|
|
|
|
|
2009-05-14 03:35:23 -07:00
|
|
|
js_HoldScope(OBJ_SCOPE(proto));
|
|
|
|
closure->map = proto->map;
|
2009-04-05 21:17:22 -07:00
|
|
|
closure->classword = jsuword(&js_FunctionClass);
|
|
|
|
closure->fslots[JSSLOT_PROTO] = OBJECT_TO_JSVAL(proto);
|
|
|
|
closure->fslots[JSSLOT_PARENT] = OBJECT_TO_JSVAL(parent);
|
|
|
|
closure->fslots[JSSLOT_PRIVATE] = PRIVATE_TO_JSVAL(fun);
|
|
|
|
for (unsigned i = JSSLOT_PRIVATE + 1; i != JS_INITIAL_NSLOTS; ++i)
|
|
|
|
closure->fslots[i] = JSVAL_VOID;
|
|
|
|
closure->dslots = NULL;
|
|
|
|
return closure;
|
|
|
|
}
|
2009-05-05 17:36:26 -07:00
|
|
|
JS_DEFINE_CALLINFO_4(extern, OBJECT, js_NewNullClosure, CONTEXT, OBJECT, OBJECT, OBJECT, 0, 0)
|
2009-04-05 21:17:22 -07:00
|
|
|
|