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-12-07 17:11:37 -08:00
|
|
|
#include "jsarray.h"
|
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"
|
2011-04-13 13:43:33 -07:00
|
|
|
#include "jstypedarray.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"
|
2010-10-29 08:05:55 -07:00
|
|
|
#include "jsinferinlines.h"
|
2010-04-10 16:16:35 -07:00
|
|
|
#include "jsscopeinlines.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-04-28 16:08:22 -07:00
|
|
|
#include "vm/GlobalObject.h"
|
|
|
|
|
2011-08-10 14:54:51 -07:00
|
|
|
#include "jsatominlines.h"
|
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;
|
|
|
|
}
|
|
|
|
|
2011-09-28 15:04:55 -07:00
|
|
|
if (isNative() && !extensibleShapeChange(cx))
|
2010-08-29 11:57:08 -07:00
|
|
|
return false;
|
|
|
|
|
2011-09-28 15:04:55 -07:00
|
|
|
flags |= NOT_EXTENSIBLE;
|
2010-08-29 11:57:08 -07:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2011-04-11 20:10:46 -07:00
|
|
|
inline JSBool
|
|
|
|
JSObject::setAttributes(JSContext *cx, jsid id, uintN *attrsp)
|
|
|
|
{
|
2011-07-15 10:14:07 -07:00
|
|
|
js::types::MarkTypePropertyConfigured(cx, this, id);
|
2011-04-11 20:10:46 -07:00
|
|
|
js::AttributesOp op = getOps()->setAttributes;
|
|
|
|
return (op ? op : js_SetAttributes)(cx, this, id, attrsp);
|
|
|
|
}
|
|
|
|
|
2011-05-16 16:15:37 -07:00
|
|
|
inline JSBool
|
2011-09-15 11:44:10 -07:00
|
|
|
JSObject::getGeneric(JSContext *cx, JSObject *receiver, jsid id, js::Value *vp)
|
2011-05-16 16:15:37 -07:00
|
|
|
{
|
2011-09-15 11:44:10 -07:00
|
|
|
js::GenericIdOp op = getOps()->getGeneric;
|
2011-05-16 16:15:37 -07:00
|
|
|
if (op) {
|
|
|
|
if (!op(cx, this, receiver, id, vp))
|
|
|
|
return false;
|
|
|
|
} else {
|
|
|
|
if (!js_GetProperty(cx, this, receiver, id, vp))
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline JSBool
|
2011-09-15 11:44:10 -07:00
|
|
|
JSObject::getProperty(JSContext *cx, JSObject *receiver, js::PropertyName *name, js::Value *vp)
|
2011-05-16 16:15:37 -07:00
|
|
|
{
|
2011-09-15 11:44:10 -07:00
|
|
|
return getGeneric(cx, receiver, ATOM_TO_JSID(name), vp);
|
|
|
|
}
|
|
|
|
|
|
|
|
inline JSBool
|
|
|
|
JSObject::getGeneric(JSContext *cx, jsid id, js::Value *vp)
|
|
|
|
{
|
|
|
|
return getGeneric(cx, this, id, vp);
|
|
|
|
}
|
|
|
|
|
|
|
|
inline JSBool
|
|
|
|
JSObject::getProperty(JSContext *cx, js::PropertyName *name, js::Value *vp)
|
|
|
|
{
|
|
|
|
return getGeneric(cx, ATOM_TO_JSID(name), vp);
|
2011-05-16 16:15:37 -07:00
|
|
|
}
|
|
|
|
|
2011-03-21 22:55:27 -07:00
|
|
|
inline JSBool
|
|
|
|
JSObject::deleteProperty(JSContext *cx, jsid id, js::Value *rval, JSBool strict)
|
|
|
|
{
|
2011-07-15 10:14:07 -07:00
|
|
|
js::types::AddTypePropertyId(cx, this, id,
|
|
|
|
js::types::Type::UndefinedType());
|
|
|
|
js::types::MarkTypePropertyConfigured(cx, this, id);
|
2011-03-21 22:55:27 -07:00
|
|
|
js::DeleteIdOp op = getOps()->deleteProperty;
|
|
|
|
return (op ? op : js_DeleteProperty)(cx, this, id, rval, strict);
|
|
|
|
}
|
|
|
|
|
2010-09-24 10:54:39 -07:00
|
|
|
inline void
|
2010-11-12 10:40:12 -08:00
|
|
|
JSObject::syncSpecialEquality()
|
2010-09-24 10:54:39 -07:00
|
|
|
{
|
2011-07-28 18:10:31 -07:00
|
|
|
if (getClass()->ext.equality) {
|
2010-11-12 10:40:12 -08:00
|
|
|
flags |= JSObject::HAS_EQUALITY;
|
2011-07-15 10:14:07 -07:00
|
|
|
JS_ASSERT_IF(!hasLazyType(), type()->hasAnyFlags(js::types::OBJECT_FLAG_SPECIAL_EQUALITY));
|
2011-03-19 16:53:07 -07:00
|
|
|
}
|
2010-11-12 10:40:12 -08:00
|
|
|
}
|
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. */
|
2011-04-08 14:21:08 -07:00
|
|
|
if (isNewborn())
|
2010-09-24 10:54:39 -07:00
|
|
|
return;
|
|
|
|
|
2010-09-20 12:43:53 -07:00
|
|
|
js::Probes::finalizeObject(this);
|
|
|
|
|
2010-09-24 10:54:39 -07:00
|
|
|
/* Finalize obj first, in case it needs map and slots. */
|
|
|
|
js::Class *clasp = getClass();
|
|
|
|
if (clasp->finalize)
|
|
|
|
clasp->finalize(cx, 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.
|
|
|
|
*/
|
2011-09-28 15:04:55 -07:00
|
|
|
inline bool
|
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
|
|
|
{
|
2011-09-02 17:23:26 -07:00
|
|
|
init(cx, &js::CallClass, &js::types::emptyTypeObject, parent, NULL, false);
|
2011-09-28 15:04:55 -07:00
|
|
|
setMap(bindings.lastShape());
|
2011-03-15 12:18:36 -07:00
|
|
|
|
|
|
|
/*
|
|
|
|
* If |bindings| is for a function that has extensible parents, that means
|
2011-09-28 15:04:55 -07:00
|
|
|
* its Call should have its own shape; see js::BaseShape::extensibleParents.
|
2011-03-15 12:18:36 -07:00
|
|
|
*/
|
2011-09-28 15:04:55 -07:00
|
|
|
if (lastProp->extensibleParents())
|
|
|
|
return generateOwnShape(cx);
|
|
|
|
return true;
|
2011-03-15 12:18:36 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Initializer for cloned block objects. Set class, prototype, frame, map, and
|
|
|
|
* shape.
|
|
|
|
*/
|
2011-09-28 15:04:55 -07:00
|
|
|
inline bool
|
2011-04-28 13:02:47 -07:00
|
|
|
JSObject::initClonedBlock(JSContext *cx, js::types::TypeObject *type, js::StackFrame *frame)
|
2011-03-15 12:18:36 -07:00
|
|
|
{
|
2011-09-02 17:23:26 -07:00
|
|
|
init(cx, &js::BlockClass, type, NULL, frame, false);
|
2011-03-15 12:18:36 -07:00
|
|
|
|
|
|
|
/* Cloned blocks copy their prototype's map; it had better be shareable. */
|
2011-09-28 15:04:55 -07:00
|
|
|
JS_ASSERT(!getProto()->inDictionaryMode());
|
|
|
|
setMap(getProto()->lastProp);
|
2011-03-15 12:18:36 -07:00
|
|
|
|
2011-09-28 15:04:55 -07:00
|
|
|
if (lastProp->extensibleParents())
|
|
|
|
return generateOwnShape(cx);
|
|
|
|
return true;
|
2011-03-15 12:18:36 -07:00
|
|
|
}
|
|
|
|
|
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)
|
|
|
|
{
|
2011-08-16 03:27:34 -07:00
|
|
|
JS_ASSERT(nativeContains(cx, shape));
|
2010-08-29 11:57:08 -07:00
|
|
|
JS_ASSERT(shape.isMethod());
|
2011-02-08 14:09:33 -08:00
|
|
|
JS_ASSERT(shape.writable());
|
2011-09-28 15:04:55 -07:00
|
|
|
JS_ASSERT(shape.hasSlot());
|
2011-07-27 15:44:43 -07:00
|
|
|
JS_ASSERT(shape.hasDefaultSetter());
|
2011-02-08 14:09:33 -08:00
|
|
|
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);
|
2011-08-18 10:39:44 -07:00
|
|
|
JS_ASSERT(fun->isNullClosure());
|
2010-08-29 11:57:08 -07:00
|
|
|
|
2011-09-17 19:14:22 -07:00
|
|
|
funobj = CloneFunctionObject(cx, fun);
|
2010-08-29 11:57:08 -07:00
|
|
|
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.
|
|
|
|
*/
|
2011-09-28 15:04:55 -07:00
|
|
|
uint32 slot = shape.slot();
|
2011-02-08 14:09:33 -08:00
|
|
|
const js::Shape *newshape = methodShapeChange(cx, shape);
|
|
|
|
if (!newshape)
|
|
|
|
return NULL;
|
|
|
|
JS_ASSERT(!newshape->isMethod());
|
2011-09-28 15:04:55 -07:00
|
|
|
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);
|
2011-02-15 12:11:04 -08:00
|
|
|
return newshape;
|
2010-08-29 11:57:08 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
inline bool
|
2011-09-28 15:04:55 -07:00
|
|
|
JSObject::canHaveMethodBarrier() const
|
2010-08-29 11:57:08 -07:00
|
|
|
{
|
2011-09-28 15:04:55 -07:00
|
|
|
return isObject() || isFunction() || isPrimitive() || isDate();
|
2010-08-29 11:57:08 -07:00
|
|
|
}
|
|
|
|
|
2011-07-28 18:10:31 -07:00
|
|
|
inline const js::Value *
|
2011-04-08 19:51:40 -07:00
|
|
|
JSObject::getRawSlots()
|
|
|
|
{
|
|
|
|
JS_ASSERT(isGlobal());
|
|
|
|
return slots;
|
|
|
|
}
|
|
|
|
|
2011-07-28 18:10:31 -07:00
|
|
|
inline const js::Value *
|
|
|
|
JSObject::getRawSlot(size_t slot, const js::Value *slots)
|
2011-04-08 19:51:40 -07:00
|
|
|
{
|
|
|
|
JS_ASSERT(isGlobal());
|
|
|
|
size_t fixed = numFixedSlots();
|
|
|
|
if (slot < fixed)
|
|
|
|
return fixedSlots() + slot;
|
|
|
|
return slots + slot - fixed;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline bool
|
|
|
|
JSObject::isFixedSlot(size_t slot)
|
|
|
|
{
|
|
|
|
JS_ASSERT(!isDenseArray());
|
|
|
|
return slot < numFixedSlots();
|
|
|
|
}
|
|
|
|
|
2011-07-02 06:38:36 -07:00
|
|
|
inline size_t
|
|
|
|
JSObject::numDynamicSlots(size_t capacity) const
|
|
|
|
{
|
|
|
|
JS_ASSERT(capacity >= numFixedSlots());
|
|
|
|
return isDenseArray() ? capacity : capacity - numFixedSlots();
|
|
|
|
}
|
|
|
|
|
2011-04-08 19:51:40 -07:00
|
|
|
inline size_t
|
|
|
|
JSObject::dynamicSlotIndex(size_t slot)
|
|
|
|
{
|
|
|
|
JS_ASSERT(!isDenseArray() && slot >= numFixedSlots());
|
|
|
|
return slot - numFixedSlots();
|
|
|
|
}
|
|
|
|
|
2010-08-29 11:57:08 -07:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2011-04-27 16:22:28 -07:00
|
|
|
inline void
|
|
|
|
JSObject::setReservedSlot(uintN index, const js::Value &v)
|
|
|
|
{
|
2011-07-21 15:36:09 -07:00
|
|
|
JS_ASSERT(index < JSSLOT_FREE(getClass()));
|
2011-04-27 16:22:28 -07:00
|
|
|
setSlot(index, v);
|
|
|
|
}
|
|
|
|
|
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());
|
2011-04-08 19:51:40 -07:00
|
|
|
return getFixedSlot(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());
|
2011-04-08 19:51:40 -07:00
|
|
|
setFixedSlot(JSSLOT_PRIMITIVE_THIS, pthis);
|
2010-04-14 18:57:30 -07:00
|
|
|
}
|
|
|
|
|
2011-04-08 19:51:40 -07:00
|
|
|
inline bool
|
|
|
|
JSObject::hasSlotsArray() const
|
2010-04-05 19:16:37 -07:00
|
|
|
{
|
2011-04-08 19:51:40 -07:00
|
|
|
JS_ASSERT_IF(!slots, !isDenseArray());
|
2011-08-11 09:42:41 -07:00
|
|
|
JS_ASSERT_IF(slots == fixedSlots(), isDenseArray() || isArrayBuffer());
|
2011-04-08 19:51:40 -07:00
|
|
|
return slots && slots != fixedSlots();
|
2010-10-13 11:49:22 -07:00
|
|
|
}
|
|
|
|
|
2011-09-01 12:20:30 -07:00
|
|
|
inline bool
|
|
|
|
JSObject::hasContiguousSlots(size_t start, size_t count) const
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
* Check that the range [start, start+count) is either all inline or all
|
|
|
|
* out of line.
|
|
|
|
*/
|
|
|
|
JS_ASSERT(start + count <= numSlots());
|
|
|
|
return (start + count <= numFixedSlots()) || (start >= numFixedSlots());
|
|
|
|
}
|
|
|
|
|
2010-10-13 11:49:22 -07:00
|
|
|
inline size_t
|
2011-04-08 19:51:40 -07:00
|
|
|
JSObject::structSize() const
|
2010-10-13 11:49:22 -07:00
|
|
|
{
|
2011-04-08 19:51:40 -07:00
|
|
|
return (isFunction() && !getPrivate())
|
|
|
|
? sizeof(JSFunction)
|
2011-07-01 16:24:32 -07:00
|
|
|
: (sizeof(JSObject) + sizeof(js::Value) * numFixedSlots());
|
2011-04-08 19:51:40 -07:00
|
|
|
}
|
2010-10-13 11:49:22 -07:00
|
|
|
|
2011-04-08 19:51:40 -07:00
|
|
|
inline size_t
|
|
|
|
JSObject::slotsAndStructSize() const
|
|
|
|
{
|
|
|
|
int ndslots = 0;
|
|
|
|
if (isDenseArray()) {
|
|
|
|
if (!denseArrayHasInlineSlots())
|
|
|
|
ndslots = numSlots();
|
|
|
|
} else {
|
|
|
|
if (slots)
|
|
|
|
ndslots = numSlots() - numFixedSlots();
|
|
|
|
}
|
2010-10-13 11:49:22 -07:00
|
|
|
|
2011-04-08 19:51:40 -07:00
|
|
|
return structSize() + sizeof(js::Value) * ndslots;
|
2010-04-05 19:16:37 -07:00
|
|
|
}
|
|
|
|
|
2010-04-05 18:32:16 -07:00
|
|
|
inline uint32
|
|
|
|
JSObject::getArrayLength() const
|
|
|
|
{
|
|
|
|
JS_ASSERT(isArray());
|
2011-08-12 11:28:51 -07:00
|
|
|
return (uint32)(uintptr_t) getPrivate();
|
2010-04-29 20:22:33 -07:00
|
|
|
}
|
|
|
|
|
2011-05-16 16:15:37 -07:00
|
|
|
inline void
|
2010-10-29 08:05:55 -07:00
|
|
|
JSObject::setArrayLength(JSContext *cx, uint32 length)
|
2010-04-29 20:22:33 -07:00
|
|
|
{
|
2010-07-22 18:45:21 -07:00
|
|
|
JS_ASSERT(isArray());
|
2010-10-29 08:05:55 -07:00
|
|
|
|
2011-04-16 06:54:01 -07:00
|
|
|
if (length > INT32_MAX) {
|
|
|
|
/*
|
|
|
|
* Mark the type of this object as possibly not a dense array, per the
|
|
|
|
* requirements of OBJECT_FLAG_NON_DENSE_ARRAY.
|
|
|
|
*/
|
2011-07-15 10:14:07 -07:00
|
|
|
js::types::MarkTypeObjectFlags(cx, this,
|
2011-06-02 10:40:27 -07:00
|
|
|
js::types::OBJECT_FLAG_NON_PACKED_ARRAY |
|
|
|
|
js::types::OBJECT_FLAG_NON_DENSE_ARRAY);
|
2011-04-16 06:54:01 -07:00
|
|
|
jsid lengthId = ATOM_TO_JSID(cx->runtime->atomState.lengthAtom);
|
2011-07-15 10:14:07 -07:00
|
|
|
js::types::AddTypePropertyId(cx, this, lengthId,
|
|
|
|
js::types::Type::DoubleType());
|
2010-10-29 08:05:55 -07:00
|
|
|
}
|
2011-03-03 14:07:48 -08:00
|
|
|
|
2011-08-14 19:51:16 -07:00
|
|
|
setPrivate((void*)(uintptr_t) length);
|
2011-03-03 14:07:48 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
inline void
|
|
|
|
JSObject::setDenseArrayLength(uint32 length)
|
|
|
|
{
|
|
|
|
/* Variant of setArrayLength for use on dense arrays where the length cannot overflow int32. */
|
|
|
|
JS_ASSERT(isDenseArray());
|
|
|
|
JS_ASSERT(length <= INT32_MAX);
|
2011-08-12 11:28:51 -07:00
|
|
|
setPrivate((void*)(uintptr_t) 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
|
|
|
}
|
|
|
|
|
2011-07-13 15:43:33 -07:00
|
|
|
inline const js::Value *
|
2010-10-13 11:49:22 -07:00
|
|
|
JSObject::getDenseArrayElements()
|
2010-04-05 18:32:16 -07:00
|
|
|
{
|
2010-04-26 18:33:36 -07:00
|
|
|
JS_ASSERT(isDenseArray());
|
2011-04-08 19:51:40 -07:00
|
|
|
return slots;
|
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
|
|
|
{
|
2010-11-05 07:37:09 -07:00
|
|
|
JS_ASSERT(isDenseArray() && idx < getDenseArrayInitializedLength());
|
2011-04-08 19:51:40 -07:00
|
|
|
return slots[idx];
|
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
|
|
|
{
|
2010-11-05 07:37:09 -07:00
|
|
|
JS_ASSERT(isDenseArray() && idx < getDenseArrayInitializedLength());
|
2011-04-08 19:51:40 -07:00
|
|
|
slots[idx] = val;
|
2010-04-26 18:33:36 -07:00
|
|
|
}
|
|
|
|
|
2011-05-16 16:15:37 -07:00
|
|
|
inline void
|
|
|
|
JSObject::setDenseArrayElementWithType(JSContext *cx, uintN idx, const js::Value &val)
|
|
|
|
{
|
2011-07-15 10:14:07 -07:00
|
|
|
js::types::AddTypePropertyId(cx, this, JSID_VOID, val);
|
2011-05-16 16:15:37 -07:00
|
|
|
setDenseArrayElement(idx, val);
|
|
|
|
}
|
|
|
|
|
2011-07-13 15:43:33 -07:00
|
|
|
inline void
|
2011-07-13 15:43:33 -07:00
|
|
|
JSObject::copyDenseArrayElements(uintN dstStart, const js::Value *src, uintN count)
|
2011-07-13 15:43:33 -07:00
|
|
|
{
|
|
|
|
JS_ASSERT(isDenseArray());
|
2011-07-28 18:10:31 -07:00
|
|
|
copySlotRange(dstStart, src, count);
|
2011-07-13 15:43:33 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
inline void
|
|
|
|
JSObject::moveDenseArrayElements(uintN dstStart, uintN srcStart, uintN count)
|
|
|
|
{
|
|
|
|
JS_ASSERT(isDenseArray());
|
|
|
|
JS_ASSERT(dstStart + count <= capacity);
|
|
|
|
JS_ASSERT(srcStart + count <= capacity);
|
2011-07-28 18:10:31 -07:00
|
|
|
memmove(slots + dstStart, slots + srcStart, count * sizeof(js::Value));
|
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
|
|
|
}
|
|
|
|
|
2011-04-08 19:51:40 -07:00
|
|
|
inline bool
|
|
|
|
JSObject::denseArrayHasInlineSlots() const
|
|
|
|
{
|
|
|
|
JS_ASSERT(isDenseArray() && slots);
|
|
|
|
return slots == fixedSlots();
|
|
|
|
}
|
|
|
|
|
2011-09-01 12:20:30 -07:00
|
|
|
namespace js {
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Any name atom for a function which will be added as a DeclEnv object to the
|
|
|
|
* scope chain above call objects for fun.
|
|
|
|
*/
|
|
|
|
static inline JSAtom *
|
|
|
|
CallObjectLambdaName(JSFunction *fun)
|
|
|
|
{
|
|
|
|
return (fun->flags & JSFUN_LAMBDA) ? fun->atom : NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
} /* namespace js */
|
|
|
|
|
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());
|
2011-04-08 19:51:40 -07:00
|
|
|
return getFixedSlot(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());
|
2011-04-08 19:51:40 -07:00
|
|
|
setFixedSlot(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
|
2011-04-08 19:51:40 -07:00
|
|
|
return (js::Value *) getFixedSlot(JSSLOT_FLAT_CLOSURE_UPVARS).toPrivate();
|
2010-08-29 11:57:08 -07:00
|
|
|
}
|
|
|
|
|
2011-08-09 01:51:59 -07:00
|
|
|
inline void
|
|
|
|
JSObject::finalizeUpvarsIfFlatClosure()
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
* Cloned function objects may be flat closures with upvars to free.
|
|
|
|
*
|
|
|
|
* We do not record in the closure objects any flags. Rather we use flags
|
|
|
|
* stored in the compiled JSFunction that we get via getFunctionPrivate()
|
|
|
|
* to distinguish between closure types. Then during finalization we must
|
|
|
|
* ensure that the compiled JSFunction always finalized after the closures
|
|
|
|
* so we can safely access it here. Currently the GC ensures that through
|
|
|
|
* finalizing JSFunction instances after finalizing any other objects even
|
|
|
|
* during the background finalization.
|
|
|
|
*
|
|
|
|
* But we must not access JSScript here that is stored in JSFunction. The
|
|
|
|
* script can be finalized before the function or closure instances. So we
|
|
|
|
* just check if JSSLOT_FLAT_CLOSURE_UPVARS holds a private value encoded
|
|
|
|
* as a double. We must also ignore newborn closures that do not have the
|
|
|
|
* private pointer set.
|
|
|
|
*
|
|
|
|
* FIXME bug 648320 - allocate upvars on the GC heap to avoid doing it
|
|
|
|
* here explicitly.
|
|
|
|
*/
|
|
|
|
JSFunction *fun = getFunctionPrivate();
|
|
|
|
if (fun && fun != this && fun->isFlatClosure()) {
|
|
|
|
const js::Value &v = getSlot(JSSLOT_FLAT_CLOSURE_UPVARS);
|
|
|
|
if (v.isDouble())
|
|
|
|
js::Foreground::free_(v.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];
|
|
|
|
}
|
|
|
|
|
2011-07-13 15:43:33 -07:00
|
|
|
inline const js::Value &
|
2010-12-29 20:21:18 -08:00
|
|
|
JSObject::getFlatClosureUpvar(uint32 i)
|
|
|
|
{
|
|
|
|
JS_ASSERT(i < getFunctionPrivate()->script()->bindings.countUpvars());
|
2010-08-29 11:57:08 -07:00
|
|
|
return getFlatClosureUpvars()[i];
|
|
|
|
}
|
|
|
|
|
2011-07-13 15:43:33 -07:00
|
|
|
inline void
|
|
|
|
JSObject::setFlatClosureUpvar(uint32 i, const js::Value &v)
|
|
|
|
{
|
|
|
|
JS_ASSERT(i < getFunctionPrivate()->script()->bindings.countUpvars());
|
|
|
|
getFlatClosureUpvars()[i] = v;
|
|
|
|
}
|
|
|
|
|
2010-08-29 11:57:08 -07:00
|
|
|
inline void
|
|
|
|
JSObject::setFlatClosureUpvars(js::Value *upvars)
|
|
|
|
{
|
|
|
|
JS_ASSERT(isFunction());
|
2011-08-18 10:39:44 -07:00
|
|
|
JS_ASSERT(getFunctionPrivate()->isFlatClosure());
|
2011-09-19 09:34:49 -07:00
|
|
|
setFixedSlot(JSSLOT_FLAT_CLOSURE_UPVARS, js::PrivateValue(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-04-08 19:51:40 -07:00
|
|
|
getFixedSlot(JSSLOT_FUN_METHOD_OBJ).isObject() &&
|
2011-04-19 08:23:41 -07:00
|
|
|
getFixedSlot(JSSLOT_FUN_METHOD_OBJ).toObject() == obj;
|
2010-08-01 09:58:03 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
inline void
|
|
|
|
JSObject::setMethodObj(JSObject& obj)
|
|
|
|
{
|
2011-07-28 18:10:31 -07:00
|
|
|
setFixedSlot(JSSLOT_FUN_METHOD_OBJ, js::ObjectValue(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());
|
2011-09-20 11:40:24 -07:00
|
|
|
return 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());
|
2011-09-20 11:40:24 -07:00
|
|
|
return 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());
|
2011-09-20 11:40:24 -07:00
|
|
|
return getSlot(JSSLOT_NAMESPACE_DECLARED);
|
2010-05-12 18:57:36 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
inline void
|
|
|
|
JSObject::setNamespaceDeclared(jsval decl)
|
|
|
|
{
|
|
|
|
JS_ASSERT(isNamespace());
|
2011-09-20 11:40:24 -07:00
|
|
|
setSlot(JSSLOT_NAMESPACE_DECLARED, decl);
|
2010-05-12 18:57:36 -07:00
|
|
|
}
|
|
|
|
|
2011-08-14 21:12:48 -07:00
|
|
|
inline JSAtom *
|
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-08-14 21:12:48 -07:00
|
|
|
return !v.isUndefined() ? &v.toString()->asAtom() : 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());
|
2011-09-20 11:40:24 -07:00
|
|
|
return getSlot(JSSLOT_QNAME_LOCAL_NAME);
|
2010-05-12 18:57:36 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
inline void
|
2011-08-14 21:12:48 -07:00
|
|
|
JSObject::setQNameLocalName(JSAtom *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
|
|
|
|
{
|
2011-04-08 19:51:40 -07:00
|
|
|
return &getFixedSlot(JSSLOT_WITH_THIS).toObject();
|
2010-06-08 14:09:40 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
inline void
|
|
|
|
JSObject::setWithThis(JSObject *thisp)
|
|
|
|
{
|
2011-04-08 19:51:40 -07:00
|
|
|
getFixedSlotRef(JSSLOT_WITH_THIS).setObject(*thisp);
|
2010-06-08 14:09:40 -07:00
|
|
|
}
|
|
|
|
|
2011-07-15 10:14:07 -07:00
|
|
|
inline bool
|
|
|
|
JSObject::setSingletonType(JSContext *cx)
|
|
|
|
{
|
|
|
|
if (!cx->typeInferenceEnabled())
|
|
|
|
return true;
|
|
|
|
|
|
|
|
JS_ASSERT(!lastProp->previous());
|
|
|
|
JS_ASSERT(!hasLazyType());
|
|
|
|
JS_ASSERT_IF(getProto(), type() == getProto()->getNewType(cx, NULL));
|
|
|
|
|
|
|
|
flags |= SINGLETON_TYPE | LAZY_TYPE;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline js::types::TypeObject *
|
|
|
|
JSObject::getType(JSContext *cx)
|
|
|
|
{
|
|
|
|
if (hasLazyType())
|
|
|
|
makeLazyType(cx);
|
|
|
|
return type_;
|
|
|
|
}
|
|
|
|
|
2010-12-18 20:44:51 -08:00
|
|
|
inline js::types::TypeObject *
|
2011-09-01 12:20:30 -07:00
|
|
|
JSObject::getNewType(JSContext *cx, JSFunction *fun, bool markUnknown)
|
2010-12-18 20:44:51 -08:00
|
|
|
{
|
|
|
|
if (isDenseArray() && !makeDenseArraySlow(cx))
|
|
|
|
return NULL;
|
2011-04-12 20:39:16 -07:00
|
|
|
if (newType) {
|
2011-06-03 20:48:16 -07:00
|
|
|
/*
|
|
|
|
* If set, the newType's newScript indicates the script used to create
|
|
|
|
* all objects in existence which have this type. If there are objects
|
|
|
|
* in existence which are not created by calling 'new' on newScript,
|
|
|
|
* we must clear the new script information from the type and will not
|
|
|
|
* be able to assume any definite properties for instances of the type.
|
|
|
|
* This case is rare, but can happen if, for example, two scripted
|
|
|
|
* functions have the same value for their 'prototype' property, or if
|
|
|
|
* Object.create is called with a prototype object that is also the
|
|
|
|
* 'prototype' property of some scripted function.
|
|
|
|
*/
|
2011-09-01 12:20:30 -07:00
|
|
|
if (newType->newScript && newType->newScript->fun != fun)
|
2011-04-12 20:39:16 -07:00
|
|
|
newType->clearNewScript(cx);
|
2011-07-15 10:14:07 -07:00
|
|
|
if (markUnknown && cx->typeInferenceEnabled() && !newType->unknownProperties())
|
|
|
|
newType->markUnknown(cx);
|
2011-04-12 20:39:16 -07:00
|
|
|
} else {
|
2011-09-01 12:20:30 -07:00
|
|
|
makeNewType(cx, fun, markUnknown);
|
2011-04-12 20:39:16 -07:00
|
|
|
}
|
2010-12-18 20:44:51 -08:00
|
|
|
return newType;
|
|
|
|
}
|
|
|
|
|
2011-07-21 07:28:01 -07:00
|
|
|
inline void
|
|
|
|
JSObject::clearType()
|
2010-12-18 20:44:51 -08:00
|
|
|
{
|
2011-07-15 10:14:07 -07:00
|
|
|
JS_ASSERT(!hasSingletonType());
|
2011-07-21 07:28:01 -07:00
|
|
|
type_ = &js::types::emptyTypeObject;
|
2010-12-18 20:44:51 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
inline void
|
|
|
|
JSObject::setType(js::types::TypeObject *newType)
|
2010-11-05 07:37:09 -07:00
|
|
|
{
|
|
|
|
#ifdef DEBUG
|
2010-12-18 20:44:51 -08:00
|
|
|
JS_ASSERT(newType);
|
|
|
|
for (JSObject *obj = newType->proto; obj; obj = obj->getProto())
|
2010-11-05 07:37:09 -07:00
|
|
|
JS_ASSERT(obj != this);
|
|
|
|
#endif
|
2011-05-10 23:33:30 -07:00
|
|
|
JS_ASSERT_IF(hasSpecialEquality(), newType->hasAnyFlags(js::types::OBJECT_FLAG_SPECIAL_EQUALITY));
|
2011-07-15 10:14:07 -07:00
|
|
|
JS_ASSERT(!hasSingletonType());
|
|
|
|
type_ = newType;
|
2011-03-16 10:02:19 -07:00
|
|
|
}
|
|
|
|
|
2009-11-18 12:29:58 -08:00
|
|
|
inline void
|
2010-12-18 20:44:51 -08:00
|
|
|
JSObject::init(JSContext *cx, js::Class *aclasp, js::types::TypeObject *type,
|
2011-06-03 20:48:16 -07:00
|
|
|
JSObject *parent, void *priv, bool denseArray)
|
2009-11-18 12:29:58 -08:00
|
|
|
{
|
2010-08-29 11:57:08 -07:00
|
|
|
clasp = aclasp;
|
2011-04-08 19:51:40 -07:00
|
|
|
flags = capacity << FIXED_SLOTS_SHIFT;
|
|
|
|
|
2011-09-02 17:23:26 -07:00
|
|
|
JS_ASSERT(denseArray == (aclasp == &js::ArrayClass));
|
2009-11-18 12:29:58 -08:00
|
|
|
|
2010-10-13 11:49:22 -07:00
|
|
|
privateData = priv;
|
|
|
|
|
|
|
|
/*
|
2010-11-05 07:37:09 -07:00
|
|
|
* Fill the fixed slots with undefined if needed. This object must
|
2011-06-01 11:15:51 -07:00
|
|
|
* already have its capacity filled in, as by js_NewGCObject. If inference
|
|
|
|
* is disabled, NewArray will backfill holes up to the array's capacity
|
|
|
|
* and unset the PACKED_ARRAY flag.
|
2010-10-13 11:49:22 -07:00
|
|
|
*/
|
2011-04-08 19:51:40 -07:00
|
|
|
slots = NULL;
|
2011-06-03 20:48:16 -07:00
|
|
|
if (denseArray) {
|
2011-04-08 19:51:40 -07:00
|
|
|
slots = fixedSlots();
|
|
|
|
flags |= PACKED_ARRAY;
|
2011-06-01 11:15:51 -07:00
|
|
|
} else {
|
2011-09-19 09:34:49 -07:00
|
|
|
js::ClearValueRange(fixedSlots(), capacity, denseArray);
|
2010-11-05 07:37:09 -07:00
|
|
|
}
|
2011-03-19 16:53:07 -07:00
|
|
|
|
2011-04-08 19:51:40 -07:00
|
|
|
newType = NULL;
|
|
|
|
JS_ASSERT(initializedLength == 0);
|
|
|
|
|
2011-03-19 16:53:07 -07:00
|
|
|
setType(type);
|
|
|
|
setParent(parent);
|
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
|
|
|
if (hasSlotsArray())
|
2011-04-08 19:51:40 -07:00
|
|
|
cx->free_(slots);
|
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-10-29 08:05:55 -07:00
|
|
|
js::types::TypeObject *type,
|
2010-12-18 20:44:51 -08:00
|
|
|
JSObject *parent,
|
2010-10-13 11:49:22 -07:00
|
|
|
void *privateValue,
|
2011-08-18 00:16:08 -07:00
|
|
|
js::gc::AllocKind kind)
|
2010-08-29 11:57:08 -07:00
|
|
|
{
|
2010-12-18 20:44:51 -08:00
|
|
|
init(cx, aclasp, type, parent, privateValue, false);
|
2010-10-13 11:49:22 -07:00
|
|
|
|
|
|
|
JS_ASSERT(!isDenseArray());
|
|
|
|
|
2010-12-18 20:44:51 -08:00
|
|
|
js::EmptyShape *empty = type->getEmptyShape(cx, aclasp, kind);
|
2010-10-13 11:49:22 -07:00
|
|
|
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-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)
|
|
|
|
{
|
|
|
|
JSSecurityCallbacks *cb = JS_GetSecurityCallbacks(cx);
|
2011-04-28 15:40:21 -07:00
|
|
|
if (JSObjectPrincipalsFinder finder = cb ? cb->findObjectPrincipals : NULL)
|
|
|
|
return finder(cx, this);
|
2011-07-22 15:22:05 -07:00
|
|
|
return cx->compartment ? cx->compartment->principals : NULL;
|
2011-04-08 10:52:51 -07:00
|
|
|
}
|
|
|
|
|
2011-04-08 14:21:08 -07:00
|
|
|
inline uint32
|
|
|
|
JSObject::slotSpan() const
|
|
|
|
{
|
2011-09-28 15:04:55 -07:00
|
|
|
if (inDictionaryMode()) {
|
|
|
|
JS_ASSERT(lastProp->base()->isOwned());
|
|
|
|
return lastProp->base()->slotSpan;
|
|
|
|
}
|
|
|
|
uint32 free = JSSLOT_FREE(getClass());
|
|
|
|
return lastProp->hasMissingSlot() ? free : JS_MAX(free, lastProp->maybeSlot() + 1);
|
2011-04-08 14:21:08 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
inline bool
|
|
|
|
JSObject::containsSlot(uint32 slot) const
|
|
|
|
{
|
|
|
|
return slot < slotSpan();
|
|
|
|
}
|
|
|
|
|
|
|
|
inline void
|
|
|
|
JSObject::setMap(js::Shape *amap)
|
|
|
|
{
|
2011-09-28 15:04:55 -07:00
|
|
|
JS_ASSERT_IF(lastProp && isNative(), !inDictionaryMode());
|
2011-04-08 14:21:08 -07:00
|
|
|
lastProp = amap;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline js::Value &
|
|
|
|
JSObject::nativeGetSlotRef(uintN slot)
|
|
|
|
{
|
|
|
|
JS_ASSERT(isNative());
|
|
|
|
JS_ASSERT(containsSlot(slot));
|
|
|
|
return getSlotRef(slot);
|
|
|
|
}
|
|
|
|
|
|
|
|
inline const js::Value &
|
|
|
|
JSObject::nativeGetSlot(uintN slot) const
|
|
|
|
{
|
|
|
|
JS_ASSERT(isNative());
|
|
|
|
JS_ASSERT(containsSlot(slot));
|
|
|
|
return getSlot(slot);
|
|
|
|
}
|
|
|
|
|
2011-09-28 15:04:55 -07:00
|
|
|
inline JSFunction *
|
|
|
|
JSObject::nativeGetMethod(const js::Shape *shape) const
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
* For method shapes, this object must have an uncloned function object in
|
|
|
|
* the shape's slot.
|
|
|
|
*/
|
|
|
|
JS_ASSERT(shape->isMethod());
|
|
|
|
#ifdef DEBUG
|
|
|
|
JSObject *obj = &nativeGetSlot(shape->slot()).toObject();
|
|
|
|
JS_ASSERT(obj->isFunction() && obj->getFunctionPrivate() == obj);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
return (JSFunction *) &nativeGetSlot(shape->slot()).toObject();
|
|
|
|
}
|
|
|
|
|
2011-04-08 14:21:08 -07:00
|
|
|
inline void
|
|
|
|
JSObject::nativeSetSlot(uintN slot, const js::Value &value)
|
|
|
|
{
|
|
|
|
JS_ASSERT(isNative());
|
|
|
|
JS_ASSERT(containsSlot(slot));
|
|
|
|
return setSlot(slot, value);
|
|
|
|
}
|
|
|
|
|
2011-05-18 10:43:08 -07:00
|
|
|
inline void
|
|
|
|
JSObject::nativeSetSlotWithType(JSContext *cx, const js::Shape *shape, const js::Value &value)
|
|
|
|
{
|
2011-09-28 15:04:55 -07:00
|
|
|
nativeSetSlot(shape->slot(), value);
|
|
|
|
js::types::AddTypePropertyId(cx, this, shape->propid(), value);
|
2011-05-18 10:43:08 -07:00
|
|
|
}
|
|
|
|
|
2011-04-08 14:21:08 -07:00
|
|
|
inline bool
|
|
|
|
JSObject::isNative() const
|
|
|
|
{
|
|
|
|
return lastProp->isNative();
|
|
|
|
}
|
|
|
|
|
|
|
|
inline bool
|
|
|
|
JSObject::isNewborn() const
|
|
|
|
{
|
|
|
|
return !lastProp;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline js::Shape **
|
2011-08-16 03:27:34 -07:00
|
|
|
JSObject::nativeSearch(JSContext *cx, jsid id, bool adding)
|
2011-04-08 14:21:08 -07:00
|
|
|
{
|
2011-08-16 03:27:34 -07:00
|
|
|
return js::Shape::search(cx, &lastProp, id, adding);
|
2011-04-08 14:21:08 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
inline const js::Shape *
|
2011-08-16 03:27:34 -07:00
|
|
|
JSObject::nativeLookup(JSContext *cx, jsid id)
|
2011-04-08 14:21:08 -07:00
|
|
|
{
|
|
|
|
JS_ASSERT(isNative());
|
2011-08-16 03:27:34 -07:00
|
|
|
return SHAPE_FETCH(nativeSearch(cx, id));
|
2011-04-08 14:21:08 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
inline bool
|
2011-08-16 03:27:34 -07:00
|
|
|
JSObject::nativeContains(JSContext *cx, jsid id)
|
2011-04-08 14:21:08 -07:00
|
|
|
{
|
2011-08-16 03:27:34 -07:00
|
|
|
return nativeLookup(cx, id) != NULL;
|
2011-04-08 14:21:08 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
inline bool
|
2011-08-16 03:27:34 -07:00
|
|
|
JSObject::nativeContains(JSContext *cx, const js::Shape &shape)
|
2011-04-08 14:21:08 -07:00
|
|
|
{
|
2011-09-28 15:04:55 -07:00
|
|
|
return nativeLookup(cx, shape.propid()) == &shape;
|
2011-04-08 14:21:08 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
inline const js::Shape *
|
|
|
|
JSObject::lastProperty() const
|
|
|
|
{
|
2011-09-28 15:04:55 -07:00
|
|
|
JS_ASSERT_IF(!isNative(), lastProp->isEmptyShape());
|
|
|
|
JS_ASSERT_IF(!lastProp->isEmptyShape(), !JSID_IS_EMPTY(lastProp->propid()));
|
2011-04-08 14:21:08 -07:00
|
|
|
return lastProp;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline bool
|
|
|
|
JSObject::nativeEmpty() const
|
|
|
|
{
|
|
|
|
return lastProperty()->isEmptyShape();
|
|
|
|
}
|
|
|
|
|
|
|
|
inline bool
|
|
|
|
JSObject::inDictionaryMode() const
|
|
|
|
{
|
|
|
|
return lastProperty()->inDictionary();
|
|
|
|
}
|
|
|
|
|
|
|
|
inline uint32
|
|
|
|
JSObject::propertyCount() const
|
|
|
|
{
|
|
|
|
return lastProperty()->entryCount();
|
|
|
|
}
|
|
|
|
|
|
|
|
inline bool
|
|
|
|
JSObject::hasPropertyTable() const
|
|
|
|
{
|
|
|
|
return lastProperty()->hasTable();
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* FIXME: shape must not be null, should use a reference here and other places.
|
|
|
|
*/
|
|
|
|
inline void
|
|
|
|
JSObject::setLastProperty(const js::Shape *shape)
|
|
|
|
{
|
|
|
|
JS_ASSERT(!inDictionaryMode());
|
|
|
|
JS_ASSERT(shape->compartment() == compartment());
|
|
|
|
|
|
|
|
lastProp = const_cast<js::Shape *>(shape);
|
|
|
|
}
|
|
|
|
|
|
|
|
inline void
|
|
|
|
JSObject::removeLastProperty()
|
|
|
|
{
|
|
|
|
JS_ASSERT(!inDictionaryMode());
|
|
|
|
|
|
|
|
lastProp = lastProp->parent;
|
|
|
|
}
|
|
|
|
|
2011-08-10 14:54:51 -07:00
|
|
|
inline JSBool
|
|
|
|
JSObject::lookupElement(JSContext *cx, uint32 index, JSObject **objp, JSProperty **propp)
|
|
|
|
{
|
2011-08-10 14:54:52 -07:00
|
|
|
js::LookupElementOp op = getOps()->lookupElement;
|
|
|
|
return (op ? op : js_LookupElement)(cx, this, index, objp, propp);
|
2011-08-10 14:54:51 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
inline JSBool
|
|
|
|
JSObject::getElement(JSContext *cx, JSObject *receiver, uint32 index, js::Value *vp)
|
|
|
|
{
|
|
|
|
jsid id;
|
|
|
|
if (!js::IndexToId(cx, index, &id))
|
|
|
|
return false;
|
2011-09-15 11:44:10 -07:00
|
|
|
return getGeneric(cx, receiver, id, vp);
|
2011-08-10 14:54:51 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
inline JSBool
|
|
|
|
JSObject::getElement(JSContext *cx, uint32 index, js::Value *vp)
|
|
|
|
{
|
|
|
|
jsid id;
|
|
|
|
if (!js::IndexToId(cx, index, &id))
|
|
|
|
return false;
|
2011-09-15 11:44:10 -07:00
|
|
|
return getGeneric(cx, id, vp);
|
2011-08-10 14:54:51 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
inline JSBool
|
|
|
|
JSObject::deleteElement(JSContext *cx, uint32 index, js::Value *rval, JSBool strict)
|
|
|
|
{
|
|
|
|
jsid id;
|
|
|
|
if (!js::IndexToId(cx, index, &id))
|
|
|
|
return false;
|
|
|
|
return deleteProperty(cx, id, rval, strict);
|
|
|
|
}
|
|
|
|
|
2011-08-12 11:26:48 -07:00
|
|
|
inline JSBool
|
2011-09-15 11:44:10 -07:00
|
|
|
JSObject::getSpecial(JSContext *cx, js::SpecialId sid, js::Value *vp)
|
2011-08-12 11:26:48 -07:00
|
|
|
{
|
2011-09-15 11:44:10 -07:00
|
|
|
return getGeneric(cx, SPECIALID_TO_JSID(sid), vp);
|
2011-08-12 11:26:48 -07:00
|
|
|
}
|
|
|
|
|
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-12-18 20:44:51 -08:00
|
|
|
inline JSObject *
|
|
|
|
js_UnwrapWithObject(JSContext *cx, JSObject *withobj)
|
|
|
|
{
|
2011-09-02 17:23:26 -07:00
|
|
|
JS_ASSERT(withobj->isWith());
|
2010-12-18 20:44:51 -08:00
|
|
|
return withobj->getProto();
|
|
|
|
}
|
|
|
|
|
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-12-18 20:44:51 -08:00
|
|
|
InitScopeForObject(JSContext* cx, JSObject* obj, js::Class *clasp, js::types::TypeObject *type,
|
2011-08-18 00:16:08 -07:00
|
|
|
gc::AllocKind 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
|
|
|
|
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
|
|
|
|
2011-03-16 18:59:20 -07:00
|
|
|
uint32 freeslot = JSSLOT_FREE(clasp);
|
|
|
|
if (freeslot > obj->numSlots() && !obj->allocSlots(cx, freeslot))
|
|
|
|
goto bad;
|
2010-04-10 16:16:35 -07:00
|
|
|
|
2011-07-21 07:28:01 -07:00
|
|
|
if (type->canProvideEmptyShape(clasp))
|
2011-03-16 18:59:20 -07:00
|
|
|
empty = type->getEmptyShape(cx, clasp, kind);
|
|
|
|
else
|
2010-08-29 11:57:08 -07:00
|
|
|
empty = js::EmptyShape::create(cx, clasp);
|
2011-03-16 18:59:20 -07:00
|
|
|
if (!empty)
|
|
|
|
goto bad;
|
2010-04-10 16:16:35 -07:00
|
|
|
|
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. */
|
2011-04-08 14:21:08 -07:00
|
|
|
JS_ASSERT(obj->isNewborn());
|
2010-04-10 16:16:35 -07:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2011-09-28 15:04:55 -07:00
|
|
|
static inline bool
|
|
|
|
InitNonNativeObject(JSContext *cx, JSObject *obj, js::Class *clasp)
|
|
|
|
{
|
|
|
|
JS_ASSERT(!clasp->isNative());
|
|
|
|
|
|
|
|
js::EmptyShape *empty = js::BaseShape::lookupEmpty(cx, clasp);
|
|
|
|
if (!empty)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
obj->setMap(empty);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2011-04-13 13:43:33 -07:00
|
|
|
static inline bool
|
2011-08-18 00:16:08 -07:00
|
|
|
CanBeFinalizedInBackground(gc::AllocKind kind, Class *clasp)
|
2011-04-13 13:43:33 -07:00
|
|
|
{
|
2011-04-25 13:05:30 -07:00
|
|
|
#ifdef JS_THREADSAFE
|
2011-04-13 13:43:33 -07:00
|
|
|
JS_ASSERT(kind <= gc::FINALIZE_OBJECT_LAST);
|
|
|
|
/* If the class has no finalizer or a finalizer that is safe to call on
|
|
|
|
* a different thread, we change the finalize kind. For example,
|
|
|
|
* FINALIZE_OBJECT0 calls the finalizer on the main thread,
|
|
|
|
* FINALIZE_OBJECT0_BACKGROUND calls the finalizer on the gcHelperThread.
|
2011-08-18 00:16:08 -07:00
|
|
|
* IsBackgroundAllocKind is called to prevent recursively incrementing
|
2011-06-03 20:48:16 -07:00
|
|
|
* the finalize kind; kind may already be a background finalize kind.
|
2011-04-13 13:43:33 -07:00
|
|
|
*/
|
2011-08-18 00:16:08 -07:00
|
|
|
if (!gc::IsBackgroundAllocKind(kind) &&
|
2011-06-03 20:48:16 -07:00
|
|
|
(!clasp->finalize || clasp->flags & JSCLASS_CONCURRENT_FINALIZER)) {
|
2011-04-13 13:43:33 -07:00
|
|
|
return true;
|
2011-06-03 20:48:16 -07:00
|
|
|
}
|
2011-04-25 13:05:30 -07:00
|
|
|
#endif
|
2011-04-13 13:43:33 -07:00
|
|
|
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,
|
2011-08-18 00:16:08 -07:00
|
|
|
JSObject *parent, gc::AllocKind kind)
|
2010-06-18 17:43:02 -07:00
|
|
|
{
|
|
|
|
JS_ASSERT(proto);
|
|
|
|
JS_ASSERT(parent);
|
2011-04-13 13:43:33 -07:00
|
|
|
JS_ASSERT(kind <= gc::FINALIZE_OBJECT_LAST);
|
2010-06-18 17:43:02 -07:00
|
|
|
|
2010-12-18 20:44:51 -08:00
|
|
|
types::TypeObject *type = proto->getNewType(cx);
|
|
|
|
if (!type)
|
|
|
|
return NULL;
|
|
|
|
|
2010-06-18 17:43:02 -07:00
|
|
|
/*
|
|
|
|
* 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
|
|
|
*/
|
2011-04-13 13:43:33 -07:00
|
|
|
|
|
|
|
if (CanBeFinalizedInBackground(kind, clasp))
|
2011-08-18 00:16:08 -07:00
|
|
|
kind = GetBackgroundAllocKind(kind);
|
2011-04-13 13:43:33 -07:00
|
|
|
|
2010-10-13 11:49:22 -07:00
|
|
|
JSObject* obj = js_NewGCObject(cx, kind);
|
2011-09-28 15:04:55 -07:00
|
|
|
if (!obj)
|
|
|
|
return NULL;
|
2010-08-09 09:11:22 -07:00
|
|
|
|
2011-09-28 15:04:55 -07:00
|
|
|
/*
|
|
|
|
* Default parent to the parent of the prototype, which was set from
|
|
|
|
* the parent of the prototype's constructor.
|
|
|
|
*/
|
|
|
|
bool denseArray = (clasp == &ArrayClass);
|
|
|
|
obj->init(cx, clasp, type, parent, NULL, denseArray);
|
2010-06-18 17:43:02 -07:00
|
|
|
|
2011-09-28 15:04:55 -07:00
|
|
|
JS_ASSERT(type->canProvideEmptyShape(clasp));
|
|
|
|
js::EmptyShape *empty = type->getEmptyShape(cx, clasp, kind);
|
|
|
|
if (!empty)
|
|
|
|
return NULL;
|
2010-06-18 17:43:02 -07:00
|
|
|
|
2011-09-28 15:04:55 -07:00
|
|
|
obj->setMap(empty);
|
2010-06-18 17:43:02 -07:00
|
|
|
|
|
|
|
return obj;
|
|
|
|
}
|
|
|
|
|
2010-10-13 11:49:22 -07:00
|
|
|
static inline JSObject *
|
2010-12-18 20:44:51 -08:00
|
|
|
NewNativeClassInstance(JSContext *cx, Class *clasp, JSObject *proto, JSObject *parent)
|
2010-10-13 11:49:22 -07:00
|
|
|
{
|
2011-08-18 00:16:08 -07:00
|
|
|
gc::AllocKind kind = gc::GetGCObjectKind(JSCLASS_RESERVED_SLOTS(clasp));
|
2010-12-18 20:44:51 -08:00
|
|
|
return NewNativeClassInstance(cx, clasp, proto, parent, kind);
|
2010-10-13 11:49:22 -07:00
|
|
|
}
|
|
|
|
|
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 *
|
2011-08-18 00:16:08 -07:00
|
|
|
NewBuiltinClassInstance(JSContext *cx, Class *clasp, gc::AllocKind 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. */
|
2010-06-28 16:38:54 -07:00
|
|
|
JSObject *global;
|
2011-05-24 16:08:40 -07:00
|
|
|
if (!cx->hasfp()) {
|
2010-06-28 16:38:54 -07:00
|
|
|
global = cx->globalObject;
|
2011-07-13 16:47:10 -07:00
|
|
|
if (!NULLABLE_OBJ_TO_INNER_OBJECT(cx, global))
|
2010-06-28 16:38:54 -07:00
|
|
|
return NULL;
|
|
|
|
} else {
|
2010-08-09 22:43:33 -07:00
|
|
|
global = cx->fp()->scopeChain().getGlobal();
|
2010-06-28 16:38:54 -07:00
|
|
|
}
|
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-12-18 20:44:51 -08:00
|
|
|
return NewNativeClassInstance(cx, clasp, proto, global, kind);
|
2010-10-13 11:49:22 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline JSObject *
|
2010-12-18 20:44:51 -08:00
|
|
|
NewBuiltinClassInstance(JSContext *cx, Class *clasp)
|
2010-10-13 11:49:22 -07:00
|
|
|
{
|
2011-08-18 00:16:08 -07:00
|
|
|
gc::AllocKind kind = gc::GetGCObjectKind(JSCLASS_RESERVED_SLOTS(clasp));
|
2010-12-18 20:44:51 -08:00
|
|
|
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-18 20:44:51 -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,
|
2011-08-18 00:16:08 -07:00
|
|
|
gc::AllocKind 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-18 20:44:51 -08:00
|
|
|
return NULL;
|
2010-10-13 11:49:22 -07:00
|
|
|
}
|
2010-12-18 20:44:51 -08:00
|
|
|
|
2011-07-21 07:28:01 -07:00
|
|
|
types::TypeObject *type = proto ? proto->getNewType(cx) : &js::types::emptyTypeObject;
|
2011-03-04 07:50:32 -08:00
|
|
|
if (!type)
|
|
|
|
return NULL;
|
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
|
|
|
*/
|
2011-04-13 13:43:33 -07:00
|
|
|
|
|
|
|
if (!isFunction && CanBeFinalizedInBackground(kind, clasp))
|
2011-08-18 00:16:08 -07:00
|
|
|
kind = GetBackgroundAllocKind(kind);
|
2011-04-13 13:43:33 -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-12-18 20:44:51 -08:00
|
|
|
obj->init(cx, clasp, type,
|
|
|
|
(!parent && proto) ? proto->getParent() : parent,
|
2011-09-02 17:23:26 -07:00
|
|
|
NULL, clasp == &ArrayClass);
|
2010-04-10 16:16:35 -07:00
|
|
|
|
2011-09-28 15:04:55 -07:00
|
|
|
if (clasp->isNative()
|
|
|
|
? !InitScopeForObject(cx, obj, clasp, type, kind)
|
|
|
|
: !InitNonNativeObject(cx, obj, clasp)) {
|
|
|
|
obj = NULL;
|
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
|
|
|
|
2011-05-10 14:56:49 -07:00
|
|
|
static JS_ALWAYS_INLINE JSObject *
|
|
|
|
NewFunction(JSContext *cx, js::GlobalObject &global)
|
|
|
|
{
|
|
|
|
JSObject *proto;
|
|
|
|
if (!js_GetClassPrototype(cx, &global, JSProto_Function, &proto))
|
|
|
|
return NULL;
|
2011-09-02 17:23:26 -07:00
|
|
|
return detail::NewObject<WithProto::Given, true>(cx, &FunctionClass, proto, &global,
|
2011-05-10 14:56:49 -07:00
|
|
|
gc::FINALIZE_OBJECT2);
|
|
|
|
}
|
|
|
|
|
2010-09-20 11:40:32 -07:00
|
|
|
static JS_ALWAYS_INLINE JSObject *
|
2010-12-18 20:44:51 -08:00
|
|
|
NewFunction(JSContext *cx, JSObject *parent)
|
2010-09-20 11:40:32 -07:00
|
|
|
{
|
2011-09-02 17:23:26 -07:00
|
|
|
return detail::NewObject<WithProto::Class, true>(cx, &FunctionClass, NULL, parent,
|
2010-10-13 11:49:22 -07:00
|
|
|
gc::FINALIZE_OBJECT2);
|
|
|
|
}
|
|
|
|
|
|
|
|
template <WithProto::e withProto>
|
|
|
|
static JS_ALWAYS_INLINE JSObject *
|
|
|
|
NewNonFunction(JSContext *cx, js::Class *clasp, JSObject *proto, JSObject *parent,
|
2011-08-18 00:16:08 -07:00
|
|
|
gc::AllocKind kind)
|
2010-10-13 11:49:22 -07:00
|
|
|
{
|
2010-12-18 20:44:51 -08:00
|
|
|
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 *
|
2010-12-18 20:44:51 -08:00
|
|
|
NewNonFunction(JSContext *cx, js::Class *clasp, JSObject *proto, JSObject *parent)
|
2010-08-09 09:11:22 -07:00
|
|
|
{
|
2011-08-18 00:16:08 -07:00
|
|
|
gc::AllocKind kind = gc::GetGCObjectKind(JSCLASS_RESERVED_SLOTS(clasp));
|
2010-12-18 20:44:51 -08:00
|
|
|
return detail::NewObject<withProto, false>(cx, clasp, proto, parent, kind);
|
2010-10-13 11:49:22 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
template <WithProto::e withProto>
|
|
|
|
static JS_ALWAYS_INLINE JSObject *
|
|
|
|
NewObject(JSContext *cx, js::Class *clasp, JSObject *proto, JSObject *parent,
|
2011-08-18 00:16:08 -07:00
|
|
|
gc::AllocKind kind)
|
2010-10-13 11:49:22 -07:00
|
|
|
{
|
2011-09-02 17:23:26 -07:00
|
|
|
if (clasp == &FunctionClass)
|
2010-12-18 20:44:51 -08:00
|
|
|
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-12-18 20:44:51 -08:00
|
|
|
NewObject(JSContext *cx, js::Class *clasp, JSObject *proto, JSObject *parent)
|
2010-04-10 16:16:35 -07:00
|
|
|
{
|
2011-08-18 00:16:08 -07:00
|
|
|
gc::AllocKind kind = gc::GetGCObjectKind(JSCLASS_RESERVED_SLOTS(clasp));
|
2010-12-18 20:44:51 -08:00
|
|
|
return NewObject<withProto>(cx, clasp, proto, parent, kind);
|
2010-10-13 11:49:22 -07:00
|
|
|
}
|
|
|
|
|
2011-04-12 20:39:16 -07:00
|
|
|
/*
|
|
|
|
* Create a plain object with the specified type. This bypasses getNewType to
|
|
|
|
* avoid losing creation site information for objects made by scripted 'new'.
|
|
|
|
*/
|
|
|
|
static JS_ALWAYS_INLINE JSObject *
|
2011-08-18 00:16:08 -07:00
|
|
|
NewObjectWithType(JSContext *cx, types::TypeObject *type, JSObject *parent, gc::AllocKind kind)
|
2011-04-12 20:39:16 -07:00
|
|
|
{
|
2011-07-28 14:17:42 -07:00
|
|
|
JS_ASSERT(type == type->proto->newType);
|
|
|
|
|
2011-09-02 17:23:26 -07:00
|
|
|
if (CanBeFinalizedInBackground(kind, &ObjectClass))
|
2011-08-18 00:16:08 -07:00
|
|
|
kind = GetBackgroundAllocKind(kind);
|
2011-08-11 20:56:17 -07:00
|
|
|
|
2011-04-12 20:39:16 -07:00
|
|
|
JSObject* obj = js_NewGCObject(cx, kind);
|
|
|
|
if (!obj)
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Default parent to the parent of the prototype, which was set from
|
|
|
|
* the parent of the prototype's constructor.
|
|
|
|
*/
|
2011-09-02 17:23:26 -07:00
|
|
|
obj->init(cx, &ObjectClass, type,
|
2011-04-12 20:39:16 -07:00
|
|
|
(!parent && type->proto) ? type->proto->getParent() : parent,
|
|
|
|
NULL, false);
|
|
|
|
|
2011-09-02 17:23:26 -07:00
|
|
|
if (!InitScopeForObject(cx, obj, &ObjectClass, type, kind)) {
|
2011-04-12 20:39:16 -07:00
|
|
|
obj = NULL;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
out:
|
|
|
|
Probes::createObject(cx, obj);
|
|
|
|
return obj;
|
|
|
|
}
|
|
|
|
|
|
|
|
extern JSObject *
|
2011-07-28 14:17:42 -07:00
|
|
|
NewReshapedObject(JSContext *cx, js::types::TypeObject *type, JSObject *parent,
|
2011-08-18 00:16:08 -07:00
|
|
|
gc::AllocKind kind, const Shape *shape);
|
2011-04-12 20:39:16 -07:00
|
|
|
|
2010-10-13 11:49:22 -07:00
|
|
|
/*
|
2011-01-24 15:32:44 -08:00
|
|
|
* As for gc::GetGCObjectKind, where numSlots is a guess at the final size of
|
2011-04-08 19:51:40 -07:00
|
|
|
* the object, zero if the final size is unknown. This should only be used for
|
|
|
|
* objects that do not require any fixed slots.
|
2010-10-13 11:49:22 -07:00
|
|
|
*/
|
2011-08-18 00:16:08 -07:00
|
|
|
static inline gc::AllocKind
|
2010-10-13 11:49:22 -07:00
|
|
|
GuessObjectGCKind(size_t numSlots, bool isArray)
|
|
|
|
{
|
|
|
|
if (numSlots)
|
2011-06-01 11:15:51 -07:00
|
|
|
return gc::GetGCObjectKind(numSlots, isArray);
|
2010-10-13 11:49:22 -07:00
|
|
|
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.
|
|
|
|
*/
|
2011-08-18 00:16:08 -07:00
|
|
|
static inline gc::AllocKind
|
2010-10-13 11:49:22 -07:00
|
|
|
NewObjectGCKind(JSContext *cx, js::Class *clasp)
|
|
|
|
{
|
2011-09-02 17:23:26 -07:00
|
|
|
if (clasp == &ArrayClass || clasp == &SlowArrayClass)
|
2010-10-13 11:49:22 -07:00
|
|
|
return gc::FINALIZE_OBJECT8;
|
2011-09-02 17:23:26 -07:00
|
|
|
if (clasp == &FunctionClass)
|
2010-10-13 11:49:22 -07:00
|
|
|
return gc::FINALIZE_OBJECT2;
|
|
|
|
return gc::FINALIZE_OBJECT4;
|
2010-04-10 16:16:35 -07:00
|
|
|
}
|
|
|
|
|
2011-04-20 13:33:05 -07:00
|
|
|
static JS_ALWAYS_INLINE JSObject*
|
|
|
|
NewObjectWithClassProto(JSContext *cx, Class *clasp, JSObject *proto,
|
2011-08-18 00:16:08 -07:00
|
|
|
gc::AllocKind kind)
|
2011-04-20 13:33:05 -07:00
|
|
|
{
|
|
|
|
JS_ASSERT(clasp->isNative());
|
|
|
|
|
2011-05-09 09:49:48 -07:00
|
|
|
types::TypeObject *type = proto->getNewType(cx);
|
|
|
|
if (!type)
|
|
|
|
return NULL;
|
|
|
|
|
2011-04-20 13:33:05 -07:00
|
|
|
if (CanBeFinalizedInBackground(kind, clasp))
|
2011-08-18 00:16:08 -07:00
|
|
|
kind = GetBackgroundAllocKind(kind);
|
2011-04-20 13:33:05 -07:00
|
|
|
|
|
|
|
JSObject* obj = js_NewGCObject(cx, kind);
|
|
|
|
if (!obj)
|
|
|
|
return NULL;
|
|
|
|
|
2011-05-09 09:49:48 -07:00
|
|
|
if (!obj->initSharingEmptyShape(cx, clasp, type, proto->getParent(), NULL, kind))
|
2011-04-20 13:33:05 -07:00
|
|
|
return NULL;
|
|
|
|
return obj;
|
|
|
|
}
|
|
|
|
|
2010-11-18 18:14:22 -08:00
|
|
|
/* Make an object with pregenerated shape from a NEWOBJECT bytecode. */
|
|
|
|
static inline JSObject *
|
2010-11-18 21:09:24 -08:00
|
|
|
CopyInitializerObject(JSContext *cx, JSObject *baseobj, types::TypeObject *type)
|
2010-11-18 18:14:22 -08:00
|
|
|
{
|
2011-09-02 17:23:26 -07:00
|
|
|
JS_ASSERT(baseobj->getClass() == &ObjectClass);
|
2010-11-18 18:14:22 -08:00
|
|
|
JS_ASSERT(!baseobj->inDictionaryMode());
|
|
|
|
|
2011-08-16 03:27:34 -07:00
|
|
|
gc::AllocKind kind = gc::GetGCObjectFixedSlotsKind(baseobj->numFixedSlots());
|
|
|
|
#ifdef JS_THREADSAFE
|
|
|
|
kind = gc::GetBackgroundAllocKind(kind);
|
|
|
|
#endif
|
|
|
|
JS_ASSERT(kind == baseobj->getAllocKind());
|
|
|
|
JSObject *obj = NewBuiltinClassInstance(cx, &ObjectClass, kind);
|
2010-11-18 18:14:22 -08:00
|
|
|
|
|
|
|
if (!obj || !obj->ensureSlots(cx, baseobj->numSlots()))
|
|
|
|
return NULL;
|
|
|
|
|
2011-07-15 10:14:07 -07:00
|
|
|
obj->setType(type);
|
2010-11-18 18:14:22 -08:00
|
|
|
obj->flags = baseobj->flags;
|
|
|
|
obj->lastProp = baseobj->lastProp;
|
|
|
|
|
|
|
|
return obj;
|
|
|
|
}
|
|
|
|
|
2011-03-05 15:29:30 -08:00
|
|
|
inline bool
|
2011-05-02 11:53:24 -07:00
|
|
|
DefineConstructorAndPrototype(JSContext *cx, GlobalObject *global,
|
2011-05-04 13:54:23 -07:00
|
|
|
JSProtoKey key, JSObject *ctor, JSObject *proto)
|
2011-03-05 15:29:30 -08:00
|
|
|
{
|
|
|
|
JS_ASSERT(!global->nativeEmpty()); /* reserved slots already allocated */
|
|
|
|
JS_ASSERT(ctor);
|
|
|
|
JS_ASSERT(proto);
|
|
|
|
|
|
|
|
jsid id = ATOM_TO_JSID(cx->runtime->atomState.classAtoms[key]);
|
2011-08-16 03:27:34 -07:00
|
|
|
JS_ASSERT(!global->nativeLookup(cx, id));
|
2011-03-05 15:29:30 -08:00
|
|
|
|
2011-06-02 10:40:27 -07:00
|
|
|
/* Set these first in case AddTypePropertyId looks for this class. */
|
2011-04-13 07:09:21 -07:00
|
|
|
global->setSlot(key, ObjectValue(*ctor));
|
|
|
|
global->setSlot(key + JSProto_LIMIT, ObjectValue(*proto));
|
2011-04-03 11:34:31 -07:00
|
|
|
|
2011-07-15 10:14:07 -07:00
|
|
|
types::AddTypePropertyId(cx, global, id, ObjectValue(*ctor));
|
2011-05-09 07:12:47 -07:00
|
|
|
if (!global->addDataProperty(cx, id, key + JSProto_LIMIT * 2, 0)) {
|
2011-04-13 07:09:21 -07:00
|
|
|
global->setSlot(key, UndefinedValue());
|
|
|
|
global->setSlot(key + JSProto_LIMIT, UndefinedValue());
|
2011-03-05 15:29:30 -08:00
|
|
|
return false;
|
2011-04-13 07:09:21 -07:00
|
|
|
}
|
2011-03-05 15:29:30 -08:00
|
|
|
|
|
|
|
global->setSlot(key + JSProto_LIMIT * 2, ObjectValue(*ctor));
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2011-07-21 15:36:09 -07:00
|
|
|
bool
|
|
|
|
PropDesc::checkGetter(JSContext *cx)
|
|
|
|
{
|
2011-07-12 18:19:13 -07:00
|
|
|
if (hasGet && !js_IsCallable(get) && !get.isUndefined()) {
|
|
|
|
JS_ReportErrorNumber(cx, js_GetErrorMessage, NULL, JSMSG_BAD_GET_SET_FIELD,
|
|
|
|
js_getter_str);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2011-07-21 15:36:09 -07:00
|
|
|
bool
|
|
|
|
PropDesc::checkSetter(JSContext *cx)
|
|
|
|
{
|
2011-07-12 18:19:13 -07:00
|
|
|
if (hasSet && !js_IsCallable(set) && !set.isUndefined()) {
|
|
|
|
JS_ReportErrorNumber(cx, js_GetErrorMessage, NULL, JSMSG_BAD_GET_SET_FIELD,
|
|
|
|
js_setter_str);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2010-06-18 17:43:02 -07:00
|
|
|
} /* namespace js */
|
2010-03-28 20:32:20 -07:00
|
|
|
|
2010-12-18 20:44:51 -08:00
|
|
|
inline JSObject *
|
|
|
|
js_GetProtoIfDenseArray(JSObject *obj)
|
|
|
|
{
|
|
|
|
return obj->isDenseArray() ? obj->getProto() : obj;
|
|
|
|
}
|
|
|
|
|
2009-11-18 12:29:58 -08:00
|
|
|
#endif /* jsobjinlines_h___ */
|