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-04-14 18:57:30 -07:00
|
|
|
#include "jsbool.h"
|
|
|
|
#include "jsdate.h"
|
2010-04-14 17:09:17 -07:00
|
|
|
#include "jsiter.h"
|
2010-04-14 18:57:30 -07:00
|
|
|
#include "jsobj.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-04-12 07:08:55 -07:00
|
|
|
#include "jsdtracef.h"
|
|
|
|
|
2010-06-16 14:13:01 -07:00
|
|
|
#include "jscntxt.h"
|
2010-04-10 16:16:35 -07:00
|
|
|
#include "jsscopeinlines.h"
|
|
|
|
|
2010-06-05 14:24:54 -07:00
|
|
|
inline void
|
|
|
|
JSObject::dropProperty(JSContext *cx, JSProperty *prop)
|
|
|
|
{
|
|
|
|
JS_ASSERT(prop);
|
|
|
|
if (isNative())
|
|
|
|
JS_UNLOCK_OBJ(cx, this);
|
|
|
|
}
|
|
|
|
|
2010-07-14 23:19:36 -07:00
|
|
|
inline js::Value
|
2010-04-05 18:32:16 -07:00
|
|
|
JSObject::getSlotMT(JSContext *cx, uintN slot)
|
|
|
|
{
|
2010-03-30 14:42:48 -07:00
|
|
|
#ifdef JS_THREADSAFE
|
|
|
|
/*
|
2010-03-31 22:13:51 -07:00
|
|
|
* If thread-safe, define a getSlotMT() that bypasses, for a native
|
2010-03-30 14:42:48 -07:00
|
|
|
* object, the lock-free "fast path" test of
|
2010-04-08 11:22:04 -07:00
|
|
|
* (obj->scope()->ownercx == cx), to avoid needlessly switching from
|
2010-03-30 14:42:48 -07:00
|
|
|
* lock-free to lock-full scope when doing GC on a different context
|
|
|
|
* from the last one to own the scope. The caller in this case is
|
2010-07-14 23:19:36 -07:00
|
|
|
* probably a Class.mark function, e.g., fun_mark, or maybe a
|
2010-03-30 14:42:48 -07:00
|
|
|
* finalizer.
|
|
|
|
*/
|
|
|
|
OBJ_CHECK_SLOT(this, slot);
|
2010-04-08 11:22:04 -07:00
|
|
|
return (scope()->title.ownercx == cx)
|
2010-07-14 23:19:36 -07:00
|
|
|
? this->lockedGetSlot(slot)
|
|
|
|
: js::Valueify(js_GetSlotThreadSafe(cx, this, slot));
|
2010-03-30 14:42:48 -07:00
|
|
|
#else
|
2010-04-08 11:22:04 -07:00
|
|
|
return this->lockedGetSlot(slot);
|
2010-03-30 14:42:48 -07:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
inline void
|
2010-07-14 23:19:36 -07:00
|
|
|
JSObject::setSlotMT(JSContext *cx, uintN slot, const js::Value &value)
|
2010-04-05 18:32:16 -07:00
|
|
|
{
|
2010-03-30 14:42:48 -07:00
|
|
|
#ifdef JS_THREADSAFE
|
|
|
|
/* Thread-safe way to set a slot. */
|
|
|
|
OBJ_CHECK_SLOT(this, slot);
|
2010-04-08 11:22:04 -07:00
|
|
|
if (scope()->title.ownercx == cx)
|
|
|
|
this->lockedSetSlot(slot, value);
|
2010-03-30 14:42:48 -07:00
|
|
|
else
|
2010-07-14 23:19:36 -07:00
|
|
|
js_SetSlotThreadSafe(cx, this, slot, js::Jsvalify(value));
|
2010-03-30 14:42:48 -07:00
|
|
|
#else
|
2010-04-08 11:22:04 -07:00
|
|
|
this->lockedSetSlot(slot, value);
|
2010-03-30 14:42:48 -07:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2010-07-14 23:19:36 -07:00
|
|
|
inline js::Value
|
2010-06-07 18:35:58 -07:00
|
|
|
JSObject::getReservedSlot(uintN index) const
|
|
|
|
{
|
|
|
|
uint32 slot = JSSLOT_START(getClass()) + index;
|
2010-07-14 23:19:36 -07:00
|
|
|
return (slot < numSlots()) ? getSlot(slot) : js::UndefinedValue();
|
2010-06-07 18:35:58 -07:00
|
|
|
}
|
|
|
|
|
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());
|
|
|
|
return fslots[JSSLOT_PRIMITIVE_THIS];
|
|
|
|
}
|
|
|
|
|
|
|
|
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());
|
|
|
|
fslots[JSSLOT_PRIMITIVE_THIS] = pthis;
|
|
|
|
}
|
|
|
|
|
2010-05-04 17:29:42 -07:00
|
|
|
inline void
|
|
|
|
JSObject::staticAssertArrayLengthIsInPrivateSlot()
|
2010-04-05 19:16:37 -07:00
|
|
|
{
|
|
|
|
JS_STATIC_ASSERT(JSSLOT_ARRAY_LENGTH == JSSLOT_PRIVATE);
|
|
|
|
}
|
|
|
|
|
2010-05-04 17:29:42 -07:00
|
|
|
inline bool
|
|
|
|
JSObject::isDenseArrayMinLenCapOk(bool strictAboutLength) const
|
2010-04-29 20:22:33 -07:00
|
|
|
{
|
|
|
|
JS_ASSERT(isDenseArray());
|
2010-05-04 17:29:42 -07:00
|
|
|
|
|
|
|
// This function can be called while the LENGTH and MINLENCAP slots are
|
|
|
|
// still set to JSVAL_VOID and there are no dslots (ie. the capacity is
|
|
|
|
// zero). If 'strictAboutLength' is false we allow this.
|
2010-07-14 23:19:36 -07:00
|
|
|
if (!strictAboutLength &&
|
|
|
|
fslots[JSSLOT_ARRAY_LENGTH].isUndefined() &&
|
|
|
|
uncheckedGetDenseArrayCapacity() == 0) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint32 length = uncheckedGetArrayLength();
|
|
|
|
uint32 capacity = uncheckedGetDenseArrayCapacity();
|
|
|
|
uint32 minLenCap = fslots[JSSLOT_DENSE_ARRAY_MINLENCAP].toPrivateUint32();
|
|
|
|
return minLenCap == JS_MIN(length, capacity);
|
2010-04-29 20:22:33 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
inline uint32
|
|
|
|
JSObject::uncheckedGetArrayLength() const
|
|
|
|
{
|
2010-07-14 23:19:36 -07:00
|
|
|
return fslots[JSSLOT_ARRAY_LENGTH].toPrivateUint32();
|
2010-04-29 20:22:33 -07:00
|
|
|
}
|
|
|
|
|
2010-04-05 18:32:16 -07:00
|
|
|
inline uint32
|
|
|
|
JSObject::getArrayLength() const
|
|
|
|
{
|
|
|
|
JS_ASSERT(isArray());
|
2010-04-29 20:22:33 -07:00
|
|
|
JS_ASSERT_IF(isDenseArray(), isDenseArrayMinLenCapOk());
|
|
|
|
return uncheckedGetArrayLength();
|
2010-04-05 18:32:16 -07:00
|
|
|
}
|
|
|
|
|
2010-04-14 18:57:30 -07:00
|
|
|
inline void
|
2010-04-29 20:22:33 -07:00
|
|
|
JSObject::setDenseArrayLength(uint32 length)
|
2010-04-05 18:32:16 -07:00
|
|
|
{
|
2010-04-29 20:22:33 -07:00
|
|
|
JS_ASSERT(isDenseArray());
|
2010-07-14 23:19:36 -07:00
|
|
|
fslots[JSSLOT_ARRAY_LENGTH].setPrivateUint32(length);
|
2010-04-29 20:22:33 -07:00
|
|
|
uint32 capacity = uncheckedGetDenseArrayCapacity();
|
2010-07-14 23:19:36 -07:00
|
|
|
fslots[JSSLOT_DENSE_ARRAY_MINLENCAP].setPrivateUint32(JS_MIN(length, capacity));
|
2010-04-29 20:22:33 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
inline void
|
|
|
|
JSObject::setSlowArrayLength(uint32 length)
|
|
|
|
{
|
|
|
|
JS_ASSERT(isSlowArray());
|
2010-07-14 23:19:36 -07:00
|
|
|
fslots[JSSLOT_ARRAY_LENGTH].setPrivateUint32(length);
|
2010-04-05 18:32:16 -07:00
|
|
|
}
|
|
|
|
|
2010-04-14 18:57:30 -07:00
|
|
|
inline uint32
|
2010-04-28 18:35:22 -07:00
|
|
|
JSObject::getDenseArrayCount() const
|
2010-04-05 18:32:16 -07:00
|
|
|
{
|
2010-04-28 18:35:22 -07:00
|
|
|
JS_ASSERT(isDenseArray());
|
2010-07-14 23:19:36 -07:00
|
|
|
return fslots[JSSLOT_DENSE_ARRAY_COUNT].toPrivateUint32();
|
2010-04-05 18:32:16 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
inline void
|
2010-04-28 18:35:22 -07:00
|
|
|
JSObject::setDenseArrayCount(uint32 count)
|
2010-04-05 18:32:16 -07:00
|
|
|
{
|
2010-04-28 18:35:22 -07:00
|
|
|
JS_ASSERT(isDenseArray());
|
2010-07-14 23:19:36 -07:00
|
|
|
fslots[JSSLOT_DENSE_ARRAY_COUNT].setPrivateUint32(count);
|
2010-04-05 18:32:16 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
inline void
|
2010-04-28 18:35:22 -07:00
|
|
|
JSObject::incDenseArrayCountBy(uint32 posDelta)
|
2010-04-05 18:32:16 -07:00
|
|
|
{
|
2010-04-28 18:35:22 -07:00
|
|
|
JS_ASSERT(isDenseArray());
|
2010-07-14 23:19:36 -07:00
|
|
|
fslots[JSSLOT_DENSE_ARRAY_COUNT].getPrivateUint32Ref() += posDelta;
|
2010-04-05 18:32:16 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
inline void
|
2010-04-28 18:35:22 -07:00
|
|
|
JSObject::decDenseArrayCountBy(uint32 negDelta)
|
2010-04-05 18:32:16 -07:00
|
|
|
{
|
2010-04-28 18:35:22 -07:00
|
|
|
JS_ASSERT(isDenseArray());
|
2010-07-14 23:19:36 -07:00
|
|
|
fslots[JSSLOT_DENSE_ARRAY_COUNT].getPrivateUint32Ref() -= negDelta;
|
2010-04-05 18:32:16 -07:00
|
|
|
}
|
|
|
|
|
2010-04-29 20:22:33 -07:00
|
|
|
inline uint32
|
|
|
|
JSObject::uncheckedGetDenseArrayCapacity() const
|
|
|
|
{
|
2010-07-14 23:19:36 -07:00
|
|
|
return dslots ? dslots[-1].toPrivateUint32() : 0;
|
2010-04-29 20:22:33 -07:00
|
|
|
}
|
|
|
|
|
2010-04-26 18:33:36 -07:00
|
|
|
inline uint32
|
|
|
|
JSObject::getDenseArrayCapacity() const
|
|
|
|
{
|
|
|
|
JS_ASSERT(isDenseArray());
|
2010-05-04 17:29:42 -07:00
|
|
|
JS_ASSERT(isDenseArrayMinLenCapOk(/* strictAboutLength = */false));
|
2010-04-29 20:22:33 -07:00
|
|
|
return uncheckedGetDenseArrayCapacity();
|
2010-04-26 18:33:36 -07:00
|
|
|
}
|
|
|
|
|
2010-04-05 18:32:16 -07:00
|
|
|
inline void
|
2010-04-26 18:33:36 -07:00
|
|
|
JSObject::setDenseArrayCapacity(uint32 capacity)
|
2010-04-05 18:32:16 -07:00
|
|
|
{
|
2010-04-26 18:33:36 -07:00
|
|
|
JS_ASSERT(isDenseArray());
|
|
|
|
JS_ASSERT(dslots);
|
2010-07-14 23:19:36 -07:00
|
|
|
dslots[-1].setPrivateUint32(capacity);
|
2010-04-29 20:22:33 -07:00
|
|
|
uint32 length = uncheckedGetArrayLength();
|
2010-07-14 23:19:36 -07:00
|
|
|
fslots[JSSLOT_DENSE_ARRAY_MINLENCAP].setPrivateUint32(JS_MIN(length, capacity));
|
2010-04-26 18:33:36 -07:00
|
|
|
}
|
|
|
|
|
2010-07-14 23:19:36 -07:00
|
|
|
inline const js::Value &
|
2010-04-26 18:33:36 -07:00
|
|
|
JSObject::getDenseArrayElement(uint32 i) const
|
|
|
|
{
|
|
|
|
JS_ASSERT(isDenseArray());
|
|
|
|
JS_ASSERT(i < getDenseArrayCapacity());
|
|
|
|
return dslots[i];
|
|
|
|
}
|
|
|
|
|
2010-07-14 23:19:36 -07:00
|
|
|
inline js::Value *
|
2010-05-04 20:28:38 -07:00
|
|
|
JSObject::addressOfDenseArrayElement(uint32 i)
|
|
|
|
{
|
|
|
|
JS_ASSERT(isDenseArray());
|
|
|
|
JS_ASSERT(i < getDenseArrayCapacity());
|
|
|
|
return &dslots[i];
|
|
|
|
}
|
|
|
|
|
2010-04-26 18:33:36 -07:00
|
|
|
inline void
|
2010-07-14 23:19:36 -07:00
|
|
|
JSObject::setDenseArrayElement(uint32 i, const js::Value &v)
|
2010-04-26 18:33:36 -07:00
|
|
|
{
|
|
|
|
JS_ASSERT(isDenseArray());
|
|
|
|
JS_ASSERT(i < getDenseArrayCapacity());
|
|
|
|
dslots[i] = v;
|
|
|
|
}
|
|
|
|
|
2010-07-14 23:19:36 -07:00
|
|
|
inline js::Value *
|
2010-04-26 18:33:36 -07:00
|
|
|
JSObject::getDenseArrayElements() const
|
|
|
|
{
|
|
|
|
JS_ASSERT(isDenseArray());
|
|
|
|
return dslots;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline void
|
|
|
|
JSObject::freeDenseArrayElements(JSContext *cx)
|
|
|
|
{
|
2010-04-29 20:22:33 -07:00
|
|
|
JS_ASSERT(isDenseArray());
|
2010-04-26 18:33:36 -07:00
|
|
|
if (dslots) {
|
|
|
|
cx->free(dslots - 1);
|
|
|
|
dslots = NULL;
|
|
|
|
}
|
2010-07-14 23:19:36 -07:00
|
|
|
fslots[JSSLOT_DENSE_ARRAY_MINLENCAP].setPrivateUint32(0);
|
|
|
|
JS_ASSERT(isDenseArrayMinLenCapOk(/* strictAboutLength = */false));
|
2010-04-29 20:22:33 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
inline void
|
|
|
|
JSObject::voidDenseOnlyArraySlots()
|
|
|
|
{
|
|
|
|
JS_ASSERT(isDenseArray());
|
2010-07-14 23:19:36 -07:00
|
|
|
fslots[JSSLOT_DENSE_ARRAY_COUNT].setUndefined();
|
|
|
|
fslots[JSSLOT_DENSE_ARRAY_MINLENCAP].setUndefined();
|
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-07-14 23:19:36 -07:00
|
|
|
fslots[JSSLOT_ARGS_LENGTH].setInt32(argc << 1);
|
2010-04-11 16:45:20 -07:00
|
|
|
JS_ASSERT(!isArgsLengthOverridden());
|
|
|
|
}
|
|
|
|
|
|
|
|
inline uint32
|
|
|
|
JSObject::getArgsLength() const
|
|
|
|
{
|
|
|
|
JS_ASSERT(isArguments());
|
2010-07-14 23:19:36 -07:00
|
|
|
uint32 argc = uint32(fslots[JSSLOT_ARGS_LENGTH].toInt32()) >> 1;
|
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-07-14 23:19:36 -07:00
|
|
|
fslots[JSSLOT_ARGS_LENGTH].getInt32Ref() |= 1;
|
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-07-14 23:19:36 -07:00
|
|
|
const js::Value &v = fslots[JSSLOT_ARGS_LENGTH];
|
|
|
|
return (v.toInt32() & 1) != 0;
|
2010-04-11 16:45:20 -07:00
|
|
|
}
|
|
|
|
|
2010-07-14 23:19:36 -07:00
|
|
|
inline const js::Value &
|
2010-04-11 16:45:20 -07:00
|
|
|
JSObject::getArgsCallee() const
|
|
|
|
{
|
|
|
|
JS_ASSERT(isArguments());
|
|
|
|
return fslots[JSSLOT_ARGS_CALLEE];
|
|
|
|
}
|
|
|
|
|
|
|
|
inline void
|
2010-07-14 23:19:36 -07:00
|
|
|
JSObject::setArgsCallee(const js::Value &callee)
|
2010-04-11 16:45:20 -07:00
|
|
|
{
|
|
|
|
JS_ASSERT(isArguments());
|
|
|
|
fslots[JSSLOT_ARGS_CALLEE] = callee;
|
|
|
|
}
|
|
|
|
|
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());
|
|
|
|
JS_ASSERT(i < numSlots() - JS_INITIAL_NSLOTS);
|
|
|
|
return dslots[i];
|
|
|
|
}
|
|
|
|
|
2010-07-14 23:19:36 -07:00
|
|
|
inline js::Value *
|
|
|
|
JSObject::addressOfArgsElement(uint32 i) const
|
|
|
|
{
|
|
|
|
JS_ASSERT(isArguments());
|
|
|
|
JS_ASSERT(i < numSlots() - JS_INITIAL_NSLOTS);
|
|
|
|
return &dslots[i];
|
|
|
|
}
|
|
|
|
|
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());
|
|
|
|
JS_ASSERT(i < numSlots() - JS_INITIAL_NSLOTS);
|
|
|
|
dslots[i] = v;
|
|
|
|
}
|
|
|
|
|
2010-07-14 23:19:36 -07:00
|
|
|
inline const js::Value &
|
2010-04-14 18:57:30 -07:00
|
|
|
JSObject::getDateLocalTime() const
|
|
|
|
{
|
|
|
|
JS_ASSERT(isDate());
|
|
|
|
return fslots[JSSLOT_DATE_LOCAL_TIME];
|
|
|
|
}
|
|
|
|
|
|
|
|
inline void
|
2010-07-14 23:19:36 -07:00
|
|
|
JSObject::setDateLocalTime(const js::Value &time)
|
2010-04-14 18:57:30 -07:00
|
|
|
{
|
|
|
|
JS_ASSERT(isDate());
|
|
|
|
fslots[JSSLOT_DATE_LOCAL_TIME] = time;
|
|
|
|
}
|
|
|
|
|
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());
|
|
|
|
return fslots[JSSLOT_DATE_UTC_TIME];
|
|
|
|
}
|
|
|
|
|
|
|
|
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());
|
|
|
|
fslots[JSSLOT_DATE_UTC_TIME] = time;
|
|
|
|
}
|
|
|
|
|
2010-07-14 23:19:36 -07:00
|
|
|
inline const js::Value &
|
2010-04-14 18:57:30 -07:00
|
|
|
JSObject::getRegExpLastIndex() const
|
|
|
|
{
|
|
|
|
JS_ASSERT(isRegExp());
|
|
|
|
return fslots[JSSLOT_REGEXP_LAST_INDEX];
|
|
|
|
}
|
|
|
|
|
2010-07-14 23:19:36 -07:00
|
|
|
inline void
|
|
|
|
JSObject::setRegExpLastIndex(const js::Value &v)
|
2010-04-14 18:57:30 -07:00
|
|
|
{
|
|
|
|
JS_ASSERT(isRegExp());
|
2010-07-14 23:19:36 -07:00
|
|
|
fslots[JSSLOT_REGEXP_LAST_INDEX] = v;
|
2010-04-14 18:57:30 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
inline void
|
|
|
|
JSObject::zeroRegExpLastIndex()
|
|
|
|
{
|
|
|
|
JS_ASSERT(isRegExp());
|
2010-07-14 23:19:36 -07:00
|
|
|
fslots[JSSLOT_REGEXP_LAST_INDEX].setInt32(0);
|
2010-04-14 18:57:30 -07:00
|
|
|
}
|
|
|
|
|
2010-05-07 17:52:52 -07:00
|
|
|
inline NativeIterator *
|
|
|
|
JSObject::getNativeIterator() const
|
|
|
|
{
|
|
|
|
return (NativeIterator *) getPrivate();
|
|
|
|
}
|
|
|
|
|
|
|
|
inline void
|
|
|
|
JSObject::setNativeIterator(NativeIterator *ni)
|
|
|
|
{
|
|
|
|
setPrivate(ni);
|
|
|
|
}
|
|
|
|
|
2010-05-12 18:57:36 -07:00
|
|
|
inline jsval
|
|
|
|
JSObject::getNamePrefix() const
|
|
|
|
{
|
|
|
|
JS_ASSERT(isNamespace() || isQName());
|
2010-07-14 23:19:36 -07:00
|
|
|
return js::Jsvalify(fslots[JSSLOT_NAME_PREFIX]);
|
2010-05-12 18:57:36 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
inline void
|
|
|
|
JSObject::setNamePrefix(jsval prefix)
|
|
|
|
{
|
|
|
|
JS_ASSERT(isNamespace() || isQName());
|
2010-07-14 23:19:36 -07:00
|
|
|
fslots[JSSLOT_NAME_PREFIX] = js::Valueify(prefix);
|
2010-05-12 18:57:36 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
inline jsval
|
|
|
|
JSObject::getNameURI() const
|
|
|
|
{
|
|
|
|
JS_ASSERT(isNamespace() || isQName());
|
2010-07-14 23:19:36 -07:00
|
|
|
return js::Jsvalify(fslots[JSSLOT_NAME_URI]);
|
2010-05-12 18:57:36 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
inline void
|
|
|
|
JSObject::setNameURI(jsval uri)
|
|
|
|
{
|
|
|
|
JS_ASSERT(isNamespace() || isQName());
|
2010-07-14 23:19:36 -07:00
|
|
|
fslots[JSSLOT_NAME_URI] = js::Valueify(uri);
|
2010-05-12 18:57:36 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
inline jsval
|
|
|
|
JSObject::getNamespaceDeclared() const
|
|
|
|
{
|
|
|
|
JS_ASSERT(isNamespace());
|
2010-07-14 23:19:36 -07:00
|
|
|
return js::Jsvalify(fslots[JSSLOT_NAMESPACE_DECLARED]);
|
2010-05-12 18:57:36 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
inline void
|
|
|
|
JSObject::setNamespaceDeclared(jsval decl)
|
|
|
|
{
|
|
|
|
JS_ASSERT(isNamespace());
|
2010-07-14 23:19:36 -07:00
|
|
|
fslots[JSSLOT_NAMESPACE_DECLARED] = js::Valueify(decl);
|
2010-05-12 18:57:36 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
inline jsval
|
|
|
|
JSObject::getQNameLocalName() const
|
|
|
|
{
|
|
|
|
JS_ASSERT(isQName());
|
2010-07-14 23:19:36 -07:00
|
|
|
return js::Jsvalify(fslots[JSSLOT_QNAME_LOCAL_NAME]);
|
2010-05-12 18:57:36 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
inline void
|
|
|
|
JSObject::setQNameLocalName(jsval name)
|
|
|
|
{
|
|
|
|
JS_ASSERT(isQName());
|
2010-07-14 23:19:36 -07:00
|
|
|
fslots[JSSLOT_QNAME_LOCAL_NAME] = js::Valueify(name);
|
2010-05-12 18:57:36 -07:00
|
|
|
}
|
|
|
|
|
2010-06-08 14:09:40 -07:00
|
|
|
inline JSObject *
|
|
|
|
JSObject::getWithThis() const
|
|
|
|
{
|
2010-07-14 23:19:36 -07:00
|
|
|
return &fslots[JSSLOT_WITH_THIS].toObject();
|
2010-06-08 14:09:40 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
inline void
|
|
|
|
JSObject::setWithThis(JSObject *thisp)
|
|
|
|
{
|
2010-07-14 23:19:36 -07:00
|
|
|
fslots[JSSLOT_WITH_THIS].setObject(*thisp);
|
2010-06-08 14:09:40 -07:00
|
|
|
}
|
|
|
|
|
2009-11-18 12:29:58 -08:00
|
|
|
inline void
|
2010-07-14 23:19:36 -07:00
|
|
|
JSObject::initSharingEmptyScope(js::Class *clasp, JSObject *proto, JSObject *parent,
|
|
|
|
const js::Value &privateSlotValue)
|
2009-11-18 12:29:58 -08:00
|
|
|
{
|
|
|
|
init(clasp, proto, parent, privateSlotValue);
|
|
|
|
|
2010-04-08 11:22:04 -07:00
|
|
|
JSEmptyScope *emptyScope = proto->scope()->emptyScope;
|
2009-11-18 12:29:58 -08:00
|
|
|
JS_ASSERT(emptyScope->clasp == clasp);
|
2010-06-01 15:01:11 -07:00
|
|
|
map = emptyScope->hold();
|
2009-11-18 12:29:58 -08:00
|
|
|
}
|
|
|
|
|
2009-12-30 03:06:26 -08:00
|
|
|
inline void
|
|
|
|
JSObject::freeSlotsArray(JSContext *cx)
|
|
|
|
{
|
|
|
|
JS_ASSERT(hasSlotsArray());
|
2010-07-14 23:19:36 -07:00
|
|
|
JS_ASSERT(dslots[-1].toPrivateUint32() > JS_INITIAL_NSLOTS);
|
2009-12-30 03:06:26 -08:00
|
|
|
cx->free(dslots - 1);
|
|
|
|
}
|
|
|
|
|
2010-01-14 09:33:14 -08:00
|
|
|
inline bool
|
|
|
|
JSObject::unbrand(JSContext *cx)
|
|
|
|
{
|
2010-03-31 22:13:51 -07:00
|
|
|
if (this->isNative()) {
|
2010-01-14 09:33:14 -08:00
|
|
|
JS_LOCK_OBJ(cx, this);
|
2010-04-08 11:22:04 -07:00
|
|
|
JSScope *scope = this->scope();
|
2010-01-26 22:50:17 -08:00
|
|
|
if (scope->isSharedEmpty()) {
|
2010-01-14 09:33:14 -08:00
|
|
|
scope = js_GetMutableScope(cx, this);
|
|
|
|
if (!scope) {
|
|
|
|
JS_UNLOCK_OBJ(cx, this);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
2010-06-02 16:45:23 -07:00
|
|
|
scope->unbrand(cx);
|
2010-01-14 09:33:14 -08:00
|
|
|
JS_UNLOCK_SCOPE(cx, scope);
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
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;
|
2010-07-14 23:19:36 -07:00
|
|
|
getter = setter = (PropertyOp) NULL;
|
|
|
|
value.setUndefined();
|
2010-05-18 19:21:43 -07:00
|
|
|
}
|
|
|
|
|
2010-07-14 23:19:36 -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-07-14 23:19:36 -07:00
|
|
|
InitScopeForObject(JSContext* cx, JSObject* obj, js::Class *clasp, JSObject* proto, JSObjectOps* ops)
|
2010-04-10 16:16:35 -07:00
|
|
|
{
|
|
|
|
JS_ASSERT(ops->isNative());
|
|
|
|
JS_ASSERT(proto == obj->getProto());
|
|
|
|
|
|
|
|
/* Share proto's emptyScope only if obj is similar to proto. */
|
|
|
|
JSScope *scope = NULL;
|
|
|
|
|
|
|
|
if (proto && proto->isNative()) {
|
|
|
|
JS_LOCK_OBJ(cx, proto);
|
|
|
|
scope = proto->scope();
|
|
|
|
if (scope->canProvideEmptyScope(ops, clasp)) {
|
|
|
|
JSScope *emptyScope = scope->getEmptyScope(cx, clasp);
|
|
|
|
JS_UNLOCK_SCOPE(cx, scope);
|
|
|
|
if (!emptyScope)
|
|
|
|
goto bad;
|
|
|
|
scope = emptyScope;
|
|
|
|
} else {
|
|
|
|
JS_UNLOCK_SCOPE(cx, scope);
|
|
|
|
scope = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!scope) {
|
|
|
|
scope = JSScope::create(cx, ops, clasp, obj, js_GenerateShape(cx, false));
|
|
|
|
if (!scope)
|
|
|
|
goto bad;
|
2010-06-18 17:43:02 -07:00
|
|
|
uint32 freeslot = JSSLOT_FREE(clasp);
|
|
|
|
JS_ASSERT(freeslot >= scope->freeslot);
|
|
|
|
if (freeslot > JS_INITIAL_NSLOTS && !obj->allocSlots(cx, freeslot))
|
2010-04-10 16:16:35 -07:00
|
|
|
goto bad;
|
2010-06-18 17:43:02 -07:00
|
|
|
scope->freeslot = freeslot;
|
|
|
|
#ifdef DEBUG
|
|
|
|
if (freeslot < obj->numSlots())
|
2010-07-14 23:19:36 -07:00
|
|
|
obj->setSlot(freeslot, UndefinedValue());
|
2010-06-18 17:43:02 -07:00
|
|
|
#endif
|
2010-04-10 16:16:35 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
obj->map = scope;
|
|
|
|
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
|
|
|
|
* class's prototype object). Use this in preference to NewObjectWithGivenProto
|
|
|
|
* and NewObject, but use NewBuiltinClassInstance if you need the default class
|
|
|
|
* prototype as proto, and its parent global as parent.
|
|
|
|
*/
|
2010-04-10 16:16:35 -07:00
|
|
|
static inline JSObject *
|
2010-07-14 23:19:36 -07:00
|
|
|
NewNativeClassInstance(JSContext *cx, Class *clasp, JSObject *proto, JSObject *parent)
|
2010-06-18 17:43:02 -07:00
|
|
|
{
|
|
|
|
JS_ASSERT(proto);
|
|
|
|
JS_ASSERT(proto->isNative());
|
|
|
|
JS_ASSERT(parent);
|
|
|
|
|
|
|
|
DTrace::ObjectCreationScope objectCreationScope(cx, cx->fp, clasp);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
JSObject* obj = js_NewGCObject(cx);
|
|
|
|
if (obj) {
|
|
|
|
/*
|
|
|
|
* Default parent to the parent of the prototype, which was set from
|
|
|
|
* the parent of the prototype's constructor.
|
|
|
|
*/
|
|
|
|
obj->init(clasp, proto, parent, JSObject::defaultPrivate(clasp));
|
|
|
|
|
|
|
|
JS_LOCK_OBJ(cx, proto);
|
|
|
|
JSScope *scope = proto->scope();
|
|
|
|
JS_ASSERT(scope->canProvideEmptyScope(&js_ObjectOps, clasp));
|
|
|
|
scope = scope->getEmptyScope(cx, clasp);
|
|
|
|
JS_UNLOCK_OBJ(cx, proto);
|
|
|
|
|
|
|
|
if (!scope) {
|
|
|
|
obj = NULL;
|
|
|
|
} else {
|
|
|
|
obj->map = scope;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Do not call debug hooks on trace, because we might be in a non-_FAIL
|
|
|
|
* builtin. See bug 481444.
|
|
|
|
*/
|
|
|
|
if (cx->debugHooks->objectHook && !JS_ON_TRACE(cx)) {
|
2010-07-14 23:19:36 -07:00
|
|
|
AutoObjectRooter tvr(cx, obj);
|
2010-06-18 17:43:02 -07:00
|
|
|
AutoKeepAtoms keep(cx->runtime);
|
|
|
|
cx->debugHooks->objectHook(cx, obj, JS_TRUE,
|
|
|
|
cx->debugHooks->objectHookData);
|
|
|
|
cx->weakRoots.finalizableNewborns[FINALIZE_OBJECT] = obj;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
objectCreationScope.handleCreation(obj);
|
|
|
|
return obj;
|
|
|
|
}
|
|
|
|
|
|
|
|
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-07-14 23:19:36 -07:00
|
|
|
NewBuiltinClassInstance(JSContext *cx, Class *clasp)
|
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;
|
|
|
|
if (!cx->fp) {
|
|
|
|
global = cx->globalObject;
|
|
|
|
OBJ_TO_INNER_OBJECT(cx, global);
|
|
|
|
if (!global)
|
|
|
|
return NULL;
|
|
|
|
} else {
|
|
|
|
global = cx->fp->scopeChain->getGlobal();
|
|
|
|
}
|
2010-06-18 17:43:02 -07:00
|
|
|
JS_ASSERT(global->getClass()->flags & JSCLASS_IS_GLOBAL);
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NewNativeClassInstance(cx, clasp, proto, global);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Like NewObject but with exactly the given proto. A null parent defaults to
|
|
|
|
* proto->getParent() if proto is non-null (else to null). NB: only this helper
|
|
|
|
* and NewObject can be used to construct full-sized JSFunction instances.
|
|
|
|
*/
|
|
|
|
static inline JSObject *
|
2010-07-14 23:19:36 -07:00
|
|
|
NewObjectWithGivenProto(JSContext *cx, Class *clasp, JSObject *proto, JSObject *parent)
|
2010-04-10 16:16:35 -07:00
|
|
|
{
|
2010-05-05 15:32:47 -07:00
|
|
|
DTrace::ObjectCreationScope objectCreationScope(cx, cx->fp, clasp);
|
2010-04-10 16:16:35 -07:00
|
|
|
|
|
|
|
/* Always call the class's getObjectOps hook if it has one. */
|
|
|
|
JSObjectOps *ops = clasp->getObjectOps
|
|
|
|
? clasp->getObjectOps(cx, clasp)
|
|
|
|
: &js_ObjectOps;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
JSObject* obj;
|
2010-06-18 17:43:02 -07:00
|
|
|
if (clasp == &js_FunctionClass) {
|
2010-04-10 16:16:35 -07:00
|
|
|
obj = (JSObject*) js_NewGCFunction(cx);
|
|
|
|
#ifdef DEBUG
|
|
|
|
if (obj) {
|
|
|
|
memset((uint8 *) obj + sizeof(JSObject), JS_FREE_PATTERN,
|
|
|
|
sizeof(JSFunction) - sizeof(JSObject));
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
} else {
|
2010-05-07 17:52:52 -07:00
|
|
|
obj = js_NewGCObject(cx);
|
2010-04-10 16:16:35 -07:00
|
|
|
}
|
|
|
|
if (!obj)
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Default parent to the parent of the prototype, which was set from
|
|
|
|
* the parent of the prototype's constructor.
|
|
|
|
*/
|
|
|
|
obj->init(clasp,
|
|
|
|
proto,
|
|
|
|
(!parent && proto) ? proto->getParent() : parent,
|
|
|
|
JSObject::defaultPrivate(clasp));
|
|
|
|
|
|
|
|
if (ops->isNative()) {
|
|
|
|
if (!InitScopeForObject(cx, obj, clasp, proto, ops)) {
|
|
|
|
obj = NULL;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
JS_ASSERT(ops->objectMap->ops == ops);
|
|
|
|
obj->map = const_cast<JSObjectMap *>(ops->objectMap);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Do not call debug hooks on trace, because we might be in a non-_FAIL
|
|
|
|
* builtin. See bug 481444.
|
|
|
|
*/
|
|
|
|
if (cx->debugHooks->objectHook && !JS_ON_TRACE(cx)) {
|
2010-07-14 23:19:36 -07:00
|
|
|
AutoObjectRooter tvr(cx, obj);
|
2010-04-10 16:16:35 -07:00
|
|
|
AutoKeepAtoms keep(cx->runtime);
|
|
|
|
cx->debugHooks->objectHook(cx, obj, JS_TRUE,
|
|
|
|
cx->debugHooks->objectHookData);
|
|
|
|
cx->weakRoots.finalizableNewborns[FINALIZE_OBJECT] = obj;
|
|
|
|
}
|
|
|
|
|
|
|
|
out:
|
2010-05-05 15:32:47 -07:00
|
|
|
objectCreationScope.handleCreation(obj);
|
2010-04-10 16:16:35 -07:00
|
|
|
return obj;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline JSProtoKey
|
2010-07-14 23:19:36 -07:00
|
|
|
GetClassProtoKey(js::Class *clasp)
|
2010-04-10 16:16:35 -07:00
|
|
|
{
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2010-06-18 17:43:02 -07:00
|
|
|
/*
|
|
|
|
* Create an instance of any class, native or not, JSFunction-sized or not.
|
|
|
|
*
|
|
|
|
* If proto is null, use the memoized original value of the class constructor
|
|
|
|
* .prototype property object for a built-in class, else the current value of
|
|
|
|
* .prototype if available, else Object.prototype.
|
|
|
|
*
|
|
|
|
* Default parent is null to proto's parent (null if proto is null too).
|
|
|
|
*/
|
2010-04-10 16:16:35 -07:00
|
|
|
static 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
|
|
|
{
|
|
|
|
/* Bootstrap the ur-object, and make it the default prototype object. */
|
|
|
|
if (!proto) {
|
|
|
|
JSProtoKey protoKey = GetClassProtoKey(clasp);
|
|
|
|
if (!js_GetClassPrototype(cx, parent, protoKey, &proto, clasp))
|
|
|
|
return NULL;
|
2010-06-18 17:43:02 -07:00
|
|
|
if (!proto && !js_GetClassPrototype(cx, parent, JSProto_Object, &proto))
|
2010-04-10 16:16:35 -07:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2010-06-18 17:43:02 -07:00
|
|
|
return NewObjectWithGivenProto(cx, clasp, proto, parent);
|
2010-04-10 16:16:35 -07:00
|
|
|
}
|
|
|
|
|
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___ */
|