2009-11-18 12:29:58 -08: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 Communicator client code, released
|
|
|
|
* March 31, 1998.
|
|
|
|
*
|
|
|
|
* The Initial Developer of the Original Code is
|
|
|
|
* Netscape Communications Corporation.
|
|
|
|
* Portions created by the Initial Developer are Copyright (C) 1998
|
|
|
|
* the Initial Developer. All Rights Reserved.
|
|
|
|
*
|
|
|
|
* Contributor(s):
|
|
|
|
*
|
|
|
|
* 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 ***** */
|
|
|
|
|
|
|
|
#ifndef jsobjinlines_h___
|
|
|
|
#define jsobjinlines_h___
|
|
|
|
|
2010-08-29 11:57:08 -07:00
|
|
|
#include <new>
|
2010-04-14 18:57:30 -07:00
|
|
|
#include "jsdate.h"
|
2010-08-29 11:57:08 -07:00
|
|
|
#include "jsfun.h"
|
2010-04-14 17:09:17 -07:00
|
|
|
#include "jsiter.h"
|
2010-08-29 11:57:08 -07:00
|
|
|
#include "jslock.h"
|
2010-04-14 18:57:30 -07:00
|
|
|
#include "jsobj.h"
|
2010-09-01 14:09:54 -07:00
|
|
|
#include "jsprobes.h"
|
2010-08-29 11:57:08 -07:00
|
|
|
#include "jspropertytree.h"
|
2011-02-22 22:25:10 -08:00
|
|
|
#include "jsproxy.h"
|
2009-11-18 12:29:58 -08:00
|
|
|
#include "jsscope.h"
|
2010-06-18 17:43:02 -07:00
|
|
|
#include "jsstaticcheck.h"
|
2010-05-12 18:57:36 -07:00
|
|
|
#include "jsxml.h"
|
|
|
|
|
2010-08-29 11:57:08 -07:00
|
|
|
/* Headers included for inline implementations used by this header. */
|
|
|
|
#include "jsbool.h"
|
2010-06-16 14:13:01 -07:00
|
|
|
#include "jscntxt.h"
|
2010-08-29 11:57:08 -07:00
|
|
|
#include "jsnum.h"
|
2011-03-15 12:18:36 -07:00
|
|
|
#include "jsscriptinlines.h"
|
2010-08-29 11:57:08 -07:00
|
|
|
#include "jsstr.h"
|
2010-04-10 16:16:35 -07:00
|
|
|
|
2011-02-22 22:25:10 -08:00
|
|
|
#include "jsfuninlines.h"
|
2010-09-24 10:54:39 -07:00
|
|
|
#include "jsgcinlines.h"
|
|
|
|
#include "jsprobes.h"
|
2011-03-14 13:59:53 -07:00
|
|
|
#include "jsscopeinlines.h"
|
2010-09-24 10:54:39 -07:00
|
|
|
|
2010-09-21 11:35:29 -07:00
|
|
|
inline bool
|
|
|
|
JSObject::preventExtensions(JSContext *cx, js::AutoIdVector *props)
|
2010-08-29 11:57:08 -07:00
|
|
|
{
|
2010-09-21 11:35:29 -07:00
|
|
|
JS_ASSERT(isExtensible());
|
|
|
|
|
|
|
|
if (js::FixOp fix = getOps()->fix) {
|
|
|
|
bool success;
|
|
|
|
if (!fix(cx, this, &success, props))
|
|
|
|
return false;
|
|
|
|
if (!success) {
|
|
|
|
JS_ReportErrorNumber(cx, js_GetErrorMessage, NULL, JSMSG_CANT_CHANGE_EXTENSIBILITY);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (!GetPropertyNames(cx, this, JSITER_HIDDEN | JSITER_OWNONLY, props))
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2010-08-29 11:57:08 -07:00
|
|
|
if (isNative())
|
2010-09-21 11:35:29 -07:00
|
|
|
extensibleShapeChange(cx);
|
|
|
|
|
|
|
|
flags |= NOT_EXTENSIBLE;
|
|
|
|
return true;
|
2010-08-29 11:57:08 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
inline bool
|
2010-11-09 11:40:56 -08:00
|
|
|
JSObject::brand(JSContext *cx)
|
2010-08-29 11:57:08 -07:00
|
|
|
{
|
|
|
|
JS_ASSERT(!generic());
|
|
|
|
JS_ASSERT(!branded());
|
|
|
|
JS_ASSERT(isNative());
|
|
|
|
generateOwnShape(cx);
|
|
|
|
if (js_IsPropertyCacheDisabled(cx)) // check for rt->shapeGen overflow
|
|
|
|
return false;
|
|
|
|
flags |= BRANDED;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline bool
|
|
|
|
JSObject::unbrand(JSContext *cx)
|
|
|
|
{
|
|
|
|
JS_ASSERT(isNative());
|
2010-11-22 17:58:53 -08:00
|
|
|
if (branded()) {
|
|
|
|
generateOwnShape(cx);
|
|
|
|
if (js_IsPropertyCacheDisabled(cx)) // check for rt->shapeGen overflow
|
|
|
|
return false;
|
|
|
|
flags &= ~BRANDED;
|
|
|
|
}
|
|
|
|
setGeneric();
|
2010-08-29 11:57:08 -07:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2010-11-12 10:40:12 -08:00
|
|
|
inline void
|
|
|
|
JSObject::syncSpecialEquality()
|
|
|
|
{
|
|
|
|
if (clasp->ext.equality)
|
|
|
|
flags |= JSObject::HAS_EQUALITY;
|
|
|
|
}
|
|
|
|
|
2010-09-24 10:54:39 -07:00
|
|
|
inline void
|
2010-11-15 12:39:00 -08:00
|
|
|
JSObject::finalize(JSContext *cx)
|
2010-09-24 10:54:39 -07:00
|
|
|
{
|
|
|
|
/* Cope with stillborn objects that have no map. */
|
|
|
|
if (!map)
|
|
|
|
return;
|
|
|
|
|
|
|
|
/* Finalize obj first, in case it needs map and slots. */
|
|
|
|
js::Class *clasp = getClass();
|
|
|
|
if (clasp->finalize)
|
|
|
|
clasp->finalize(cx, this);
|
|
|
|
|
|
|
|
js::Probes::finalizeObject(this);
|
|
|
|
|
|
|
|
finish(cx);
|
|
|
|
}
|
|
|
|
|
2011-03-15 12:18:36 -07:00
|
|
|
/*
|
|
|
|
* Initializer for Call objects for functions and eval frames. Set class,
|
|
|
|
* parent, map, and shape, and allocate slots.
|
|
|
|
*/
|
|
|
|
inline void
|
2011-03-14 11:30:36 -07:00
|
|
|
JSObject::initCall(JSContext *cx, const js::Bindings &bindings, JSObject *parent)
|
2011-03-15 12:18:36 -07:00
|
|
|
{
|
|
|
|
init(cx, &js_CallClass, NULL, parent, NULL, false);
|
2011-03-14 11:30:36 -07:00
|
|
|
map = bindings.lastShape();
|
2011-03-15 12:18:36 -07:00
|
|
|
|
|
|
|
/*
|
|
|
|
* If |bindings| is for a function that has extensible parents, that means
|
|
|
|
* its Call should have its own shape; see js::Bindings::extensibleParents.
|
|
|
|
*/
|
2011-03-14 11:30:36 -07:00
|
|
|
if (bindings.extensibleParents())
|
2011-03-15 12:18:36 -07:00
|
|
|
setOwnShape(js_GenerateShape(cx));
|
|
|
|
else
|
|
|
|
objShape = map->shape;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Initializer for cloned block objects. Set class, prototype, frame, map, and
|
|
|
|
* shape.
|
|
|
|
*/
|
|
|
|
inline void
|
|
|
|
JSObject::initClonedBlock(JSContext *cx, JSObject *proto, JSStackFrame *frame)
|
|
|
|
{
|
|
|
|
init(cx, &js_BlockClass, proto, NULL, frame, false);
|
|
|
|
|
|
|
|
/* Cloned blocks copy their prototype's map; it had better be shareable. */
|
|
|
|
JS_ASSERT(!proto->inDictionaryMode() || proto->lastProp->frozen());
|
|
|
|
map = proto->map;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If the prototype has its own shape, that means the clone should, too; see
|
|
|
|
* js::Bindings::extensibleParents.
|
|
|
|
*/
|
|
|
|
if (proto->hasOwnShape())
|
|
|
|
setOwnShape(js_GenerateShape(cx));
|
|
|
|
else
|
|
|
|
objShape = map->shape;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Mark a compile-time block as OWN_SHAPE, indicating that its run-time clones
|
|
|
|
* also need unique shapes. See js::Bindings::extensibleParents.
|
|
|
|
*/
|
|
|
|
inline void
|
|
|
|
JSObject::setBlockOwnShape(JSContext *cx) {
|
|
|
|
JS_ASSERT(isStaticBlock());
|
|
|
|
setOwnShape(js_GenerateShape(cx));
|
|
|
|
}
|
|
|
|
|
2010-08-29 11:57:08 -07:00
|
|
|
/*
|
|
|
|
* Property read barrier for deferred cloning of compiler-created function
|
|
|
|
* objects optimized as typically non-escaping, ad-hoc methods in obj.
|
|
|
|
*/
|
2011-02-15 12:11:04 -08:00
|
|
|
inline const js::Shape *
|
2010-08-29 11:57:08 -07:00
|
|
|
JSObject::methodReadBarrier(JSContext *cx, const js::Shape &shape, js::Value *vp)
|
|
|
|
{
|
|
|
|
JS_ASSERT(canHaveMethodBarrier());
|
|
|
|
JS_ASSERT(hasMethodBarrier());
|
|
|
|
JS_ASSERT(nativeContains(shape));
|
|
|
|
JS_ASSERT(shape.isMethod());
|
2011-04-08 10:52:48 -07:00
|
|
|
JS_ASSERT(shape.methodObject() == vp->toObject());
|
2011-02-08 14:09:33 -08:00
|
|
|
JS_ASSERT(shape.writable());
|
|
|
|
JS_ASSERT(shape.slot != SHAPE_INVALID_SLOT);
|
|
|
|
JS_ASSERT(shape.hasDefaultSetter() || shape.setterOp() == js_watch_set);
|
|
|
|
JS_ASSERT(!isGlobal()); /* i.e. we are not changing the global shape */
|
2010-08-29 11:57:08 -07:00
|
|
|
|
|
|
|
JSObject *funobj = &vp->toObject();
|
2011-02-15 12:11:04 -08:00
|
|
|
JSFunction *fun = funobj->getFunctionPrivate();
|
|
|
|
JS_ASSERT(fun == funobj);
|
|
|
|
JS_ASSERT(FUN_NULL_CLOSURE(fun));
|
2010-08-29 11:57:08 -07:00
|
|
|
|
|
|
|
funobj = CloneFunctionObject(cx, fun, funobj->getParent());
|
|
|
|
if (!funobj)
|
2011-02-15 12:11:04 -08:00
|
|
|
return NULL;
|
2010-08-29 11:57:08 -07:00
|
|
|
funobj->setMethodObj(*this);
|
|
|
|
|
2011-02-08 14:09:33 -08:00
|
|
|
/*
|
|
|
|
* Replace the method property with an ordinary data property. This is
|
|
|
|
* equivalent to this->setProperty(cx, shape.id, vp) except that any
|
|
|
|
* watchpoint on the property is not triggered.
|
|
|
|
*/
|
|
|
|
uint32 slot = shape.slot;
|
|
|
|
const js::Shape *newshape = methodShapeChange(cx, shape);
|
|
|
|
if (!newshape)
|
|
|
|
return NULL;
|
|
|
|
JS_ASSERT(!newshape->isMethod());
|
|
|
|
JS_ASSERT(newshape->slot == slot);
|
2010-08-29 11:57:08 -07:00
|
|
|
vp->setObject(*funobj);
|
2011-02-08 14:09:33 -08:00
|
|
|
nativeSetSlot(slot, *vp);
|
2010-08-29 11:57:08 -07:00
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
if (cx->runtime->functionMeterFilename) {
|
|
|
|
JS_FUNCTION_METER(cx, mreadbarrier);
|
|
|
|
|
2011-03-23 17:40:11 -07:00
|
|
|
typedef JSRuntime::FunctionCountMap::Ptr Ptr;
|
|
|
|
if (Ptr p = cx->runtime->methodReadBarrierCountMap.lookupWithDefault(fun, 0))
|
2010-08-29 11:57:08 -07:00
|
|
|
++p->value;
|
|
|
|
}
|
|
|
|
#endif
|
2011-02-15 12:11:04 -08:00
|
|
|
return newshape;
|
2010-08-29 11:57:08 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
static JS_ALWAYS_INLINE bool
|
|
|
|
ChangesMethodValue(const js::Value &prev, const js::Value &v)
|
|
|
|
{
|
|
|
|
JSObject *prevObj;
|
|
|
|
return prev.isObject() && (prevObj = &prev.toObject())->isFunction() &&
|
|
|
|
(!v.isObject() || &v.toObject() != prevObj);
|
|
|
|
}
|
|
|
|
|
2011-01-17 09:30:08 -08:00
|
|
|
inline const js::Shape *
|
2010-08-29 11:57:08 -07:00
|
|
|
JSObject::methodWriteBarrier(JSContext *cx, const js::Shape &shape, const js::Value &v)
|
|
|
|
{
|
2010-11-22 17:58:53 -08:00
|
|
|
if (brandedOrHasMethodBarrier() && shape.slot != SHAPE_INVALID_SLOT) {
|
|
|
|
const js::Value &prev = nativeGetSlot(shape.slot);
|
|
|
|
|
|
|
|
if (ChangesMethodValue(prev, v)) {
|
|
|
|
JS_FUNCTION_METER(cx, mwritebarrier);
|
|
|
|
return methodShapeChange(cx, shape);
|
2010-08-29 11:57:08 -07:00
|
|
|
}
|
|
|
|
}
|
2011-01-17 09:30:08 -08:00
|
|
|
return &shape;
|
2010-08-29 11:57:08 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
inline bool
|
|
|
|
JSObject::methodWriteBarrier(JSContext *cx, uint32 slot, const js::Value &v)
|
|
|
|
{
|
2010-11-22 17:58:53 -08:00
|
|
|
if (brandedOrHasMethodBarrier()) {
|
2010-10-22 17:04:22 -07:00
|
|
|
const js::Value &prev = nativeGetSlot(slot);
|
2010-08-29 11:57:08 -07:00
|
|
|
|
|
|
|
if (ChangesMethodValue(prev, v)) {
|
|
|
|
JS_FUNCTION_METER(cx, mwslotbarrier);
|
|
|
|
return methodShapeChange(cx, slot);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline bool
|
|
|
|
JSObject::ensureClassReservedSlots(JSContext *cx)
|
|
|
|
{
|
|
|
|
return !nativeEmpty() || ensureClassReservedSlotsForEmptyObject(cx);
|
|
|
|
}
|
|
|
|
|
2010-07-14 23:19:36 -07:00
|
|
|
inline js::Value
|
2010-06-07 18:35:58 -07:00
|
|
|
JSObject::getReservedSlot(uintN index) const
|
|
|
|
{
|
2010-10-13 11:49:22 -07:00
|
|
|
return (index < numSlots()) ? getSlot(index) : js::UndefinedValue();
|
2010-06-07 18:35:58 -07:00
|
|
|
}
|
|
|
|
|
2010-08-01 09:58:03 -07:00
|
|
|
inline bool
|
|
|
|
JSObject::canHaveMethodBarrier() const
|
|
|
|
{
|
|
|
|
return isObject() || isFunction() || isPrimitive() || isDate();
|
|
|
|
}
|
|
|
|
|
2010-04-14 18:57:30 -07:00
|
|
|
inline bool
|
|
|
|
JSObject::isPrimitive() const
|
|
|
|
{
|
|
|
|
return isNumber() || isString() || isBoolean();
|
|
|
|
}
|
|
|
|
|
2010-07-14 23:19:36 -07:00
|
|
|
inline const js::Value &
|
2010-04-14 18:57:30 -07:00
|
|
|
JSObject::getPrimitiveThis() const
|
|
|
|
{
|
|
|
|
JS_ASSERT(isPrimitive());
|
2010-10-13 11:49:22 -07:00
|
|
|
return getSlot(JSSLOT_PRIMITIVE_THIS);
|
2010-04-14 18:57:30 -07:00
|
|
|
}
|
|
|
|
|
2010-08-29 11:57:08 -07:00
|
|
|
inline void
|
2010-07-14 23:19:36 -07:00
|
|
|
JSObject::setPrimitiveThis(const js::Value &pthis)
|
2010-04-14 18:57:30 -07:00
|
|
|
{
|
|
|
|
JS_ASSERT(isPrimitive());
|
2010-10-13 11:49:22 -07:00
|
|
|
setSlot(JSSLOT_PRIMITIVE_THIS, pthis);
|
2010-04-14 18:57:30 -07:00
|
|
|
}
|
|
|
|
|
2010-11-15 17:21:25 -08:00
|
|
|
inline /* gc::FinalizeKind */ unsigned
|
|
|
|
JSObject::finalizeKind() const
|
2010-11-18 18:14:22 -08:00
|
|
|
{
|
2010-11-15 17:21:25 -08:00
|
|
|
return js::gc::FinalizeKind(arena()->header()->thingKind);
|
2010-11-18 18:14:22 -08:00
|
|
|
}
|
|
|
|
|
2010-10-13 11:49:22 -07:00
|
|
|
inline size_t
|
|
|
|
JSObject::numFixedSlots() const
|
2010-04-05 19:16:37 -07:00
|
|
|
{
|
2010-10-13 11:49:22 -07:00
|
|
|
if (isFunction())
|
|
|
|
return JSObject::FUN_CLASS_RESERVED_SLOTS;
|
|
|
|
if (!hasSlotsArray())
|
|
|
|
return capacity;
|
2010-11-15 17:21:25 -08:00
|
|
|
return js::gc::GetGCKindSlots(js::gc::FinalizeKind(finalizeKind()));
|
2010-10-13 11:49:22 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
inline size_t
|
|
|
|
JSObject::slotsAndStructSize(uint32 nslots) const
|
|
|
|
{
|
|
|
|
bool isFun = isFunction() && this == (JSObject*) getPrivate();
|
|
|
|
|
|
|
|
int ndslots = hasSlotsArray() ? nslots : 0;
|
|
|
|
int nfslots = isFun ? 0 : numFixedSlots();
|
|
|
|
|
|
|
|
return sizeof(js::Value) * (ndslots + nfslots)
|
|
|
|
+ isFun ? sizeof(JSFunction) : sizeof(JSObject);
|
2010-04-05 19:16:37 -07:00
|
|
|
}
|
|
|
|
|
2010-04-05 18:32:16 -07:00
|
|
|
inline uint32
|
|
|
|
JSObject::getArrayLength() const
|
|
|
|
{
|
|
|
|
JS_ASSERT(isArray());
|
2010-10-13 11:49:22 -07:00
|
|
|
return (uint32)(size_t) getPrivate();
|
2010-04-29 20:22:33 -07:00
|
|
|
}
|
|
|
|
|
2010-08-29 11:57:08 -07:00
|
|
|
inline void
|
2010-07-22 18:45:21 -07:00
|
|
|
JSObject::setArrayLength(uint32 length)
|
2010-04-29 20:22:33 -07:00
|
|
|
{
|
2010-07-22 18:45:21 -07:00
|
|
|
JS_ASSERT(isArray());
|
2010-10-13 11:49:22 -07:00
|
|
|
setPrivate((void*) length);
|
2010-04-05 18:32:16 -07:00
|
|
|
}
|
|
|
|
|
2010-04-26 18:33:36 -07:00
|
|
|
inline uint32
|
2010-10-13 11:49:22 -07:00
|
|
|
JSObject::getDenseArrayCapacity()
|
2010-04-26 18:33:36 -07:00
|
|
|
{
|
|
|
|
JS_ASSERT(isDenseArray());
|
2010-10-13 11:49:22 -07:00
|
|
|
return numSlots();
|
2010-04-26 18:33:36 -07:00
|
|
|
}
|
|
|
|
|
2010-10-13 11:49:22 -07:00
|
|
|
inline js::Value*
|
|
|
|
JSObject::getDenseArrayElements()
|
2010-04-05 18:32:16 -07:00
|
|
|
{
|
2010-04-26 18:33:36 -07:00
|
|
|
JS_ASSERT(isDenseArray());
|
2010-10-13 11:49:22 -07:00
|
|
|
return getSlots();
|
2010-09-01 14:09:54 -07:00
|
|
|
}
|
|
|
|
|
2010-07-14 23:19:36 -07:00
|
|
|
inline const js::Value &
|
2010-10-13 11:49:22 -07:00
|
|
|
JSObject::getDenseArrayElement(uintN idx)
|
2010-04-26 18:33:36 -07:00
|
|
|
{
|
|
|
|
JS_ASSERT(isDenseArray());
|
2010-10-13 11:49:22 -07:00
|
|
|
return getSlot(idx);
|
2010-04-26 18:33:36 -07:00
|
|
|
}
|
|
|
|
|
2010-07-14 23:19:36 -07:00
|
|
|
inline js::Value *
|
2010-10-13 11:49:22 -07:00
|
|
|
JSObject::addressOfDenseArrayElement(uintN idx)
|
2010-05-04 20:28:38 -07:00
|
|
|
{
|
|
|
|
JS_ASSERT(isDenseArray());
|
2010-10-13 11:49:22 -07:00
|
|
|
return &getSlotRef(idx);
|
2010-05-04 20:28:38 -07:00
|
|
|
}
|
|
|
|
|
2010-04-26 18:33:36 -07:00
|
|
|
inline void
|
2010-10-13 11:49:22 -07:00
|
|
|
JSObject::setDenseArrayElement(uintN idx, const js::Value &val)
|
2010-04-26 18:33:36 -07:00
|
|
|
{
|
|
|
|
JS_ASSERT(isDenseArray());
|
2010-10-13 11:49:22 -07:00
|
|
|
setSlot(idx, val);
|
2010-04-26 18:33:36 -07:00
|
|
|
}
|
|
|
|
|
2010-09-20 12:05:21 -07:00
|
|
|
inline void
|
2010-10-13 11:49:22 -07:00
|
|
|
JSObject::shrinkDenseArrayElements(JSContext *cx, uintN cap)
|
2010-09-20 12:05:21 -07:00
|
|
|
{
|
|
|
|
JS_ASSERT(isDenseArray());
|
2010-10-13 11:49:22 -07:00
|
|
|
shrinkSlots(cx, cap);
|
2010-04-05 18:32:16 -07:00
|
|
|
}
|
|
|
|
|
2010-04-11 16:45:20 -07:00
|
|
|
inline void
|
|
|
|
JSObject::setArgsLength(uint32 argc)
|
|
|
|
{
|
|
|
|
JS_ASSERT(isArguments());
|
|
|
|
JS_ASSERT(argc <= JS_ARGS_LENGTH_MAX);
|
2010-08-04 14:39:45 -07:00
|
|
|
JS_ASSERT(UINT32_MAX > (uint64(argc) << ARGS_PACKED_BITS_COUNT));
|
2010-10-13 11:49:22 -07:00
|
|
|
getSlotRef(JSSLOT_ARGS_LENGTH).setInt32(argc << ARGS_PACKED_BITS_COUNT);
|
2010-04-11 16:45:20 -07:00
|
|
|
JS_ASSERT(!isArgsLengthOverridden());
|
|
|
|
}
|
|
|
|
|
|
|
|
inline uint32
|
2010-08-04 13:50:01 -07:00
|
|
|
JSObject::getArgsInitialLength() const
|
2010-04-11 16:45:20 -07:00
|
|
|
{
|
|
|
|
JS_ASSERT(isArguments());
|
2010-10-13 11:49:22 -07:00
|
|
|
uint32 argc = uint32(getSlot(JSSLOT_ARGS_LENGTH).toInt32()) >> ARGS_PACKED_BITS_COUNT;
|
2010-04-11 16:45:20 -07:00
|
|
|
JS_ASSERT(argc <= JS_ARGS_LENGTH_MAX);
|
|
|
|
return argc;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline void
|
|
|
|
JSObject::setArgsLengthOverridden()
|
|
|
|
{
|
|
|
|
JS_ASSERT(isArguments());
|
2010-10-13 11:49:22 -07:00
|
|
|
getSlotRef(JSSLOT_ARGS_LENGTH).getInt32Ref() |= ARGS_LENGTH_OVERRIDDEN_BIT;
|
2010-04-11 16:45:20 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
inline bool
|
2010-05-02 21:42:09 -07:00
|
|
|
JSObject::isArgsLengthOverridden() const
|
2010-04-11 16:45:20 -07:00
|
|
|
{
|
|
|
|
JS_ASSERT(isArguments());
|
2010-10-13 11:49:22 -07:00
|
|
|
const js::Value &v = getSlot(JSSLOT_ARGS_LENGTH);
|
2010-08-04 14:39:45 -07:00
|
|
|
return v.toInt32() & ARGS_LENGTH_OVERRIDDEN_BIT;
|
2010-04-11 16:45:20 -07:00
|
|
|
}
|
|
|
|
|
2010-08-29 11:57:08 -07:00
|
|
|
inline js::ArgumentsData *
|
|
|
|
JSObject::getArgsData() const
|
2010-04-11 16:45:20 -07:00
|
|
|
{
|
|
|
|
JS_ASSERT(isArguments());
|
2010-10-13 11:49:22 -07:00
|
|
|
return (js::ArgumentsData *) getSlot(JSSLOT_ARGS_DATA).toPrivate();
|
2010-04-11 16:45:20 -07:00
|
|
|
}
|
|
|
|
|
2010-08-29 11:57:08 -07:00
|
|
|
inline void
|
|
|
|
JSObject::setArgsData(js::ArgumentsData *data)
|
2010-04-11 16:45:20 -07:00
|
|
|
{
|
|
|
|
JS_ASSERT(isArguments());
|
2010-10-13 11:49:22 -07:00
|
|
|
getSlotRef(JSSLOT_ARGS_DATA).setPrivate(data);
|
2010-08-29 11:57:08 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
inline const js::Value &
|
|
|
|
JSObject::getArgsCallee() const
|
|
|
|
{
|
|
|
|
return getArgsData()->callee;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline void
|
|
|
|
JSObject::setArgsCallee(const js::Value &callee)
|
|
|
|
{
|
|
|
|
getArgsData()->callee = callee;
|
2010-04-11 16:45:20 -07:00
|
|
|
}
|
|
|
|
|
2010-07-14 23:19:36 -07:00
|
|
|
inline const js::Value &
|
2010-05-02 21:42:09 -07:00
|
|
|
JSObject::getArgsElement(uint32 i) const
|
|
|
|
{
|
|
|
|
JS_ASSERT(isArguments());
|
2010-08-29 11:57:08 -07:00
|
|
|
JS_ASSERT(i < getArgsInitialLength());
|
|
|
|
return getArgsData()->slots[i];
|
2010-05-02 21:42:09 -07:00
|
|
|
}
|
|
|
|
|
2010-10-20 23:52:55 -07:00
|
|
|
inline js::Value *
|
|
|
|
JSObject::getArgsElements() const
|
|
|
|
{
|
|
|
|
JS_ASSERT(isArguments());
|
|
|
|
return getArgsData()->slots;
|
|
|
|
}
|
|
|
|
|
2010-07-14 23:19:36 -07:00
|
|
|
inline js::Value *
|
2010-10-13 11:49:22 -07:00
|
|
|
JSObject::addressOfArgsElement(uint32 i)
|
2010-07-14 23:19:36 -07:00
|
|
|
{
|
|
|
|
JS_ASSERT(isArguments());
|
2010-08-29 11:57:08 -07:00
|
|
|
JS_ASSERT(i < getArgsInitialLength());
|
|
|
|
return &getArgsData()->slots[i];
|
2010-07-14 23:19:36 -07:00
|
|
|
}
|
|
|
|
|
2010-05-02 21:42:09 -07:00
|
|
|
inline void
|
2010-07-14 23:19:36 -07:00
|
|
|
JSObject::setArgsElement(uint32 i, const js::Value &v)
|
2010-05-02 21:42:09 -07:00
|
|
|
{
|
|
|
|
JS_ASSERT(isArguments());
|
2010-08-29 11:57:08 -07:00
|
|
|
JS_ASSERT(i < getArgsInitialLength());
|
|
|
|
getArgsData()->slots[i] = v;
|
2010-05-02 21:42:09 -07:00
|
|
|
}
|
|
|
|
|
2011-01-05 12:54:04 -08:00
|
|
|
inline bool
|
|
|
|
JSObject::callIsForEval() const
|
|
|
|
{
|
|
|
|
JS_ASSERT(isCall());
|
|
|
|
JS_ASSERT(getSlot(JSSLOT_CALL_CALLEE).isObjectOrNull());
|
|
|
|
JS_ASSERT_IF(getSlot(JSSLOT_CALL_CALLEE).isObject(),
|
|
|
|
getSlot(JSSLOT_CALL_CALLEE).toObject().isFunction());
|
|
|
|
return getSlot(JSSLOT_CALL_CALLEE).isNull();
|
|
|
|
}
|
|
|
|
|
2010-12-29 20:21:18 -08:00
|
|
|
inline JSStackFrame *
|
|
|
|
JSObject::maybeCallObjStackFrame() const
|
|
|
|
{
|
|
|
|
JS_ASSERT(isCall());
|
|
|
|
return reinterpret_cast<JSStackFrame *>(getPrivate());
|
|
|
|
}
|
|
|
|
|
2010-08-09 22:43:33 -07:00
|
|
|
inline void
|
2010-10-12 11:38:06 -07:00
|
|
|
JSObject::setCallObjCallee(JSObject *callee)
|
2010-08-09 22:43:33 -07:00
|
|
|
{
|
|
|
|
JS_ASSERT(isCall());
|
2010-10-12 11:38:06 -07:00
|
|
|
JS_ASSERT_IF(callee, callee->isFunction());
|
|
|
|
return getSlotRef(JSSLOT_CALL_CALLEE).setObjectOrNull(callee);
|
2010-08-09 22:43:33 -07:00
|
|
|
}
|
|
|
|
|
2010-10-12 11:38:06 -07:00
|
|
|
inline JSObject *
|
2010-08-09 22:43:33 -07:00
|
|
|
JSObject::getCallObjCallee() const
|
|
|
|
{
|
|
|
|
JS_ASSERT(isCall());
|
2010-10-12 11:38:06 -07:00
|
|
|
return getSlot(JSSLOT_CALL_CALLEE).toObjectOrNull();
|
2010-08-09 22:43:33 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
inline JSFunction *
|
|
|
|
JSObject::getCallObjCalleeFunction() const
|
|
|
|
{
|
|
|
|
JS_ASSERT(isCall());
|
2010-10-13 11:49:22 -07:00
|
|
|
return getSlot(JSSLOT_CALL_CALLEE).toObject().getFunctionPrivate();
|
2010-08-09 22:43:33 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
inline const js::Value &
|
|
|
|
JSObject::getCallObjArguments() const
|
|
|
|
{
|
|
|
|
JS_ASSERT(isCall());
|
2011-01-05 12:54:04 -08:00
|
|
|
JS_ASSERT(!callIsForEval());
|
2010-10-13 11:49:22 -07:00
|
|
|
return getSlot(JSSLOT_CALL_ARGUMENTS);
|
2010-08-09 22:43:33 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
inline void
|
|
|
|
JSObject::setCallObjArguments(const js::Value &v)
|
|
|
|
{
|
|
|
|
JS_ASSERT(isCall());
|
2011-01-05 12:54:04 -08:00
|
|
|
JS_ASSERT(!callIsForEval());
|
2010-10-13 11:49:22 -07:00
|
|
|
setSlot(JSSLOT_CALL_ARGUMENTS, v);
|
2010-08-09 22:43:33 -07:00
|
|
|
}
|
|
|
|
|
2010-12-29 20:21:18 -08:00
|
|
|
inline const js::Value &
|
|
|
|
JSObject::callObjArg(uintN i) const
|
|
|
|
{
|
|
|
|
JS_ASSERT(isCall());
|
|
|
|
JS_ASSERT(i < getCallObjCalleeFunction()->nargs);
|
|
|
|
return getSlot(JSObject::CALL_RESERVED_SLOTS + i);
|
|
|
|
}
|
|
|
|
|
|
|
|
inline js::Value &
|
|
|
|
JSObject::callObjArg(uintN i)
|
|
|
|
{
|
|
|
|
JS_ASSERT(isCall());
|
|
|
|
JS_ASSERT(i < getCallObjCalleeFunction()->nargs);
|
|
|
|
return getSlotRef(JSObject::CALL_RESERVED_SLOTS + i);
|
|
|
|
}
|
|
|
|
|
|
|
|
inline const js::Value &
|
|
|
|
JSObject::callObjVar(uintN i) const
|
|
|
|
{
|
|
|
|
JSFunction *fun = getCallObjCalleeFunction();
|
|
|
|
JS_ASSERT(fun->nargs == fun->script()->bindings.countArgs());
|
|
|
|
JS_ASSERT(i < fun->script()->bindings.countVars());
|
|
|
|
return getSlot(JSObject::CALL_RESERVED_SLOTS + fun->nargs + i);
|
|
|
|
}
|
|
|
|
|
|
|
|
inline js::Value &
|
|
|
|
JSObject::callObjVar(uintN i)
|
|
|
|
{
|
|
|
|
JSFunction *fun = getCallObjCalleeFunction();
|
|
|
|
JS_ASSERT(fun->nargs == fun->script()->bindings.countArgs());
|
|
|
|
JS_ASSERT(i < fun->script()->bindings.countVars());
|
|
|
|
return getSlotRef(JSObject::CALL_RESERVED_SLOTS + fun->nargs + i);
|
|
|
|
}
|
|
|
|
|
2010-07-14 23:19:36 -07:00
|
|
|
inline const js::Value &
|
2010-04-14 18:57:30 -07:00
|
|
|
JSObject::getDateUTCTime() const
|
|
|
|
{
|
|
|
|
JS_ASSERT(isDate());
|
2010-10-13 11:49:22 -07:00
|
|
|
return getSlot(JSSLOT_DATE_UTC_TIME);
|
2010-04-14 18:57:30 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
inline void
|
2010-07-14 23:19:36 -07:00
|
|
|
JSObject::setDateUTCTime(const js::Value &time)
|
2010-04-14 18:57:30 -07:00
|
|
|
{
|
|
|
|
JS_ASSERT(isDate());
|
2010-10-13 11:49:22 -07:00
|
|
|
setSlot(JSSLOT_DATE_UTC_TIME, time);
|
2010-04-14 18:57:30 -07:00
|
|
|
}
|
|
|
|
|
2010-08-29 11:57:08 -07:00
|
|
|
inline js::Value *
|
|
|
|
JSObject::getFlatClosureUpvars() const
|
|
|
|
{
|
2010-12-29 20:21:18 -08:00
|
|
|
#ifdef DEBUG
|
|
|
|
JSFunction *fun = getFunctionPrivate();
|
|
|
|
JS_ASSERT(fun->isFlatClosure());
|
|
|
|
JS_ASSERT(fun->script()->bindings.countUpvars() == fun->script()->upvars()->length);
|
|
|
|
#endif
|
2010-10-13 11:49:22 -07:00
|
|
|
return (js::Value *) getSlot(JSSLOT_FLAT_CLOSURE_UPVARS).toPrivate();
|
2010-08-29 11:57:08 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
inline js::Value
|
|
|
|
JSObject::getFlatClosureUpvar(uint32 i) const
|
|
|
|
{
|
2010-11-16 15:34:24 -08:00
|
|
|
JS_ASSERT(i < getFunctionPrivate()->script()->bindings.countUpvars());
|
2010-08-29 11:57:08 -07:00
|
|
|
return getFlatClosureUpvars()[i];
|
|
|
|
}
|
|
|
|
|
2010-12-29 20:21:18 -08:00
|
|
|
inline js::Value &
|
|
|
|
JSObject::getFlatClosureUpvar(uint32 i)
|
|
|
|
{
|
|
|
|
JS_ASSERT(i < getFunctionPrivate()->script()->bindings.countUpvars());
|
|
|
|
return getFlatClosureUpvars()[i];
|
|
|
|
}
|
|
|
|
|
2010-08-29 11:57:08 -07:00
|
|
|
inline void
|
|
|
|
JSObject::setFlatClosureUpvars(js::Value *upvars)
|
|
|
|
{
|
|
|
|
JS_ASSERT(isFunction());
|
|
|
|
JS_ASSERT(FUN_FLAT_CLOSURE(getFunctionPrivate()));
|
2010-10-13 11:49:22 -07:00
|
|
|
getSlotRef(JSSLOT_FLAT_CLOSURE_UPVARS).setPrivate(upvars);
|
2010-08-29 11:57:08 -07:00
|
|
|
}
|
|
|
|
|
2010-08-01 09:58:03 -07:00
|
|
|
inline bool
|
|
|
|
JSObject::hasMethodObj(const JSObject& obj) const
|
|
|
|
{
|
2010-10-13 11:49:22 -07:00
|
|
|
return JSSLOT_FUN_METHOD_OBJ < numSlots() &&
|
2011-01-04 12:27:18 -08:00
|
|
|
getSlot(JSSLOT_FUN_METHOD_OBJ).isObject() &&
|
2011-04-08 10:52:48 -07:00
|
|
|
getSlot(JSSLOT_FUN_METHOD_OBJ).toObject() == obj;
|
2010-08-01 09:58:03 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
inline void
|
|
|
|
JSObject::setMethodObj(JSObject& obj)
|
|
|
|
{
|
2010-10-13 11:49:22 -07:00
|
|
|
getSlotRef(JSSLOT_FUN_METHOD_OBJ).setObject(obj);
|
2010-08-01 09:58:03 -07:00
|
|
|
}
|
|
|
|
|
2010-10-10 15:37:22 -07:00
|
|
|
inline js::NativeIterator *
|
2010-05-07 17:52:52 -07:00
|
|
|
JSObject::getNativeIterator() const
|
|
|
|
{
|
2010-10-10 15:37:22 -07:00
|
|
|
return (js::NativeIterator *) getPrivate();
|
2010-05-07 17:52:52 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
inline void
|
2010-10-10 15:37:22 -07:00
|
|
|
JSObject::setNativeIterator(js::NativeIterator *ni)
|
2010-05-07 17:52:52 -07:00
|
|
|
{
|
|
|
|
setPrivate(ni);
|
|
|
|
}
|
|
|
|
|
2010-12-06 10:26:58 -08:00
|
|
|
inline JSLinearString *
|
2010-05-12 18:57:36 -07:00
|
|
|
JSObject::getNamePrefix() const
|
2010-12-06 10:26:58 -08:00
|
|
|
{
|
|
|
|
JS_ASSERT(isNamespace() || isQName());
|
|
|
|
const js::Value &v = getSlot(JSSLOT_NAME_PREFIX);
|
2011-03-14 13:59:53 -07:00
|
|
|
return !v.isUndefined() ? &v.toString()->asLinear() : NULL;
|
2010-12-06 10:26:58 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
inline jsval
|
|
|
|
JSObject::getNamePrefixVal() const
|
2010-05-12 18:57:36 -07:00
|
|
|
{
|
|
|
|
JS_ASSERT(isNamespace() || isQName());
|
2010-10-13 11:49:22 -07:00
|
|
|
return js::Jsvalify(getSlot(JSSLOT_NAME_PREFIX));
|
2010-05-12 18:57:36 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
inline void
|
2010-12-06 10:26:58 -08:00
|
|
|
JSObject::setNamePrefix(JSLinearString *prefix)
|
2010-05-12 18:57:36 -07:00
|
|
|
{
|
|
|
|
JS_ASSERT(isNamespace() || isQName());
|
2010-12-06 10:26:58 -08:00
|
|
|
setSlot(JSSLOT_NAME_PREFIX, prefix ? js::StringValue(prefix) : js::UndefinedValue());
|
2010-05-12 18:57:36 -07:00
|
|
|
}
|
|
|
|
|
2010-12-06 10:26:58 -08:00
|
|
|
inline void
|
|
|
|
JSObject::clearNamePrefix()
|
|
|
|
{
|
|
|
|
JS_ASSERT(isNamespace() || isQName());
|
|
|
|
setSlot(JSSLOT_NAME_PREFIX, js::UndefinedValue());
|
|
|
|
}
|
|
|
|
|
|
|
|
inline JSLinearString *
|
2010-05-12 18:57:36 -07:00
|
|
|
JSObject::getNameURI() const
|
2010-12-06 10:26:58 -08:00
|
|
|
{
|
|
|
|
JS_ASSERT(isNamespace() || isQName());
|
|
|
|
const js::Value &v = getSlot(JSSLOT_NAME_URI);
|
2011-03-14 13:59:53 -07:00
|
|
|
return !v.isUndefined() ? &v.toString()->asLinear() : NULL;
|
2010-12-06 10:26:58 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
inline jsval
|
|
|
|
JSObject::getNameURIVal() const
|
2010-05-12 18:57:36 -07:00
|
|
|
{
|
|
|
|
JS_ASSERT(isNamespace() || isQName());
|
2010-10-13 11:49:22 -07:00
|
|
|
return js::Jsvalify(getSlot(JSSLOT_NAME_URI));
|
2010-05-12 18:57:36 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
inline void
|
2010-12-06 10:26:58 -08:00
|
|
|
JSObject::setNameURI(JSLinearString *uri)
|
2010-05-12 18:57:36 -07:00
|
|
|
{
|
|
|
|
JS_ASSERT(isNamespace() || isQName());
|
2010-12-06 10:26:58 -08:00
|
|
|
setSlot(JSSLOT_NAME_URI, uri ? js::StringValue(uri) : js::UndefinedValue());
|
2010-05-12 18:57:36 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
inline jsval
|
|
|
|
JSObject::getNamespaceDeclared() const
|
|
|
|
{
|
|
|
|
JS_ASSERT(isNamespace());
|
2010-10-13 11:49:22 -07:00
|
|
|
return js::Jsvalify(getSlot(JSSLOT_NAMESPACE_DECLARED));
|
2010-05-12 18:57:36 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
inline void
|
|
|
|
JSObject::setNamespaceDeclared(jsval decl)
|
|
|
|
{
|
|
|
|
JS_ASSERT(isNamespace());
|
2010-10-13 11:49:22 -07:00
|
|
|
setSlot(JSSLOT_NAMESPACE_DECLARED, js::Valueify(decl));
|
2010-05-12 18:57:36 -07:00
|
|
|
}
|
|
|
|
|
2010-12-06 10:26:58 -08:00
|
|
|
inline JSLinearString *
|
2010-05-12 18:57:36 -07:00
|
|
|
JSObject::getQNameLocalName() const
|
2010-12-06 10:26:58 -08:00
|
|
|
{
|
|
|
|
JS_ASSERT(isQName());
|
|
|
|
const js::Value &v = getSlot(JSSLOT_QNAME_LOCAL_NAME);
|
2011-03-14 13:59:53 -07:00
|
|
|
return !v.isUndefined() ? &v.toString()->asLinear() : NULL;
|
2010-12-06 10:26:58 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
inline jsval
|
|
|
|
JSObject::getQNameLocalNameVal() const
|
2010-05-12 18:57:36 -07:00
|
|
|
{
|
|
|
|
JS_ASSERT(isQName());
|
2010-10-13 11:49:22 -07:00
|
|
|
return js::Jsvalify(getSlot(JSSLOT_QNAME_LOCAL_NAME));
|
2010-05-12 18:57:36 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
inline void
|
2010-12-06 10:26:58 -08:00
|
|
|
JSObject::setQNameLocalName(JSLinearString *name)
|
2010-05-12 18:57:36 -07:00
|
|
|
{
|
|
|
|
JS_ASSERT(isQName());
|
2010-12-06 10:26:58 -08:00
|
|
|
setSlot(JSSLOT_QNAME_LOCAL_NAME, name ? js::StringValue(name) : js::UndefinedValue());
|
2010-05-12 18:57:36 -07:00
|
|
|
}
|
|
|
|
|
2010-06-08 14:09:40 -07:00
|
|
|
inline JSObject *
|
|
|
|
JSObject::getWithThis() const
|
|
|
|
{
|
2010-10-13 11:49:22 -07:00
|
|
|
return &getSlot(JSSLOT_WITH_THIS).toObject();
|
2010-06-08 14:09:40 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
inline void
|
|
|
|
JSObject::setWithThis(JSObject *thisp)
|
|
|
|
{
|
2010-10-13 11:49:22 -07:00
|
|
|
getSlotRef(JSSLOT_WITH_THIS).setObject(*thisp);
|
2010-06-08 14:09:40 -07:00
|
|
|
}
|
|
|
|
|
2009-11-18 12:29:58 -08:00
|
|
|
inline void
|
2010-10-13 11:49:22 -07:00
|
|
|
JSObject::init(JSContext *cx, js::Class *aclasp, JSObject *proto, JSObject *parent,
|
|
|
|
void *priv, bool useHoles)
|
2009-11-18 12:29:58 -08:00
|
|
|
{
|
2010-08-29 11:57:08 -07:00
|
|
|
clasp = aclasp;
|
2010-12-21 16:06:19 -08:00
|
|
|
flags = 0;
|
2009-11-18 12:29:58 -08:00
|
|
|
|
2010-08-29 11:57:08 -07:00
|
|
|
#ifdef DEBUG
|
|
|
|
/*
|
|
|
|
* NB: objShape must not be set here; rather, the caller must call setMap
|
|
|
|
* or setSharedNonNativeMap after calling init. To defend this requirement
|
2011-03-23 11:57:19 -07:00
|
|
|
* we set objShape to a value that obj->shape() is asserted never to return.
|
2010-08-29 11:57:08 -07:00
|
|
|
*/
|
|
|
|
objShape = JSObjectMap::INVALID_SHAPE;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
setProto(proto);
|
|
|
|
setParent(parent);
|
|
|
|
|
2010-10-13 11:49:22 -07:00
|
|
|
privateData = priv;
|
|
|
|
slots = fixedSlots();
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Fill the fixed slots with undefined or array holes. This object must
|
|
|
|
* already have its capacity filled in, as by js_NewGCObject.
|
|
|
|
*/
|
|
|
|
JS_ASSERT(capacity == numFixedSlots());
|
|
|
|
ClearValueRange(slots, capacity, useHoles);
|
2010-08-29 11:57:08 -07:00
|
|
|
|
2010-10-13 11:49:22 -07:00
|
|
|
emptyShapes = NULL;
|
2010-09-10 17:06:30 -07:00
|
|
|
}
|
|
|
|
|
2010-08-29 11:57:08 -07:00
|
|
|
inline void
|
|
|
|
JSObject::finish(JSContext *cx)
|
2009-11-18 12:29:58 -08:00
|
|
|
{
|
2010-08-29 11:57:08 -07:00
|
|
|
#ifdef DEBUG
|
|
|
|
if (isNative())
|
|
|
|
JS_LOCK_RUNTIME_VOID(cx->runtime, cx->runtime->liveObjectProps -= propertyCount());
|
|
|
|
#endif
|
|
|
|
if (hasSlotsArray())
|
|
|
|
freeSlotsArray(cx);
|
2010-10-13 16:10:15 -07:00
|
|
|
if (emptyShapes)
|
2011-03-31 01:14:12 -07:00
|
|
|
cx->free_(emptyShapes);
|
2010-08-29 11:57:08 -07:00
|
|
|
}
|
2009-11-18 12:29:58 -08:00
|
|
|
|
2010-10-13 11:49:22 -07:00
|
|
|
inline bool
|
|
|
|
JSObject::initSharingEmptyShape(JSContext *cx,
|
|
|
|
js::Class *aclasp,
|
2010-08-29 11:57:08 -07:00
|
|
|
JSObject *proto,
|
|
|
|
JSObject *parent,
|
2010-10-13 11:49:22 -07:00
|
|
|
void *privateValue,
|
|
|
|
/* js::gc::FinalizeKind */ unsigned kind)
|
2010-08-29 11:57:08 -07:00
|
|
|
{
|
2010-10-13 11:49:22 -07:00
|
|
|
init(cx, aclasp, proto, parent, privateValue, false);
|
|
|
|
|
|
|
|
JS_ASSERT(!isDenseArray());
|
|
|
|
|
|
|
|
js::EmptyShape *empty = proto->getEmptyShape(cx, aclasp, kind);
|
|
|
|
if (!empty)
|
|
|
|
return false;
|
2010-08-29 11:57:08 -07:00
|
|
|
|
|
|
|
setMap(empty);
|
2010-10-13 11:49:22 -07:00
|
|
|
return true;
|
2009-11-18 12:29:58 -08:00
|
|
|
}
|
|
|
|
|
2010-09-10 17:06:30 -07:00
|
|
|
inline void
|
2010-10-13 11:49:22 -07:00
|
|
|
JSObject::freeSlotsArray(JSContext *cx)
|
2010-09-10 17:06:30 -07:00
|
|
|
{
|
2010-10-13 11:49:22 -07:00
|
|
|
JS_ASSERT(hasSlotsArray());
|
2011-03-31 01:14:12 -07:00
|
|
|
cx->free_(slots);
|
2010-09-10 17:06:30 -07:00
|
|
|
}
|
|
|
|
|
2009-12-30 03:06:26 -08:00
|
|
|
inline void
|
2010-10-13 11:49:22 -07:00
|
|
|
JSObject::revertToFixedSlots(JSContext *cx)
|
2009-12-30 03:06:26 -08:00
|
|
|
{
|
|
|
|
JS_ASSERT(hasSlotsArray());
|
2010-10-13 11:49:22 -07:00
|
|
|
size_t fixed = numFixedSlots();
|
|
|
|
JS_ASSERT(capacity >= fixed);
|
|
|
|
memcpy(fixedSlots(), slots, fixed * sizeof(js::Value));
|
|
|
|
freeSlotsArray(cx);
|
|
|
|
slots = fixedSlots();
|
|
|
|
capacity = fixed;
|
2009-12-30 03:06:26 -08:00
|
|
|
}
|
|
|
|
|
2010-01-14 09:33:14 -08:00
|
|
|
inline bool
|
2010-08-29 11:57:08 -07:00
|
|
|
JSObject::hasProperty(JSContext *cx, jsid id, bool *foundp, uintN flags)
|
|
|
|
{
|
|
|
|
JSObject *pobj;
|
|
|
|
JSProperty *prop;
|
|
|
|
JSAutoResolveFlags rf(cx, flags);
|
|
|
|
if (!lookupProperty(cx, id, &pobj, &prop))
|
|
|
|
return false;
|
|
|
|
*foundp = !!prop;
|
2010-01-14 09:33:14 -08:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2010-08-29 11:57:08 -07:00
|
|
|
inline bool
|
|
|
|
JSObject::isCallable()
|
|
|
|
{
|
|
|
|
return isFunction() || getClass()->call;
|
|
|
|
}
|
|
|
|
|
2011-04-08 10:52:51 -07:00
|
|
|
inline JSPrincipals *
|
|
|
|
JSObject::principals(JSContext *cx)
|
|
|
|
{
|
|
|
|
JSPrincipals *compPrincipals = compartment()->principals;
|
|
|
|
#ifdef DEBUG
|
|
|
|
if (!compPrincipals)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Assert that the compartment's principals are either the same or
|
|
|
|
* equivalent to those we would find through security hooks.
|
|
|
|
*/
|
|
|
|
JSSecurityCallbacks *cb = JS_GetSecurityCallbacks(cx);
|
|
|
|
if (JSObjectPrincipalsFinder finder = cb ? cb->findObjectPrincipals : NULL) {
|
|
|
|
JSPrincipals *hookPrincipals = finder(cx, this);
|
|
|
|
JS_ASSERT(hookPrincipals == compPrincipals ||
|
|
|
|
(hookPrincipals->subsume(hookPrincipals, compPrincipals) &&
|
|
|
|
compPrincipals->subsume(compPrincipals, hookPrincipals)));
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
return compPrincipals;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline JSPrincipals *
|
|
|
|
JSStackFrame::principals(JSContext *cx) const
|
|
|
|
{
|
|
|
|
return scopeChain().principals(cx);
|
|
|
|
}
|
|
|
|
|
2010-08-29 11:57:08 -07:00
|
|
|
static inline bool
|
|
|
|
js_IsCallable(const js::Value &v)
|
2010-01-14 09:33:14 -08:00
|
|
|
{
|
2010-08-29 11:57:08 -07:00
|
|
|
return v.isObject() && v.toObject().isCallable();
|
|
|
|
}
|
|
|
|
|
2010-03-28 20:32:20 -07:00
|
|
|
namespace js {
|
|
|
|
|
2010-07-14 23:19:36 -07:00
|
|
|
class AutoPropDescArrayRooter : private AutoGCRooter
|
2010-03-28 20:32:20 -07:00
|
|
|
{
|
|
|
|
public:
|
2010-07-14 23:19:36 -07:00
|
|
|
AutoPropDescArrayRooter(JSContext *cx)
|
2010-03-28 20:32:20 -07:00
|
|
|
: AutoGCRooter(cx, DESCRIPTORS), descriptors(cx)
|
|
|
|
{ }
|
|
|
|
|
2010-07-14 23:19:36 -07:00
|
|
|
PropDesc *append() {
|
|
|
|
if (!descriptors.append(PropDesc()))
|
2010-03-28 20:32:20 -07:00
|
|
|
return NULL;
|
|
|
|
return &descriptors.back();
|
|
|
|
}
|
|
|
|
|
2010-07-14 23:19:36 -07:00
|
|
|
PropDesc& operator[](size_t i) {
|
2010-03-28 20:32:20 -07:00
|
|
|
JS_ASSERT(i < descriptors.length());
|
|
|
|
return descriptors[i];
|
|
|
|
}
|
|
|
|
|
|
|
|
friend void AutoGCRooter::trace(JSTracer *trc);
|
|
|
|
|
|
|
|
private:
|
2010-07-14 23:19:36 -07:00
|
|
|
PropDescArray descriptors;
|
2010-03-28 20:32:20 -07:00
|
|
|
};
|
|
|
|
|
2010-07-14 23:19:36 -07:00
|
|
|
class AutoPropertyDescriptorRooter : private AutoGCRooter, public PropertyDescriptor
|
2010-05-18 19:21:43 -07:00
|
|
|
{
|
|
|
|
public:
|
2010-07-14 23:19:36 -07:00
|
|
|
AutoPropertyDescriptorRooter(JSContext *cx) : AutoGCRooter(cx, DESCRIPTOR) {
|
2010-05-18 19:21:43 -07:00
|
|
|
obj = NULL;
|
|
|
|
attrs = 0;
|
2011-02-09 11:31:40 -08:00
|
|
|
getter = (PropertyOp) NULL;
|
|
|
|
setter = (StrictPropertyOp) NULL;
|
2010-07-14 23:19:36 -07:00
|
|
|
value.setUndefined();
|
2010-05-18 19:21:43 -07:00
|
|
|
}
|
|
|
|
|
2010-08-29 11:57:08 -07:00
|
|
|
AutoPropertyDescriptorRooter(JSContext *cx, PropertyDescriptor *desc)
|
|
|
|
: AutoGCRooter(cx, DESCRIPTOR)
|
|
|
|
{
|
2010-06-23 14:35:10 -07:00
|
|
|
obj = desc->obj;
|
|
|
|
attrs = desc->attrs;
|
|
|
|
getter = desc->getter;
|
|
|
|
setter = desc->setter;
|
|
|
|
value = desc->value;
|
|
|
|
}
|
|
|
|
|
2010-05-18 19:21:43 -07:00
|
|
|
friend void AutoGCRooter::trace(JSTracer *trc);
|
|
|
|
};
|
|
|
|
|
2010-04-10 16:16:35 -07:00
|
|
|
static inline bool
|
2010-10-13 11:49:22 -07:00
|
|
|
InitScopeForObject(JSContext* cx, JSObject* obj, js::Class *clasp, JSObject* proto,
|
|
|
|
gc::FinalizeKind kind)
|
2010-04-10 16:16:35 -07:00
|
|
|
{
|
2010-06-12 09:29:04 -07:00
|
|
|
JS_ASSERT(clasp->isNative());
|
2010-04-10 16:16:35 -07:00
|
|
|
JS_ASSERT(proto == obj->getProto());
|
|
|
|
|
2010-08-29 11:57:08 -07:00
|
|
|
/* Share proto's emptyShape only if obj is similar to proto. */
|
|
|
|
js::EmptyShape *empty = NULL;
|
2010-04-10 16:16:35 -07:00
|
|
|
|
2010-08-29 11:57:08 -07:00
|
|
|
if (proto) {
|
|
|
|
if (proto->canProvideEmptyShape(clasp)) {
|
2010-10-13 11:49:22 -07:00
|
|
|
empty = proto->getEmptyShape(cx, clasp, kind);
|
2010-08-29 11:57:08 -07:00
|
|
|
if (!empty)
|
2010-04-10 16:16:35 -07:00
|
|
|
goto bad;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-08-29 11:57:08 -07:00
|
|
|
if (!empty) {
|
|
|
|
empty = js::EmptyShape::create(cx, clasp);
|
|
|
|
if (!empty)
|
|
|
|
goto bad;
|
2010-10-13 11:49:22 -07:00
|
|
|
uint32 freeslot = JSSLOT_FREE(clasp);
|
|
|
|
if (freeslot > obj->numSlots() && !obj->allocSlots(cx, freeslot))
|
2010-04-10 16:16:35 -07:00
|
|
|
goto bad;
|
|
|
|
}
|
|
|
|
|
2010-08-29 11:57:08 -07:00
|
|
|
obj->setMap(empty);
|
2010-04-10 16:16:35 -07:00
|
|
|
return true;
|
|
|
|
|
|
|
|
bad:
|
|
|
|
/* The GC nulls map initially. It should still be null on error. */
|
|
|
|
JS_ASSERT(!obj->map);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2010-06-18 17:43:02 -07:00
|
|
|
/*
|
|
|
|
* Helper optimized for creating a native instance of the given class (not the
|
2010-08-09 09:11:22 -07:00
|
|
|
* class's prototype object). Use this in preference to NewObject, but use
|
|
|
|
* NewBuiltinClassInstance if you need the default class prototype as proto,
|
|
|
|
* and its parent global as parent.
|
2010-06-18 17:43:02 -07:00
|
|
|
*/
|
2010-04-10 16:16:35 -07:00
|
|
|
static inline JSObject *
|
2010-10-13 11:49:22 -07:00
|
|
|
NewNativeClassInstance(JSContext *cx, Class *clasp, JSObject *proto,
|
|
|
|
JSObject *parent, gc::FinalizeKind kind)
|
2010-06-18 17:43:02 -07:00
|
|
|
{
|
|
|
|
JS_ASSERT(proto);
|
|
|
|
JS_ASSERT(parent);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Allocate an object from the GC heap and initialize all its fields before
|
2010-08-09 09:11:22 -07:00
|
|
|
* doing any operation that can potentially trigger GC.
|
2010-06-18 17:43:02 -07:00
|
|
|
*/
|
2010-10-13 11:49:22 -07:00
|
|
|
JSObject* obj = js_NewGCObject(cx, kind);
|
2010-08-09 09:11:22 -07:00
|
|
|
|
2010-06-18 17:43:02 -07:00
|
|
|
if (obj) {
|
|
|
|
/*
|
|
|
|
* Default parent to the parent of the prototype, which was set from
|
|
|
|
* the parent of the prototype's constructor.
|
|
|
|
*/
|
2010-10-13 11:49:22 -07:00
|
|
|
bool useHoles = (clasp == &js_ArrayClass);
|
|
|
|
obj->init(cx, clasp, proto, parent, NULL, useHoles);
|
2010-06-18 17:43:02 -07:00
|
|
|
|
2010-08-29 11:57:08 -07:00
|
|
|
JS_ASSERT(proto->canProvideEmptyShape(clasp));
|
2010-10-13 11:49:22 -07:00
|
|
|
js::EmptyShape *empty = proto->getEmptyShape(cx, clasp, kind);
|
2010-06-18 17:43:02 -07:00
|
|
|
|
2010-08-29 11:57:08 -07:00
|
|
|
if (empty)
|
|
|
|
obj->setMap(empty);
|
|
|
|
else
|
2010-06-18 17:43:02 -07:00
|
|
|
obj = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return obj;
|
|
|
|
}
|
|
|
|
|
2010-10-13 11:49:22 -07:00
|
|
|
static inline JSObject *
|
|
|
|
NewNativeClassInstance(JSContext *cx, Class *clasp, JSObject *proto, JSObject *parent)
|
|
|
|
{
|
|
|
|
gc::FinalizeKind kind = gc::GetGCObjectKind(JSCLASS_RESERVED_SLOTS(clasp));
|
|
|
|
return NewNativeClassInstance(cx, clasp, proto, parent, kind);
|
|
|
|
}
|
|
|
|
|
2010-06-18 17:43:02 -07:00
|
|
|
bool
|
|
|
|
FindClassPrototype(JSContext *cx, JSObject *scope, JSProtoKey protoKey, JSObject **protop,
|
2010-07-14 23:19:36 -07:00
|
|
|
Class *clasp);
|
2010-06-18 17:43:02 -07:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Helper used to create Boolean, Date, RegExp, etc. instances of built-in
|
2010-07-14 23:19:36 -07:00
|
|
|
* classes with class prototypes of the same Class. See, e.g., jsdate.cpp,
|
2010-06-18 17:43:02 -07:00
|
|
|
* jsregexp.cpp, and js_PrimitiveToObject in jsobj.cpp. Use this to get the
|
|
|
|
* right default proto and parent for clasp in cx.
|
|
|
|
*/
|
|
|
|
static inline JSObject *
|
2010-10-13 11:49:22 -07:00
|
|
|
NewBuiltinClassInstance(JSContext *cx, Class *clasp, gc::FinalizeKind kind)
|
2010-06-18 17:43:02 -07:00
|
|
|
{
|
|
|
|
VOUCH_DOES_NOT_REQUIRE_STACK();
|
|
|
|
|
|
|
|
JSProtoKey protoKey = JSCLASS_CACHED_PROTO_KEY(clasp);
|
|
|
|
JS_ASSERT(protoKey != JSProto_Null);
|
|
|
|
|
|
|
|
/* NB: inline-expanded and specialized version of js_GetClassPrototype. */
|
2011-02-19 19:50:19 -08:00
|
|
|
JSObject *global;
|
|
|
|
if (!cx->hasfp()) {
|
|
|
|
global = cx->globalObject;
|
|
|
|
OBJ_TO_INNER_OBJECT(cx, global);
|
|
|
|
if (!global)
|
|
|
|
return NULL;
|
|
|
|
} else {
|
|
|
|
global = cx->fp()->scopeChain().getGlobal();
|
|
|
|
}
|
2011-01-08 15:01:52 -08:00
|
|
|
JS_ASSERT(global->isGlobal());
|
2010-06-18 17:43:02 -07:00
|
|
|
|
2010-07-14 23:19:36 -07:00
|
|
|
const Value &v = global->getReservedSlot(JSProto_LIMIT + protoKey);
|
2010-06-18 17:43:02 -07:00
|
|
|
JSObject *proto;
|
2010-07-14 23:19:36 -07:00
|
|
|
if (v.isObject()) {
|
|
|
|
proto = &v.toObject();
|
2010-06-18 17:43:02 -07:00
|
|
|
JS_ASSERT(proto->getParent() == global);
|
|
|
|
} else {
|
|
|
|
if (!FindClassPrototype(cx, global, protoKey, &proto, clasp))
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2010-10-13 11:49:22 -07:00
|
|
|
return NewNativeClassInstance(cx, clasp, proto, global, kind);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline JSObject *
|
|
|
|
NewBuiltinClassInstance(JSContext *cx, Class *clasp)
|
|
|
|
{
|
|
|
|
gc::FinalizeKind kind = gc::GetGCObjectKind(JSCLASS_RESERVED_SLOTS(clasp));
|
|
|
|
return NewBuiltinClassInstance(cx, clasp, kind);
|
2010-06-18 17:43:02 -07:00
|
|
|
}
|
|
|
|
|
2010-08-09 09:11:22 -07:00
|
|
|
static inline JSProtoKey
|
|
|
|
GetClassProtoKey(js::Class *clasp)
|
|
|
|
{
|
|
|
|
JSProtoKey key = JSCLASS_CACHED_PROTO_KEY(clasp);
|
|
|
|
if (key != JSProto_Null)
|
|
|
|
return key;
|
|
|
|
if (clasp->flags & JSCLASS_IS_ANONYMOUS)
|
|
|
|
return JSProto_Object;
|
|
|
|
return JSProto_Null;
|
|
|
|
}
|
|
|
|
|
|
|
|
namespace WithProto {
|
|
|
|
enum e {
|
|
|
|
Class = 0,
|
|
|
|
Given = 1
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2010-06-18 17:43:02 -07:00
|
|
|
/*
|
2010-08-09 09:11:22 -07:00
|
|
|
* Create an instance of any class, native or not, JSFunction-sized or not.
|
|
|
|
*
|
|
|
|
* If withProto is 'Class':
|
|
|
|
* If proto is null:
|
|
|
|
* for a built-in class:
|
|
|
|
* use the memoized original value of the class constructor .prototype
|
|
|
|
* property object
|
|
|
|
* else if available
|
|
|
|
* the current value of .prototype
|
|
|
|
* else
|
|
|
|
* Object.prototype.
|
|
|
|
*
|
|
|
|
* If parent is null, default it to proto->getParent() if proto is non
|
|
|
|
* null, else to null.
|
|
|
|
*
|
|
|
|
* If withProto is 'Given':
|
|
|
|
* We allocate an object with exactly the given proto. A null parent
|
|
|
|
* defaults to proto->getParent() if proto is non-null (else to null).
|
|
|
|
*
|
|
|
|
* If isFunction is true, return a JSFunction-sized object. If isFunction is
|
|
|
|
* false, return a normal object.
|
|
|
|
*
|
|
|
|
* Note that as a template, there will be lots of instantiations, which means
|
|
|
|
* the internals will be specialized based on the template parameters.
|
2010-06-18 17:43:02 -07:00
|
|
|
*/
|
2010-12-13 16:22:59 -08:00
|
|
|
static JS_ALWAYS_INLINE bool
|
|
|
|
FindProto(JSContext *cx, js::Class *clasp, JSObject *parent, JSObject ** proto)
|
|
|
|
{
|
|
|
|
JSProtoKey protoKey = GetClassProtoKey(clasp);
|
|
|
|
if (!js_GetClassPrototype(cx, parent, protoKey, proto, clasp))
|
|
|
|
return false;
|
|
|
|
if (!(*proto) && !js_GetClassPrototype(cx, parent, JSProto_Object, proto))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2010-08-09 09:11:22 -07:00
|
|
|
namespace detail
|
|
|
|
{
|
|
|
|
template <bool withProto, bool isFunction>
|
|
|
|
static JS_ALWAYS_INLINE JSObject *
|
2010-10-13 11:49:22 -07:00
|
|
|
NewObject(JSContext *cx, js::Class *clasp, JSObject *proto, JSObject *parent,
|
|
|
|
gc::FinalizeKind kind)
|
2010-04-10 16:16:35 -07:00
|
|
|
{
|
2010-08-09 09:11:22 -07:00
|
|
|
/* Bootstrap the ur-object, and make it the default prototype object. */
|
|
|
|
if (withProto == WithProto::Class && !proto) {
|
2011-01-24 15:32:44 -08:00
|
|
|
if (!FindProto(cx, clasp, parent, &proto))
|
2010-12-13 16:22:59 -08:00
|
|
|
return NULL;
|
2010-10-13 11:49:22 -07:00
|
|
|
}
|
2010-08-09 09:11:22 -07:00
|
|
|
|
2010-04-10 16:16:35 -07:00
|
|
|
/*
|
|
|
|
* Allocate an object from the GC heap and initialize all its fields before
|
|
|
|
* doing any operation that can potentially trigger GC. Functions have a
|
|
|
|
* larger non-standard allocation size.
|
2010-08-09 09:11:22 -07:00
|
|
|
*
|
|
|
|
* The should be specialized by the template.
|
2010-04-10 16:16:35 -07:00
|
|
|
*/
|
2010-10-13 11:49:22 -07:00
|
|
|
JSObject* obj = isFunction ? js_NewGCFunction(cx) : js_NewGCObject(cx, kind);
|
2010-04-10 16:16:35 -07:00
|
|
|
if (!obj)
|
|
|
|
goto out;
|
|
|
|
|
2010-10-13 11:49:22 -07:00
|
|
|
/* This needs to match up with the size of JSFunction::data_padding. */
|
|
|
|
JS_ASSERT_IF(isFunction, kind == gc::FINALIZE_OBJECT2);
|
|
|
|
|
2010-04-10 16:16:35 -07:00
|
|
|
/*
|
|
|
|
* Default parent to the parent of the prototype, which was set from
|
|
|
|
* the parent of the prototype's constructor.
|
|
|
|
*/
|
2010-10-13 11:49:22 -07:00
|
|
|
obj->init(cx, clasp, proto,
|
|
|
|
(!parent && proto) ? proto->getParent() : parent,
|
|
|
|
NULL, clasp == &js_ArrayClass);
|
2010-04-10 16:16:35 -07:00
|
|
|
|
2010-06-12 09:29:04 -07:00
|
|
|
if (clasp->isNative()) {
|
2010-10-13 11:49:22 -07:00
|
|
|
if (!InitScopeForObject(cx, obj, clasp, proto, kind)) {
|
2010-04-10 16:16:35 -07:00
|
|
|
obj = NULL;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
} else {
|
2010-08-29 11:57:08 -07:00
|
|
|
obj->setSharedNonNativeMap();
|
2010-04-10 16:16:35 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
out:
|
2010-09-01 14:09:54 -07:00
|
|
|
Probes::createObject(cx, obj);
|
2010-04-10 16:16:35 -07:00
|
|
|
return obj;
|
|
|
|
}
|
2010-10-13 11:49:22 -07:00
|
|
|
} /* namespace detail */
|
2010-09-20 11:40:32 -07:00
|
|
|
|
|
|
|
static JS_ALWAYS_INLINE JSObject *
|
2010-09-20 12:05:21 -07:00
|
|
|
NewFunction(JSContext *cx, JSObject *parent)
|
2010-09-20 11:40:32 -07:00
|
|
|
{
|
2010-10-13 11:49:22 -07:00
|
|
|
return detail::NewObject<WithProto::Class, true>(cx, &js_FunctionClass, NULL, parent,
|
|
|
|
gc::FINALIZE_OBJECT2);
|
|
|
|
}
|
|
|
|
|
|
|
|
template <WithProto::e withProto>
|
|
|
|
static JS_ALWAYS_INLINE JSObject *
|
|
|
|
NewNonFunction(JSContext *cx, js::Class *clasp, JSObject *proto, JSObject *parent,
|
|
|
|
gc::FinalizeKind kind)
|
|
|
|
{
|
|
|
|
return detail::NewObject<withProto, false>(cx, clasp, proto, parent, kind);
|
2010-04-10 16:16:35 -07:00
|
|
|
}
|
|
|
|
|
2010-08-09 09:11:22 -07:00
|
|
|
template <WithProto::e withProto>
|
|
|
|
static JS_ALWAYS_INLINE JSObject *
|
|
|
|
NewNonFunction(JSContext *cx, js::Class *clasp, JSObject *proto, JSObject *parent)
|
|
|
|
{
|
2010-10-13 11:49:22 -07:00
|
|
|
gc::FinalizeKind kind = gc::GetGCObjectKind(JSCLASS_RESERVED_SLOTS(clasp));
|
|
|
|
return detail::NewObject<withProto, false>(cx, clasp, proto, parent, kind);
|
|
|
|
}
|
|
|
|
|
|
|
|
template <WithProto::e withProto>
|
|
|
|
static JS_ALWAYS_INLINE JSObject *
|
|
|
|
NewObject(JSContext *cx, js::Class *clasp, JSObject *proto, JSObject *parent,
|
|
|
|
gc::FinalizeKind kind)
|
|
|
|
{
|
|
|
|
if (clasp == &js_FunctionClass)
|
|
|
|
return detail::NewObject<withProto, true>(cx, clasp, proto, parent, kind);
|
|
|
|
return detail::NewObject<withProto, false>(cx, clasp, proto, parent, kind);
|
2010-08-09 09:11:22 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
template <WithProto::e withProto>
|
|
|
|
static JS_ALWAYS_INLINE JSObject *
|
2010-07-14 23:19:36 -07:00
|
|
|
NewObject(JSContext *cx, js::Class *clasp, JSObject *proto, JSObject *parent)
|
2010-04-10 16:16:35 -07:00
|
|
|
{
|
2010-10-13 11:49:22 -07:00
|
|
|
gc::FinalizeKind kind = gc::GetGCObjectKind(JSCLASS_RESERVED_SLOTS(clasp));
|
|
|
|
return NewObject<withProto>(cx, clasp, proto, parent, kind);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2011-01-24 15:32:44 -08:00
|
|
|
* As for gc::GetGCObjectKind, where numSlots is a guess at the final size of
|
2010-10-13 11:49:22 -07:00
|
|
|
* the object, zero if the final size is unknown.
|
|
|
|
*/
|
|
|
|
static inline gc::FinalizeKind
|
|
|
|
GuessObjectGCKind(size_t numSlots, bool isArray)
|
|
|
|
{
|
|
|
|
if (numSlots)
|
|
|
|
return gc::GetGCObjectKind(numSlots);
|
|
|
|
return isArray ? gc::FINALIZE_OBJECT8 : gc::FINALIZE_OBJECT4;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Get the GC kind to use for scripted 'new' on the given class.
|
|
|
|
* FIXME bug 547327: estimate the size from the allocation site.
|
|
|
|
*/
|
|
|
|
static inline gc::FinalizeKind
|
|
|
|
NewObjectGCKind(JSContext *cx, js::Class *clasp)
|
|
|
|
{
|
|
|
|
if (clasp == &js_ArrayClass || clasp == &js_SlowArrayClass)
|
|
|
|
return gc::FINALIZE_OBJECT8;
|
|
|
|
if (clasp == &js_FunctionClass)
|
|
|
|
return gc::FINALIZE_OBJECT2;
|
|
|
|
return gc::FINALIZE_OBJECT4;
|
2010-04-10 16:16:35 -07:00
|
|
|
}
|
|
|
|
|
2010-11-18 18:14:22 -08:00
|
|
|
/* Make an object with pregenerated shape from a NEWOBJECT bytecode. */
|
|
|
|
static inline JSObject *
|
|
|
|
CopyInitializerObject(JSContext *cx, JSObject *baseobj)
|
|
|
|
{
|
|
|
|
JS_ASSERT(baseobj->getClass() == &js_ObjectClass);
|
|
|
|
JS_ASSERT(!baseobj->inDictionaryMode());
|
|
|
|
|
2010-11-15 17:21:25 -08:00
|
|
|
gc::FinalizeKind kind = gc::FinalizeKind(baseobj->finalizeKind());
|
2010-11-18 18:14:22 -08:00
|
|
|
JSObject *obj = NewBuiltinClassInstance(cx, &js_ObjectClass, kind);
|
|
|
|
|
|
|
|
if (!obj || !obj->ensureSlots(cx, baseobj->numSlots()))
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
obj->flags = baseobj->flags;
|
|
|
|
obj->lastProp = baseobj->lastProp;
|
|
|
|
obj->objShape = baseobj->objShape;
|
|
|
|
|
|
|
|
return obj;
|
|
|
|
}
|
|
|
|
|
2011-01-26 13:37:45 -08:00
|
|
|
/*
|
|
|
|
* When we have an object of a builtin class, we don't quite know what its
|
|
|
|
* valueOf/toString methods are, since these methods may have been overwritten
|
|
|
|
* or shadowed. However, we can still do better than js_TryMethod by
|
|
|
|
* hard-coding the necessary properties for us to find the native we expect.
|
|
|
|
*
|
|
|
|
* TODO: a per-thread shape-based cache would be faster and simpler.
|
|
|
|
*/
|
|
|
|
static JS_ALWAYS_INLINE bool
|
|
|
|
ClassMethodIsNative(JSContext *cx, JSObject *obj, Class *clasp, jsid methodid,
|
|
|
|
Native native)
|
|
|
|
{
|
|
|
|
JS_ASSERT(obj->getClass() == clasp);
|
|
|
|
|
|
|
|
if (HasNativeMethod(obj, methodid, native))
|
|
|
|
return true;
|
|
|
|
|
|
|
|
JSObject *pobj = obj->getProto();
|
|
|
|
return pobj && pobj->getClass() == clasp &&
|
|
|
|
HasNativeMethod(pobj, methodid, native);
|
|
|
|
}
|
|
|
|
|
2011-03-05 15:29:30 -08:00
|
|
|
inline bool
|
|
|
|
DefineConstructorAndPrototype(JSContext *cx, JSObject *global,
|
|
|
|
JSProtoKey key, JSFunction *ctor, JSObject *proto)
|
|
|
|
{
|
|
|
|
JS_ASSERT(global->isGlobal());
|
|
|
|
JS_ASSERT(!global->nativeEmpty()); /* reserved slots already allocated */
|
|
|
|
JS_ASSERT(ctor);
|
|
|
|
JS_ASSERT(proto);
|
|
|
|
|
|
|
|
jsid id = ATOM_TO_JSID(cx->runtime->atomState.classAtoms[key]);
|
|
|
|
JS_ASSERT(!global->nativeLookup(id));
|
|
|
|
|
|
|
|
if (!global->addDataProperty(cx, id, key + JSProto_LIMIT * 2, 0))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
global->setSlot(key, ObjectValue(*ctor));
|
|
|
|
global->setSlot(key + JSProto_LIMIT, ObjectValue(*proto));
|
|
|
|
global->setSlot(key + JSProto_LIMIT * 2, ObjectValue(*ctor));
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2010-06-18 17:43:02 -07:00
|
|
|
} /* namespace js */
|
2010-03-28 20:32:20 -07:00
|
|
|
|
2009-11-18 12:29:58 -08:00
|
|
|
#endif /* jsobjinlines_h___ */
|