2011-10-25 16:07:42 -07:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
2009-11-18 12:29:58 -08:00
|
|
|
* vim: set ts=8 sw=4 et tw=99:
|
|
|
|
*
|
|
|
|
* ***** BEGIN LICENSE BLOCK *****
|
|
|
|
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
|
|
|
*
|
|
|
|
* The contents of this file are subject to the Mozilla Public License Version
|
|
|
|
* 1.1 (the "License"); you may not use this file except in compliance with
|
|
|
|
* the License. You may obtain a copy of the License at
|
|
|
|
* http://www.mozilla.org/MPL/
|
|
|
|
*
|
|
|
|
* Software distributed under the License is distributed on an "AS IS" basis,
|
|
|
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
|
|
|
* for the specific language governing rights and limitations under the
|
|
|
|
* License.
|
|
|
|
*
|
|
|
|
* The Original Code is Mozilla 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>
|
2011-10-25 16:07:42 -07:00
|
|
|
|
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"
|
2011-10-25 16:07:42 -07:00
|
|
|
#include "jsgcmark.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"
|
2011-04-13 13:43:33 -07:00
|
|
|
#include "jstypedarray.h"
|
2010-05-12 18:57:36 -07:00
|
|
|
#include "jsxml.h"
|
2011-10-04 07:06:54 -07:00
|
|
|
#include "jswrapper.h"
|
2010-05-12 18:57:36 -07:00
|
|
|
|
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-10-25 16:07:42 -07:00
|
|
|
#include "gc/Barrier.h"
|
|
|
|
#include "js/TemplateLib.h"
|
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"
|
2011-03-14 13:59:53 -07:00
|
|
|
#include "jsscopeinlines.h"
|
2010-09-24 10:54:39 -07:00
|
|
|
|
2011-10-25 16:07:42 -07:00
|
|
|
#include "gc/Barrier-inl.h"
|
|
|
|
#include "vm/String-inl.h"
|
|
|
|
|
2011-10-10 17:14:38 -07:00
|
|
|
inline bool
|
|
|
|
JSObject::hasPrivate() const
|
2011-10-04 18:46:03 -07:00
|
|
|
{
|
2011-11-02 13:34:19 -07:00
|
|
|
return getClass()->hasPrivate();
|
2011-10-10 17:14:38 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
inline void *&
|
Bug 708735 - Use <stdint.h> types in JSAPI and throughout SpiderMonkey. Continue to provide the {u,}int{8,16,32,64} and JS{Uint,Int}{8,16,32,64} integer types through a single header, however, for a simpler backout strategy -- and also to ease the transition for embedders. r=timeless on switching the jsd API to use the <stdint.h> types, r=luke, r=dmandelin
2011-12-08 19:54:10 -08:00
|
|
|
JSObject::privateRef(uint32_t nfixed) const
|
2011-10-10 17:14:38 -07:00
|
|
|
{
|
|
|
|
/*
|
|
|
|
* The private pointer of an object can hold any word sized value.
|
|
|
|
* Private pointers are stored immediately after the last fixed slot of
|
|
|
|
* the object.
|
|
|
|
*/
|
|
|
|
JS_ASSERT(nfixed == numFixedSlots());
|
2011-11-02 13:34:19 -07:00
|
|
|
JS_ASSERT(hasPrivate());
|
2011-11-14 09:13:33 -08:00
|
|
|
js::HeapValue *end = &fixedSlots()[nfixed];
|
2011-10-10 17:14:38 -07:00
|
|
|
return *reinterpret_cast<void**>(end);
|
2011-10-04 18:46:03 -07:00
|
|
|
}
|
|
|
|
|
2011-10-10 17:14:38 -07:00
|
|
|
inline void *
|
2011-11-08 13:08:13 -08:00
|
|
|
JSObject::getPrivate() const { return privateRef(numFixedSlots()); }
|
2011-10-10 17:14:38 -07:00
|
|
|
|
|
|
|
inline void *
|
2011-11-08 13:08:13 -08:00
|
|
|
JSObject::getPrivate(size_t nfixed) const { return privateRef(nfixed); }
|
2011-10-10 17:14:38 -07:00
|
|
|
|
2011-10-04 18:46:03 -07:00
|
|
|
inline void
|
|
|
|
JSObject::setPrivate(void *data)
|
|
|
|
{
|
2011-11-14 09:13:33 -08:00
|
|
|
void **pprivate = &privateRef(numFixedSlots());
|
|
|
|
|
|
|
|
privateWriteBarrierPre(pprivate);
|
|
|
|
*pprivate = data;
|
|
|
|
privateWriteBarrierPost(pprivate);
|
2011-10-04 18:46:03 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
inline bool
|
|
|
|
JSObject::enumerate(JSContext *cx, JSIterateOp iterop, js::Value *statep, jsid *idp)
|
|
|
|
{
|
|
|
|
JSNewEnumerateOp op = getOps()->enumerate;
|
|
|
|
return (op ? op : JS_EnumerateState)(cx, this, iterop, statep, idp);
|
|
|
|
}
|
|
|
|
|
|
|
|
inline bool
|
|
|
|
JSObject::defaultValue(JSContext *cx, JSType hint, js::Value *vp)
|
|
|
|
{
|
|
|
|
JSConvertOp op = getClass()->convert;
|
|
|
|
bool ok = (op == JS_ConvertStub ? js::DefaultValue : op)(cx, this, hint, vp);
|
|
|
|
JS_ASSERT_IF(ok, vp->isPrimitive());
|
|
|
|
return ok;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline JSType
|
|
|
|
JSObject::typeOf(JSContext *cx)
|
|
|
|
{
|
|
|
|
js::TypeOfOp op = getOps()->typeOf;
|
|
|
|
return (op ? op : js_TypeOf)(cx, this);
|
|
|
|
}
|
|
|
|
|
|
|
|
inline JSObject *
|
|
|
|
JSObject::thisObject(JSContext *cx)
|
|
|
|
{
|
|
|
|
JSObjectOp op = getOps()->thisObject;
|
|
|
|
return op ? op(cx, this) : this;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline JSBool
|
2011-10-05 17:16:25 -07:00
|
|
|
JSObject::setGeneric(JSContext *cx, jsid id, js::Value *vp, JSBool strict)
|
2011-10-04 18:46:03 -07:00
|
|
|
{
|
2011-10-05 17:16:25 -07:00
|
|
|
if (getOps()->setGeneric)
|
|
|
|
return nonNativeSetProperty(cx, id, vp, strict);
|
|
|
|
return js_SetPropertyHelper(cx, this, id, 0, vp, strict);
|
2011-10-04 18:46:03 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
inline JSBool
|
2011-10-05 17:16:25 -07:00
|
|
|
JSObject::setProperty(JSContext *cx, js::PropertyName *name, js::Value *vp, JSBool strict)
|
2011-10-04 18:46:03 -07:00
|
|
|
{
|
2011-10-05 17:16:25 -07:00
|
|
|
return setGeneric(cx, ATOM_TO_JSID(name), vp, strict);
|
2011-10-04 18:46:03 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
inline JSBool
|
Bug 708735 - Use <stdint.h> types in JSAPI and throughout SpiderMonkey. Continue to provide the {u,}int{8,16,32,64} and JS{Uint,Int}{8,16,32,64} integer types through a single header, however, for a simpler backout strategy -- and also to ease the transition for embedders. r=timeless on switching the jsd API to use the <stdint.h> types, r=luke, r=dmandelin
2011-12-08 19:54:10 -08:00
|
|
|
JSObject::setElement(JSContext *cx, uint32_t index, js::Value *vp, JSBool strict)
|
2011-10-04 18:46:03 -07:00
|
|
|
{
|
|
|
|
if (getOps()->setElement)
|
|
|
|
return nonNativeSetElement(cx, index, vp, strict);
|
|
|
|
return js_SetElementHelper(cx, this, index, 0, vp, strict);
|
|
|
|
}
|
|
|
|
|
|
|
|
inline JSBool
|
2011-10-05 17:16:25 -07:00
|
|
|
JSObject::setSpecial(JSContext *cx, js::SpecialId sid, js::Value *vp, JSBool strict)
|
2011-10-04 18:46:03 -07:00
|
|
|
{
|
2011-10-05 17:16:25 -07:00
|
|
|
return setGeneric(cx, SPECIALID_TO_JSID(sid), vp, strict);
|
2011-10-04 18:46:03 -07:00
|
|
|
}
|
|
|
|
|
2011-04-11 20:10:46 -07:00
|
|
|
inline JSBool
|
2011-10-04 17:21:06 -07:00
|
|
|
JSObject::setGenericAttributes(JSContext *cx, jsid id, uintN *attrsp)
|
2011-04-11 20:10:46 -07:00
|
|
|
{
|
2011-07-15 10:14:07 -07:00
|
|
|
js::types::MarkTypePropertyConfigured(cx, this, id);
|
2011-10-04 17:21:06 -07:00
|
|
|
js::GenericAttributesOp op = getOps()->setGenericAttributes;
|
2011-04-11 20:10:46 -07:00
|
|
|
return (op ? op : js_SetAttributes)(cx, this, id, attrsp);
|
|
|
|
}
|
|
|
|
|
2011-10-04 18:46:03 -07:00
|
|
|
inline JSBool
|
2011-10-04 17:21:06 -07:00
|
|
|
JSObject::setPropertyAttributes(JSContext *cx, js::PropertyName *name, uintN *attrsp)
|
2011-10-04 18:46:03 -07:00
|
|
|
{
|
2011-10-04 17:21:06 -07:00
|
|
|
return setGenericAttributes(cx, ATOM_TO_JSID(name), attrsp);
|
2011-10-04 18:46:03 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
inline JSBool
|
Bug 708735 - Use <stdint.h> types in JSAPI and throughout SpiderMonkey. Continue to provide the {u,}int{8,16,32,64} and JS{Uint,Int}{8,16,32,64} integer types through a single header, however, for a simpler backout strategy -- and also to ease the transition for embedders. r=timeless on switching the jsd API to use the <stdint.h> types, r=luke, r=dmandelin
2011-12-08 19:54:10 -08:00
|
|
|
JSObject::setElementAttributes(JSContext *cx, uint32_t index, uintN *attrsp)
|
2011-10-04 18:46:03 -07:00
|
|
|
{
|
|
|
|
js::ElementAttributesOp op = getOps()->setElementAttributes;
|
|
|
|
return (op ? op : js_SetElementAttributes)(cx, this, index, attrsp);
|
|
|
|
}
|
|
|
|
|
2011-10-04 17:21:06 -07:00
|
|
|
inline JSBool
|
|
|
|
JSObject::setSpecialAttributes(JSContext *cx, js::SpecialId sid, uintN *attrsp)
|
|
|
|
{
|
|
|
|
return setGenericAttributes(cx, SPECIALID_TO_JSID(sid), 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
|
2011-10-04 17:49:57 -07:00
|
|
|
JSObject::deleteGeneric(JSContext *cx, jsid id, js::Value *rval, JSBool strict)
|
2011-03-21 22:55:27 -07:00
|
|
|
{
|
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-10-04 17:49:57 -07:00
|
|
|
js::DeleteGenericOp op = getOps()->deleteGeneric;
|
2011-03-21 22:55:27 -07:00
|
|
|
return (op ? op : js_DeleteProperty)(cx, this, id, rval, strict);
|
|
|
|
}
|
|
|
|
|
2011-10-04 17:49:57 -07:00
|
|
|
inline JSBool
|
|
|
|
JSObject::deleteProperty(JSContext *cx, js::PropertyName *name, js::Value *rval, JSBool strict)
|
|
|
|
{
|
|
|
|
return deleteGeneric(cx, ATOM_TO_JSID(name), rval, strict);
|
|
|
|
}
|
|
|
|
|
|
|
|
inline JSBool
|
Bug 708735 - Use <stdint.h> types in JSAPI and throughout SpiderMonkey. Continue to provide the {u,}int{8,16,32,64} and JS{Uint,Int}{8,16,32,64} integer types through a single header, however, for a simpler backout strategy -- and also to ease the transition for embedders. r=timeless on switching the jsd API to use the <stdint.h> types, r=luke, r=dmandelin
2011-12-08 19:54:10 -08:00
|
|
|
JSObject::deleteElement(JSContext *cx, uint32_t index, js::Value *rval, JSBool strict)
|
2011-10-04 17:49:57 -07:00
|
|
|
{
|
|
|
|
jsid id;
|
|
|
|
if (!js::IndexToId(cx, index, &id))
|
|
|
|
return false;
|
|
|
|
return deleteGeneric(cx, id, rval, strict);
|
|
|
|
}
|
|
|
|
|
|
|
|
inline JSBool
|
|
|
|
JSObject::deleteSpecial(JSContext *cx, js::SpecialId sid, js::Value *rval, JSBool strict)
|
|
|
|
{
|
|
|
|
return deleteGeneric(cx, SPECIALID_TO_JSID(sid), rval, strict);
|
|
|
|
}
|
|
|
|
|
2010-09-24 10:54:39 -07:00
|
|
|
inline void
|
2011-09-29 20:29:13 -07:00
|
|
|
JSObject::finalize(JSContext *cx, bool background)
|
2010-09-24 10:54:39 -07:00
|
|
|
{
|
2010-09-20 12:43:53 -07:00
|
|
|
js::Probes::finalizeObject(this);
|
|
|
|
|
2011-09-29 20:29:13 -07:00
|
|
|
if (!background) {
|
|
|
|
/*
|
|
|
|
* Finalize obj first, in case it needs map and slots. Objects with
|
2011-10-05 11:54:28 -07:00
|
|
|
* finalize hooks are not finalized in the background, as the class is
|
|
|
|
* stored in the object's shape, which may have already been destroyed.
|
2011-09-29 20:29:13 -07:00
|
|
|
*/
|
|
|
|
js::Class *clasp = getClass();
|
|
|
|
if (clasp->finalize)
|
|
|
|
clasp->finalize(cx, this);
|
|
|
|
}
|
2010-09-24 10:54:39 -07:00
|
|
|
|
|
|
|
finish(cx);
|
|
|
|
}
|
|
|
|
|
2011-10-12 22:29:43 -07:00
|
|
|
inline JSObject *
|
|
|
|
JSObject::getParent() const
|
|
|
|
{
|
2011-10-13 20:21:36 -07:00
|
|
|
return lastProperty()->getObjectParent();
|
2011-10-12 22:29:43 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
inline bool
|
2011-11-09 09:52:59 -08:00
|
|
|
JSObject::isInternalScope() const
|
2011-10-12 22:29:43 -07:00
|
|
|
{
|
2011-10-13 20:21:36 -07:00
|
|
|
return isCall() || isDeclEnv() || isBlock() || isWith();
|
2011-10-12 22:29:43 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
inline JSObject *
|
2011-11-09 09:52:59 -08:00
|
|
|
JSObject::internalScopeChain() const
|
2011-10-12 22:29:43 -07:00
|
|
|
{
|
2011-11-09 09:52:59 -08:00
|
|
|
JS_ASSERT(isInternalScope());
|
|
|
|
return &getFixedSlot(SCOPE_CHAIN_SLOT).toObject();
|
2011-10-12 22:29:43 -07:00
|
|
|
}
|
|
|
|
|
2011-11-09 09:52:59 -08:00
|
|
|
inline bool
|
|
|
|
JSObject::setInternalScopeChain(JSContext *cx, JSObject *obj)
|
2011-10-12 22:29:43 -07:00
|
|
|
{
|
2011-11-09 09:52:59 -08:00
|
|
|
JS_ASSERT(isInternalScope());
|
|
|
|
if (!obj->setDelegate(cx))
|
|
|
|
return false;
|
|
|
|
setFixedSlot(SCOPE_CHAIN_SLOT, JS::ObjectValue(*obj));
|
|
|
|
return true;
|
2011-10-12 22:29:43 -07:00
|
|
|
}
|
|
|
|
|
2011-11-09 09:52:59 -08:00
|
|
|
/*static*/ inline size_t
|
|
|
|
JSObject::offsetOfInternalScopeChain()
|
2011-10-13 20:21:36 -07:00
|
|
|
{
|
2011-11-09 09:52:59 -08:00
|
|
|
return getFixedSlotOffset(SCOPE_CHAIN_SLOT);
|
2011-11-08 16:14:34 -08:00
|
|
|
}
|
|
|
|
|
2011-10-12 22:29:43 -07:00
|
|
|
inline JSObject *
|
2011-11-09 09:52:59 -08:00
|
|
|
JSObject::scopeChain() const
|
2011-10-12 22:29:43 -07:00
|
|
|
{
|
2011-11-09 09:52:59 -08:00
|
|
|
return isInternalScope() ? internalScopeChain() : getParent();
|
2011-10-12 22:29:43 -07:00
|
|
|
}
|
|
|
|
|
2011-11-09 09:52:59 -08:00
|
|
|
inline JSObject *
|
2011-10-07 12:02:50 -07:00
|
|
|
JSObject::staticBlockScopeChain() const
|
2011-10-12 22:29:43 -07:00
|
|
|
{
|
2011-11-09 09:52:59 -08:00
|
|
|
JS_ASSERT(isStaticBlock());
|
|
|
|
return getFixedSlot(SCOPE_CHAIN_SLOT).toObjectOrNull();
|
2011-10-12 22:29:43 -07:00
|
|
|
}
|
|
|
|
|
2011-11-09 09:52:59 -08:00
|
|
|
inline void
|
|
|
|
JSObject::setStaticBlockScopeChain(JSObject *obj)
|
2011-10-12 22:29:43 -07:00
|
|
|
{
|
2011-11-09 09:52:59 -08:00
|
|
|
JS_ASSERT(isStaticBlock());
|
|
|
|
setFixedSlot(SCOPE_CHAIN_SLOT, JS::ObjectOrNullValue(obj));
|
2011-10-12 22:29:43 -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-11-10 17:50:05 -08:00
|
|
|
inline 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
|
|
|
|
2011-10-11 15:28:54 -07:00
|
|
|
JSFunction *fun = vp->toObject().toFunction();
|
|
|
|
JS_ASSERT(!fun->isClonedMethod());
|
2011-08-18 10:39:44 -07:00
|
|
|
JS_ASSERT(fun->isNullClosure());
|
2010-08-29 11:57:08 -07:00
|
|
|
|
2011-10-12 22:29:43 -07:00
|
|
|
fun = js::CloneFunctionObject(cx, fun);
|
2011-10-11 15:28:54 -07:00
|
|
|
if (!fun)
|
2011-02-15 12:11:04 -08:00
|
|
|
return NULL;
|
2011-10-11 15:28:54 -07:00
|
|
|
fun->setMethodObj(*this);
|
2010-08-29 11:57:08 -07:00
|
|
|
|
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.
|
|
|
|
*/
|
Bug 708735 - Use <stdint.h> types in JSAPI and throughout SpiderMonkey. Continue to provide the {u,}int{8,16,32,64} and JS{Uint,Int}{8,16,32,64} integer types through a single header, however, for a simpler backout strategy -- and also to ease the transition for embedders. r=timeless on switching the jsd API to use the <stdint.h> types, r=luke, r=dmandelin
2011-12-08 19:54:10 -08:00
|
|
|
uint32_t slot = shape.slot();
|
2011-11-10 17:50:05 -08:00
|
|
|
js::Shape *newshape = methodShapeChange(cx, shape);
|
2011-02-08 14:09:33 -08:00
|
|
|
if (!newshape)
|
|
|
|
return NULL;
|
|
|
|
JS_ASSERT(!newshape->isMethod());
|
2011-09-28 15:04:55 -07:00
|
|
|
JS_ASSERT(newshape->slot() == slot);
|
2011-10-11 15:28:54 -07:00
|
|
|
vp->setObject(*fun);
|
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-04-08 19:51:40 -07:00
|
|
|
inline bool
|
|
|
|
JSObject::isFixedSlot(size_t slot)
|
|
|
|
{
|
|
|
|
JS_ASSERT(!isDenseArray());
|
|
|
|
return slot < numFixedSlots();
|
|
|
|
}
|
|
|
|
|
2011-07-02 06:38:36 -07:00
|
|
|
inline size_t
|
2011-10-10 11:41:03 -07:00
|
|
|
JSObject::dynamicSlotIndex(size_t slot)
|
2011-07-02 06:38:36 -07:00
|
|
|
{
|
2011-10-10 11:41:03 -07:00
|
|
|
JS_ASSERT(!isDenseArray() && slot >= numFixedSlots());
|
|
|
|
return slot - numFixedSlots();
|
|
|
|
}
|
|
|
|
|
|
|
|
/*static*/ inline size_t
|
|
|
|
JSObject::dynamicSlotsCount(size_t nfixed, size_t span)
|
|
|
|
{
|
|
|
|
if (span <= nfixed)
|
|
|
|
return 0;
|
|
|
|
span -= nfixed;
|
|
|
|
if (span <= SLOT_CAPACITY_MIN)
|
|
|
|
return SLOT_CAPACITY_MIN;
|
|
|
|
|
2011-11-08 13:03:33 -08:00
|
|
|
size_t slots = js::RoundUpPow2(span);
|
2011-10-10 11:41:03 -07:00
|
|
|
JS_ASSERT(slots >= span);
|
|
|
|
return slots;
|
2011-07-02 06:38:36 -07:00
|
|
|
}
|
|
|
|
|
2011-04-08 19:51:40 -07:00
|
|
|
inline size_t
|
2011-10-10 11:41:03 -07:00
|
|
|
JSObject::numDynamicSlots() const
|
2011-04-08 19:51:40 -07:00
|
|
|
{
|
2011-10-10 11:41:03 -07:00
|
|
|
return dynamicSlotsCount(numFixedSlots(), slotSpan());
|
2011-04-08 19:51:40 -07:00
|
|
|
}
|
|
|
|
|
2011-10-10 11:41:03 -07:00
|
|
|
inline void
|
|
|
|
JSObject::setLastPropertyInfallible(const js::Shape *shape)
|
2010-08-29 11:57:08 -07:00
|
|
|
{
|
2011-10-10 11:41:03 -07:00
|
|
|
JS_ASSERT(!shape->inDictionary());
|
|
|
|
JS_ASSERT(shape->compartment() == compartment());
|
|
|
|
JS_ASSERT(!inDictionaryMode());
|
|
|
|
JS_ASSERT(slotSpan() == shape->slotSpan());
|
2011-10-14 11:06:15 -07:00
|
|
|
JS_ASSERT(numFixedSlots() == shape->numFixedSlots());
|
2011-10-10 11:41:03 -07:00
|
|
|
|
|
|
|
shape_ = const_cast<js::Shape *>(shape);
|
2010-08-29 11:57:08 -07:00
|
|
|
}
|
|
|
|
|
2011-10-13 20:21:36 -07:00
|
|
|
inline void
|
|
|
|
JSObject::removeLastProperty(JSContext *cx)
|
|
|
|
{
|
|
|
|
JS_ASSERT(canRemoveLastProperty());
|
|
|
|
JS_ALWAYS_TRUE(setLastProperty(cx, lastProperty()->previous()));
|
|
|
|
}
|
|
|
|
|
|
|
|
inline bool
|
|
|
|
JSObject::canRemoveLastProperty()
|
|
|
|
{
|
|
|
|
/*
|
2011-11-09 09:52:59 -08:00
|
|
|
* Check that the information about the object stored in the last
|
|
|
|
* property's base shape is consistent with that stored in the previous
|
|
|
|
* shape. If not consistent, then the last property cannot be removed as it
|
|
|
|
* will induce a change in the object itself, and the object must be
|
|
|
|
* converted to dictionary mode instead. See BaseShape comment in jsscope.h
|
2011-10-13 20:21:36 -07:00
|
|
|
*/
|
|
|
|
JS_ASSERT(!inDictionaryMode());
|
|
|
|
const js::Shape *previous = lastProperty()->previous();
|
2011-10-14 13:51:21 -07:00
|
|
|
return previous->getObjectParent() == lastProperty()->getObjectParent()
|
|
|
|
&& previous->getObjectFlags() == lastProperty()->getObjectFlags();
|
2011-10-13 20:21:36 -07:00
|
|
|
}
|
|
|
|
|
2011-11-14 09:13:33 -08:00
|
|
|
inline const js::HeapValue *
|
|
|
|
JSObject::getRawSlots()
|
2010-08-29 11:57:08 -07:00
|
|
|
{
|
2011-11-14 09:13:33 -08:00
|
|
|
JS_ASSERT(isGlobal());
|
|
|
|
return slots;
|
2010-08-29 11:57:08 -07:00
|
|
|
}
|
|
|
|
|
2010-07-14 23:19:36 -07:00
|
|
|
inline js::Value
|
2010-06-07 18:35:58 -07:00
|
|
|
JSObject::getReservedSlot(uintN index) const
|
|
|
|
{
|
2011-10-10 11:41:03 -07:00
|
|
|
JS_ASSERT(index < JSSLOT_FREE(getClass()));
|
|
|
|
return getSlot(index);
|
2010-06-07 18:35:58 -07:00
|
|
|
}
|
|
|
|
|
2011-10-25 16:07:42 -07:00
|
|
|
inline js::HeapValue &
|
|
|
|
JSObject::getReservedSlotRef(uintN index)
|
|
|
|
{
|
2011-11-14 09:13:33 -08:00
|
|
|
JS_ASSERT(index < JSSLOT_FREE(getClass()));
|
2011-10-25 16:07:42 -07:00
|
|
|
return getSlotRef(index);
|
|
|
|
}
|
|
|
|
|
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-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.
|
|
|
|
*/
|
2011-11-08 13:03:33 -08:00
|
|
|
JS_ASSERT(slotInRange(start + count, SENTINEL_ALLOWED));
|
2011-09-01 12:20:30 -07:00
|
|
|
return (start + count <= numFixedSlots()) || (start >= numFixedSlots());
|
|
|
|
}
|
|
|
|
|
2011-10-25 16:07:42 -07:00
|
|
|
inline void
|
|
|
|
JSObject::prepareSlotRangeForOverwrite(size_t start, size_t end)
|
|
|
|
{
|
2011-11-14 09:13:33 -08:00
|
|
|
for (size_t i = start; i < end; i++)
|
2011-11-14 18:46:47 -08:00
|
|
|
getSlotAddressUnchecked(i)->js::HeapValue::~HeapValue();
|
2011-04-08 19:51:40 -07:00
|
|
|
}
|
2010-10-13 11:49:22 -07:00
|
|
|
|
2011-11-14 09:13:33 -08:00
|
|
|
inline void
|
|
|
|
JSObject::prepareElementRangeForOverwrite(size_t start, size_t end)
|
2011-04-08 19:51:40 -07:00
|
|
|
{
|
2011-11-14 09:13:33 -08:00
|
|
|
JS_ASSERT(isDenseArray());
|
|
|
|
JS_ASSERT(end <= getDenseArrayInitializedLength());
|
|
|
|
for (size_t i = start; i < end; i++)
|
|
|
|
elements[i].js::HeapValue::~HeapValue();
|
2010-04-05 19:16:37 -07:00
|
|
|
}
|
|
|
|
|
Bug 708735 - Use <stdint.h> types in JSAPI and throughout SpiderMonkey. Continue to provide the {u,}int{8,16,32,64} and JS{Uint,Int}{8,16,32,64} integer types through a single header, however, for a simpler backout strategy -- and also to ease the transition for embedders. r=timeless on switching the jsd API to use the <stdint.h> types, r=luke, r=dmandelin
2011-12-08 19:54:10 -08:00
|
|
|
inline uint32_t
|
2010-04-05 18:32:16 -07:00
|
|
|
JSObject::getArrayLength() const
|
|
|
|
{
|
|
|
|
JS_ASSERT(isArray());
|
2011-10-10 11:41:03 -07:00
|
|
|
return getElementsHeader()->length;
|
2010-04-29 20:22:33 -07:00
|
|
|
}
|
|
|
|
|
2011-05-16 16:15:37 -07:00
|
|
|
inline void
|
Bug 708735 - Use <stdint.h> types in JSAPI and throughout SpiderMonkey. Continue to provide the {u,}int{8,16,32,64} and JS{Uint,Int}{8,16,32,64} integer types through a single header, however, for a simpler backout strategy -- and also to ease the transition for embedders. r=timeless on switching the jsd API to use the <stdint.h> types, r=luke, r=dmandelin
2011-12-08 19:54:10 -08:00
|
|
|
JSObject::setArrayLength(JSContext *cx, uint32_t 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-10-10 11:41:03 -07:00
|
|
|
getElementsHeader()->length = length;
|
2011-03-03 14:07:48 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
inline void
|
Bug 708735 - Use <stdint.h> types in JSAPI and throughout SpiderMonkey. Continue to provide the {u,}int{8,16,32,64} and JS{Uint,Int}{8,16,32,64} integer types through a single header, however, for a simpler backout strategy -- and also to ease the transition for embedders. r=timeless on switching the jsd API to use the <stdint.h> types, r=luke, r=dmandelin
2011-12-08 19:54:10 -08:00
|
|
|
JSObject::setDenseArrayLength(uint32_t length)
|
2011-03-03 14:07:48 -08:00
|
|
|
{
|
|
|
|
/* Variant of setArrayLength for use on dense arrays where the length cannot overflow int32. */
|
|
|
|
JS_ASSERT(isDenseArray());
|
|
|
|
JS_ASSERT(length <= INT32_MAX);
|
2011-10-10 11:41:03 -07:00
|
|
|
getElementsHeader()->length = length;
|
2010-04-05 18:32:16 -07:00
|
|
|
}
|
|
|
|
|
Bug 708735 - Use <stdint.h> types in JSAPI and throughout SpiderMonkey. Continue to provide the {u,}int{8,16,32,64} and JS{Uint,Int}{8,16,32,64} integer types through a single header, however, for a simpler backout strategy -- and also to ease the transition for embedders. r=timeless on switching the jsd API to use the <stdint.h> types, r=luke, r=dmandelin
2011-12-08 19:54:10 -08:00
|
|
|
inline uint32_t
|
2011-10-27 14:16:02 -07:00
|
|
|
JSObject::getDenseArrayInitializedLength()
|
|
|
|
{
|
|
|
|
JS_ASSERT(isDenseArray());
|
|
|
|
return getElementsHeader()->initializedLength;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline void
|
Bug 708735 - Use <stdint.h> types in JSAPI and throughout SpiderMonkey. Continue to provide the {u,}int{8,16,32,64} and JS{Uint,Int}{8,16,32,64} integer types through a single header, however, for a simpler backout strategy -- and also to ease the transition for embedders. r=timeless on switching the jsd API to use the <stdint.h> types, r=luke, r=dmandelin
2011-12-08 19:54:10 -08:00
|
|
|
JSObject::setDenseArrayInitializedLength(uint32_t length)
|
2011-10-27 14:16:02 -07:00
|
|
|
{
|
|
|
|
JS_ASSERT(isDenseArray());
|
|
|
|
JS_ASSERT(length <= getDenseArrayCapacity());
|
2011-12-06 14:56:48 -08:00
|
|
|
prepareElementRangeForOverwrite(length, getElementsHeader()->initializedLength);
|
2011-10-27 14:16:02 -07:00
|
|
|
getElementsHeader()->initializedLength = length;
|
2010-04-05 18:32:16 -07:00
|
|
|
}
|
|
|
|
|
Bug 708735 - Use <stdint.h> types in JSAPI and throughout SpiderMonkey. Continue to provide the {u,}int{8,16,32,64} and JS{Uint,Int}{8,16,32,64} integer types through a single header, however, for a simpler backout strategy -- and also to ease the transition for embedders. r=timeless on switching the jsd API to use the <stdint.h> types, r=luke, r=dmandelin
2011-12-08 19:54:10 -08:00
|
|
|
inline uint32_t
|
2010-10-13 11:49:22 -07:00
|
|
|
JSObject::getDenseArrayCapacity()
|
2010-04-26 18:33:36 -07:00
|
|
|
{
|
|
|
|
JS_ASSERT(isDenseArray());
|
2011-10-10 11:41:03 -07:00
|
|
|
return getElementsHeader()->capacity;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline bool
|
Bug 708735 - Use <stdint.h> types in JSAPI and throughout SpiderMonkey. Continue to provide the {u,}int{8,16,32,64} and JS{Uint,Int}{8,16,32,64} integer types through a single header, however, for a simpler backout strategy -- and also to ease the transition for embedders. r=timeless on switching the jsd API to use the <stdint.h> types, r=luke, r=dmandelin
2011-12-08 19:54:10 -08:00
|
|
|
JSObject::ensureElements(JSContext *cx, uint32_t capacity)
|
2011-10-10 11:41:03 -07:00
|
|
|
{
|
|
|
|
if (capacity > getDenseArrayCapacity())
|
|
|
|
return growElements(cx, capacity);
|
|
|
|
return true;
|
2010-04-26 18:33:36 -07:00
|
|
|
}
|
|
|
|
|
2011-10-25 16:07:42 -07:00
|
|
|
inline js::HeapValueArray
|
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-11-14 09:13:33 -08:00
|
|
|
return js::HeapValueArray(elements);
|
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-10-10 11:41:03 -07:00
|
|
|
return elements[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-10-10 11:41:03 -07:00
|
|
|
elements[idx] = val;
|
2010-04-26 18:33:36 -07:00
|
|
|
}
|
|
|
|
|
2011-10-25 16:07:42 -07:00
|
|
|
inline void
|
|
|
|
JSObject::initDenseArrayElement(uintN idx, const js::Value &val)
|
|
|
|
{
|
|
|
|
JS_ASSERT(isDenseArray() && idx < getDenseArrayInitializedLength());
|
2011-11-14 09:13:33 -08:00
|
|
|
elements[idx].init(val);
|
2011-10-25 16:07:42 -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-10-25 16:07:42 -07:00
|
|
|
inline void
|
|
|
|
JSObject::initDenseArrayElementWithType(JSContext *cx, uintN idx, const js::Value &val)
|
|
|
|
{
|
|
|
|
js::types::AddTypePropertyId(cx, this, JSID_VOID, val);
|
|
|
|
initDenseArrayElement(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-10-25 16:07:42 -07:00
|
|
|
{
|
2011-11-14 09:13:33 -08:00
|
|
|
JS_ASSERT(dstStart + count <= getDenseArrayCapacity());
|
2011-12-15 15:27:32 -08:00
|
|
|
for (unsigned i = 0; i < count; ++i)
|
|
|
|
elements[dstStart + i] = src[i];
|
2011-10-25 16:07:42 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
inline void
|
|
|
|
JSObject::initDenseArrayElements(uintN dstStart, const js::Value *src, uintN count)
|
2011-07-13 15:43:33 -07:00
|
|
|
{
|
2011-10-10 11:41:03 -07:00
|
|
|
JS_ASSERT(dstStart + count <= getDenseArrayCapacity());
|
2011-12-15 15:27:32 -08:00
|
|
|
for (unsigned i = 0; i < count; ++i)
|
|
|
|
elements[dstStart + i].init(src[i]);
|
2011-07-13 15:43:33 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
inline void
|
|
|
|
JSObject::moveDenseArrayElements(uintN dstStart, uintN srcStart, uintN count)
|
|
|
|
{
|
2011-10-10 11:41:03 -07:00
|
|
|
JS_ASSERT(dstStart + count <= getDenseArrayCapacity());
|
|
|
|
JS_ASSERT(srcStart + count <= getDenseArrayCapacity());
|
2011-10-25 16:07:42 -07:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Use a custom write barrier here since it's performance sensitive. We
|
2011-11-14 09:13:33 -08:00
|
|
|
* only want to barrier the elements that are being overwritten.
|
2011-10-25 16:07:42 -07:00
|
|
|
*/
|
|
|
|
uintN markStart, markEnd;
|
|
|
|
if (dstStart > srcStart) {
|
|
|
|
markStart = js::Max(srcStart + count, dstStart);
|
|
|
|
markEnd = dstStart + count;
|
|
|
|
} else {
|
|
|
|
markStart = dstStart;
|
|
|
|
markEnd = js::Min(dstStart + count, srcStart);
|
|
|
|
}
|
2011-11-14 09:13:33 -08:00
|
|
|
prepareElementRangeForOverwrite(markStart, markEnd);
|
2010-04-26 18:33:36 -07:00
|
|
|
|
2011-10-10 11:41:03 -07:00
|
|
|
memmove(elements + dstStart, elements + srcStart, count * sizeof(js::Value));
|
2010-04-05 18:32:16 -07:00
|
|
|
}
|
|
|
|
|
2011-04-08 19:51:40 -07:00
|
|
|
inline bool
|
|
|
|
JSObject::denseArrayHasInlineSlots() const
|
|
|
|
{
|
2011-10-10 11:41:03 -07:00
|
|
|
JS_ASSERT(isDenseArray());
|
|
|
|
return elements == fixedElements();
|
2011-04-08 19:51:40 -07:00
|
|
|
}
|
|
|
|
|
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-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-10-25 16:07:42 -07:00
|
|
|
setFixedSlot(JSSLOT_WITH_THIS, js::ObjectValue(*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;
|
|
|
|
|
2011-10-10 11:41:03 -07:00
|
|
|
JS_ASSERT(!lastProperty()->previous());
|
2011-07-15 10:14:07 -07:00
|
|
|
JS_ASSERT(!hasLazyType());
|
|
|
|
JS_ASSERT_IF(getProto(), type() == getProto()->getNewType(cx, NULL));
|
|
|
|
|
2011-10-14 14:54:04 -07:00
|
|
|
js::types::TypeObject *type = cx->compartment->getLazyType(cx, getProto());
|
|
|
|
if (!type)
|
|
|
|
return false;
|
2011-07-15 10:14:07 -07:00
|
|
|
|
2011-10-14 14:54:04 -07:00
|
|
|
type_ = type;
|
2011-07-15 10:14:07 -07:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline js::types::TypeObject *
|
|
|
|
JSObject::getType(JSContext *cx)
|
|
|
|
{
|
|
|
|
if (hasLazyType())
|
|
|
|
makeLazyType(cx);
|
|
|
|
return type_;
|
|
|
|
}
|
|
|
|
|
2011-10-07 20:09:09 -07:00
|
|
|
inline bool
|
|
|
|
JSObject::clearType(JSContext *cx)
|
2010-12-18 20:44:51 -08:00
|
|
|
{
|
2011-07-15 10:14:07 -07:00
|
|
|
JS_ASSERT(!hasSingletonType());
|
2011-10-07 20:09:09 -07:00
|
|
|
|
|
|
|
js::types::TypeObject *type = cx->compartment->getEmptyType(cx);
|
|
|
|
if (!type)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
type_ = type;
|
|
|
|
return true;
|
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-11-02 13:34:19 -07:00
|
|
|
JS_ASSERT_IF(hasSpecialEquality(),
|
2011-10-14 13:51:21 -07:00
|
|
|
newType->hasAnyFlags(js::types::OBJECT_FLAG_SPECIAL_EQUALITY));
|
2011-11-02 13:34:19 -07:00
|
|
|
JS_ASSERT(!hasSingletonType());
|
2011-07-15 10:14:07 -07:00
|
|
|
type_ = newType;
|
2011-03-16 10:02:19 -07:00
|
|
|
}
|
|
|
|
|
2011-11-16 12:52:47 -08:00
|
|
|
inline bool JSObject::setIteratedSingleton(JSContext *cx)
|
|
|
|
{
|
2011-10-14 13:51:21 -07:00
|
|
|
return setFlag(cx, js::BaseShape::ITERATED_SINGLETON);
|
|
|
|
}
|
|
|
|
|
2011-11-16 12:52:47 -08:00
|
|
|
inline bool JSObject::isSystem() const
|
|
|
|
{
|
|
|
|
return lastProperty()->hasObjectFlag(js::BaseShape::SYSTEM);
|
|
|
|
}
|
|
|
|
|
|
|
|
inline bool JSObject::setSystem(JSContext *cx)
|
|
|
|
{
|
2011-10-14 13:51:21 -07:00
|
|
|
return setFlag(cx, js::BaseShape::SYSTEM);
|
|
|
|
}
|
|
|
|
|
2011-11-16 12:52:47 -08:00
|
|
|
inline bool JSObject::isDelegate() const
|
|
|
|
{
|
|
|
|
return lastProperty()->hasObjectFlag(js::BaseShape::DELEGATE);
|
|
|
|
}
|
|
|
|
|
|
|
|
inline bool JSObject::setDelegate(JSContext *cx)
|
|
|
|
{
|
2011-10-14 13:51:21 -07:00
|
|
|
return setFlag(cx, js::BaseShape::DELEGATE, GENERATE_SHAPE);
|
|
|
|
}
|
|
|
|
|
2011-11-16 12:52:47 -08:00
|
|
|
inline bool JSObject::isVarObj() const
|
|
|
|
{
|
|
|
|
return lastProperty()->hasObjectFlag(js::BaseShape::VAROBJ);
|
|
|
|
}
|
|
|
|
|
|
|
|
inline bool JSObject::setVarObj(JSContext *cx)
|
|
|
|
{
|
2011-10-14 13:51:21 -07:00
|
|
|
return setFlag(cx, js::BaseShape::VAROBJ);
|
|
|
|
}
|
|
|
|
|
2011-11-16 12:52:47 -08:00
|
|
|
inline bool JSObject::setWatched(JSContext *cx)
|
|
|
|
{
|
2011-10-14 13:51:21 -07:00
|
|
|
return setFlag(cx, js::BaseShape::WATCHED, GENERATE_SHAPE);
|
|
|
|
}
|
|
|
|
|
2011-11-16 12:52:47 -08:00
|
|
|
inline bool JSObject::hasUncacheableProto() const
|
|
|
|
{
|
|
|
|
return lastProperty()->hasObjectFlag(js::BaseShape::UNCACHEABLE_PROTO);
|
|
|
|
}
|
2011-10-14 13:51:21 -07:00
|
|
|
|
2011-11-29 13:37:18 -08:00
|
|
|
inline bool JSObject::setUncacheableProto(JSContext *cx)
|
|
|
|
{
|
|
|
|
return setFlag(cx, js::BaseShape::UNCACHEABLE_PROTO, GENERATE_SHAPE);
|
|
|
|
}
|
|
|
|
|
2011-11-16 12:52:47 -08:00
|
|
|
inline bool JSObject::isExtensible() const
|
|
|
|
{
|
|
|
|
return !lastProperty()->hasObjectFlag(js::BaseShape::NOT_EXTENSIBLE);
|
|
|
|
}
|
|
|
|
|
|
|
|
inline bool JSObject::isBoundFunction() const
|
|
|
|
{
|
|
|
|
return lastProperty()->hasObjectFlag(js::BaseShape::BOUND_FUNCTION);
|
|
|
|
}
|
|
|
|
|
|
|
|
inline bool JSObject::isIndexed() const
|
|
|
|
{
|
|
|
|
return lastProperty()->hasObjectFlag(js::BaseShape::INDEXED);
|
|
|
|
}
|
|
|
|
|
|
|
|
inline bool JSObject::watched() const
|
|
|
|
{
|
|
|
|
return lastProperty()->hasObjectFlag(js::BaseShape::WATCHED);
|
|
|
|
}
|
|
|
|
|
|
|
|
inline bool JSObject::hasSpecialEquality() const
|
|
|
|
{
|
2011-10-14 13:51:21 -07:00
|
|
|
return !!getClass()->ext.equality;
|
|
|
|
}
|
|
|
|
|
2011-10-04 18:46:03 -07:00
|
|
|
inline bool JSObject::isArguments() const { return isNormalArguments() || isStrictArguments(); }
|
|
|
|
inline bool JSObject::isArrayBuffer() const { return hasClass(&js::ArrayBufferClass); }
|
|
|
|
inline bool JSObject::isNormalArguments() const { return hasClass(&js::NormalArgumentsObjectClass); }
|
|
|
|
inline bool JSObject::isStrictArguments() const { return hasClass(&js::StrictArgumentsObjectClass); }
|
|
|
|
inline bool JSObject::isNumber() const { return hasClass(&js::NumberClass); }
|
|
|
|
inline bool JSObject::isBoolean() const { return hasClass(&js::BooleanClass); }
|
|
|
|
inline bool JSObject::isString() const { return hasClass(&js::StringClass); }
|
|
|
|
inline bool JSObject::isPrimitive() const { return isNumber() || isString() || isBoolean(); }
|
|
|
|
inline bool JSObject::isDate() const { return hasClass(&js::DateClass); }
|
|
|
|
inline bool JSObject::isFunction() const { return hasClass(&js::FunctionClass); }
|
|
|
|
inline bool JSObject::isObject() const { return hasClass(&js::ObjectClass); }
|
|
|
|
inline bool JSObject::isWith() const { return hasClass(&js::WithClass); }
|
|
|
|
inline bool JSObject::isBlock() const { return hasClass(&js::BlockClass); }
|
|
|
|
inline bool JSObject::isStaticBlock() const { return isBlock() && !getProto(); }
|
|
|
|
inline bool JSObject::isClonedBlock() const { return isBlock() && !!getProto(); }
|
|
|
|
inline bool JSObject::isCall() const { return hasClass(&js::CallClass); }
|
|
|
|
inline bool JSObject::isDeclEnv() const { return hasClass(&js::DeclEnvClass); }
|
|
|
|
inline bool JSObject::isRegExp() const { return hasClass(&js::RegExpClass); }
|
|
|
|
inline bool JSObject::isScript() const { return hasClass(&js::ScriptClass); }
|
|
|
|
inline bool JSObject::isGenerator() const { return hasClass(&js::GeneratorClass); }
|
|
|
|
inline bool JSObject::isIterator() const { return hasClass(&js::IteratorClass); }
|
|
|
|
inline bool JSObject::isStopIteration() const { return hasClass(&js::StopIterationClass); }
|
|
|
|
inline bool JSObject::isError() const { return hasClass(&js::ErrorClass); }
|
|
|
|
inline bool JSObject::isXML() const { return hasClass(&js::XMLClass); }
|
|
|
|
inline bool JSObject::isNamespace() const { return hasClass(&js::NamespaceClass); }
|
|
|
|
inline bool JSObject::isWeakMap() const { return hasClass(&js::WeakMapClass); }
|
|
|
|
inline bool JSObject::isFunctionProxy() const { return hasClass(&js::FunctionProxyClass); }
|
|
|
|
|
2011-10-10 11:41:03 -07:00
|
|
|
inline bool JSObject::isArray() const
|
|
|
|
{
|
|
|
|
return isSlowArray() || isDenseArray();
|
|
|
|
}
|
|
|
|
|
|
|
|
inline bool JSObject::isDenseArray() const
|
|
|
|
{
|
|
|
|
bool result = hasClass(&js::ArrayClass);
|
|
|
|
JS_ASSERT_IF(result, elements != js::emptyObjectElements);
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline bool JSObject::isSlowArray() const
|
|
|
|
{
|
|
|
|
bool result = hasClass(&js::SlowArrayClass);
|
|
|
|
JS_ASSERT_IF(result, elements != js::emptyObjectElements);
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2011-10-04 18:46:03 -07:00
|
|
|
inline bool
|
|
|
|
JSObject::isXMLId() const
|
|
|
|
{
|
|
|
|
return hasClass(&js::QNameClass)
|
|
|
|
|| hasClass(&js::AttributeNameClass)
|
|
|
|
|| hasClass(&js::AnyNameClass);
|
|
|
|
}
|
|
|
|
|
|
|
|
inline bool
|
|
|
|
JSObject::isQName() const
|
|
|
|
{
|
|
|
|
return hasClass(&js::QNameClass)
|
|
|
|
|| hasClass(&js::AttributeNameClass)
|
|
|
|
|| hasClass(&js::AnyNameClass);
|
|
|
|
}
|
|
|
|
|
2009-11-18 12:29:58 -08:00
|
|
|
inline void
|
2011-11-14 09:13:33 -08:00
|
|
|
JSObject::initializeSlotRange(size_t start, size_t length)
|
2009-11-18 12:29:58 -08:00
|
|
|
{
|
2011-11-14 18:46:47 -08:00
|
|
|
/*
|
|
|
|
* No bounds check, as this is used when the object's shape does not
|
|
|
|
* reflect its allocated slots (updateSlotsForSpan).
|
|
|
|
*/
|
2011-11-02 13:34:19 -07:00
|
|
|
JS_ASSERT(!isDenseArray());
|
|
|
|
size_t fixed = numFixedSlots();
|
|
|
|
if (start < fixed) {
|
|
|
|
if (start + length < fixed) {
|
2011-11-14 13:03:50 -08:00
|
|
|
js::InitValueRange(fixedSlots() + start, length, false);
|
2011-11-02 13:34:19 -07:00
|
|
|
} else {
|
|
|
|
size_t localClear = fixed - start;
|
2011-11-14 13:03:50 -08:00
|
|
|
js::InitValueRange(fixedSlots() + start, localClear, false);
|
|
|
|
js::InitValueRange(slots, length - localClear, false);
|
2011-11-02 13:34:19 -07:00
|
|
|
}
|
|
|
|
} else {
|
2011-11-14 13:03:50 -08:00
|
|
|
js::InitValueRange(slots + start - fixed, length, false);
|
2011-11-02 13:34:19 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-11-18 14:59:31 -08:00
|
|
|
/* static */ inline JSObject *
|
|
|
|
JSObject::create(JSContext *cx, js::gc::AllocKind kind,
|
|
|
|
js::Shape *shape, js::types::TypeObject *type, js::HeapValue *slots)
|
2011-11-02 13:34:19 -07:00
|
|
|
{
|
|
|
|
/*
|
|
|
|
* Callers must use dynamicSlotsCount to size the initial slot array of the
|
|
|
|
* object. We can't check the allocated capacity of the dynamic slots, but
|
|
|
|
* make sure their presence is consistent with the shape.
|
|
|
|
*/
|
|
|
|
JS_ASSERT(shape && type);
|
|
|
|
JS_ASSERT(!!dynamicSlotsCount(shape->numFixedSlots(), shape->slotSpan()) == !!slots);
|
2011-11-18 14:59:31 -08:00
|
|
|
JS_ASSERT(js::gc::GetGCKindSlots(kind, shape->getObjectClass()) == shape->numFixedSlots());
|
|
|
|
|
|
|
|
JSObject *obj = js_NewGCObject(cx, kind);
|
|
|
|
if (!obj)
|
|
|
|
return NULL;
|
2011-11-02 13:34:19 -07:00
|
|
|
|
2011-11-18 14:59:31 -08:00
|
|
|
obj->shape_.init(shape);
|
|
|
|
obj->type_.init(type);
|
|
|
|
obj->slots = slots;
|
|
|
|
obj->elements = js::emptyObjectElements;
|
2011-11-02 13:34:19 -07:00
|
|
|
|
|
|
|
if (shape->getObjectClass()->hasPrivate())
|
2011-11-22 15:21:10 -08:00
|
|
|
obj->privateRef(shape->numFixedSlots()) = NULL;
|
2011-11-18 14:59:31 -08:00
|
|
|
|
|
|
|
if (size_t span = shape->slotSpan())
|
|
|
|
obj->initializeSlotRange(0, span);
|
2011-03-19 16:53:07 -07:00
|
|
|
|
2011-11-18 14:59:31 -08:00
|
|
|
return obj;
|
2010-09-10 17:06:30 -07:00
|
|
|
}
|
|
|
|
|
2011-11-18 14:59:31 -08:00
|
|
|
/* static */ inline JSObject *
|
|
|
|
JSObject::createDenseArray(JSContext *cx, js::gc::AllocKind kind,
|
Bug 708735 - Use <stdint.h> types in JSAPI and throughout SpiderMonkey. Continue to provide the {u,}int{8,16,32,64} and JS{Uint,Int}{8,16,32,64} integer types through a single header, however, for a simpler backout strategy -- and also to ease the transition for embedders. r=timeless on switching the jsd API to use the <stdint.h> types, r=luke, r=dmandelin
2011-12-08 19:54:10 -08:00
|
|
|
js::Shape *shape, js::types::TypeObject *type, uint32_t length)
|
2011-10-14 11:06:15 -07:00
|
|
|
{
|
2011-11-02 13:34:19 -07:00
|
|
|
JS_ASSERT(shape && type);
|
|
|
|
JS_ASSERT(shape->getObjectClass() == &js::ArrayClass);
|
2011-10-14 11:06:15 -07:00
|
|
|
|
2011-11-21 16:20:39 -08:00
|
|
|
/*
|
|
|
|
* Dense arrays are non-native, and never have properties to store.
|
|
|
|
* The number of fixed slots in the shape of such objects is zero.
|
|
|
|
*/
|
|
|
|
JS_ASSERT(shape->numFixedSlots() == 0);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* The array initially stores its elements inline, there must be enough
|
|
|
|
* space for an elements header.
|
|
|
|
*/
|
|
|
|
JS_ASSERT(js::gc::GetGCKindSlots(kind) >= js::ObjectElements::VALUES_PER_HEADER);
|
|
|
|
|
Bug 708735 - Use <stdint.h> types in JSAPI and throughout SpiderMonkey. Continue to provide the {u,}int{8,16,32,64} and JS{Uint,Int}{8,16,32,64} integer types through a single header, however, for a simpler backout strategy -- and also to ease the transition for embedders. r=timeless on switching the jsd API to use the <stdint.h> types, r=luke, r=dmandelin
2011-12-08 19:54:10 -08:00
|
|
|
uint32_t capacity = js::gc::GetGCKindSlots(kind) - js::ObjectElements::VALUES_PER_HEADER;
|
2011-10-14 11:06:15 -07:00
|
|
|
|
2011-11-18 14:59:31 -08:00
|
|
|
JSObject *obj = js_NewGCObject(cx, kind);
|
|
|
|
if (!obj)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
obj->shape_.init(shape);
|
|
|
|
obj->type_.init(type);
|
|
|
|
obj->slots = NULL;
|
|
|
|
obj->setFixedElements();
|
2011-11-21 16:20:39 -08:00
|
|
|
new (obj->getElementsHeader()) js::ObjectElements(capacity, length);
|
2011-11-18 14:59:31 -08:00
|
|
|
|
|
|
|
return obj;
|
2011-10-14 11:06:15 -07:00
|
|
|
}
|
|
|
|
|
2010-08-29 11:57:08 -07:00
|
|
|
inline void
|
|
|
|
JSObject::finish(JSContext *cx)
|
2009-11-18 12:29:58 -08:00
|
|
|
{
|
2011-10-10 11:41:03 -07:00
|
|
|
if (hasDynamicSlots())
|
2011-04-08 19:51:40 -07:00
|
|
|
cx->free_(slots);
|
2011-10-10 11:41:03 -07:00
|
|
|
if (hasDynamicElements())
|
|
|
|
cx->free_(getElementsHeader());
|
2010-08-29 11:57:08 -07:00
|
|
|
}
|
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);
|
2011-10-08 15:45:04 -07:00
|
|
|
if (!lookupGeneric(cx, id, &pobj, &prop))
|
2010-08-29 11:57:08 -07:00
|
|
|
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
|
|
|
}
|
|
|
|
|
Bug 708735 - Use <stdint.h> types in JSAPI and throughout SpiderMonkey. Continue to provide the {u,}int{8,16,32,64} and JS{Uint,Int}{8,16,32,64} integer types through a single header, however, for a simpler backout strategy -- and also to ease the transition for embedders. r=timeless on switching the jsd API to use the <stdint.h> types, r=luke, r=dmandelin
2011-12-08 19:54:10 -08:00
|
|
|
inline uint32_t
|
2011-04-08 14:21:08 -07:00
|
|
|
JSObject::slotSpan() const
|
|
|
|
{
|
2011-10-05 11:54:28 -07:00
|
|
|
if (inDictionaryMode())
|
2011-10-10 11:41:03 -07:00
|
|
|
return lastProperty()->base()->slotSpan();
|
|
|
|
return lastProperty()->slotSpan();
|
2011-04-08 14:21:08 -07:00
|
|
|
}
|
|
|
|
|
2011-10-25 16:07:42 -07:00
|
|
|
inline js::HeapValue &
|
2011-04-08 14:21:08 -07:00
|
|
|
JSObject::nativeGetSlotRef(uintN slot)
|
|
|
|
{
|
|
|
|
JS_ASSERT(isNative());
|
2011-12-21 06:31:11 -08:00
|
|
|
JS_ASSERT(slot < slotSpan());
|
2011-04-08 14:21:08 -07:00
|
|
|
return getSlotRef(slot);
|
|
|
|
}
|
|
|
|
|
|
|
|
inline const js::Value &
|
|
|
|
JSObject::nativeGetSlot(uintN slot) const
|
|
|
|
{
|
|
|
|
JS_ASSERT(isNative());
|
2011-12-21 06:31:11 -08:00
|
|
|
JS_ASSERT(slot < slotSpan());
|
2011-04-08 14:21:08 -07:00
|
|
|
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();
|
2011-10-11 15:28:54 -07:00
|
|
|
JS_ASSERT(obj->isFunction() && !obj->toFunction()->isClonedMethod());
|
2011-09-28 15:04:55 -07:00
|
|
|
#endif
|
|
|
|
|
2011-10-05 11:54:28 -07:00
|
|
|
return static_cast<JSFunction *>(&nativeGetSlot(shape->slot()).toObject());
|
2011-09-28 15:04:55 -07:00
|
|
|
}
|
|
|
|
|
2011-04-08 14:21:08 -07:00
|
|
|
inline void
|
|
|
|
JSObject::nativeSetSlot(uintN slot, const js::Value &value)
|
|
|
|
{
|
|
|
|
JS_ASSERT(isNative());
|
2011-12-21 06:31:11 -08:00
|
|
|
JS_ASSERT(slot < slotSpan());
|
2011-04-08 14:21:08 -07:00
|
|
|
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
|
|
|
|
{
|
2011-10-10 11:41:03 -07:00
|
|
|
return lastProperty()->isNative();
|
2011-04-08 14:21:08 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
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-10-11 16:46:42 -07:00
|
|
|
return js::Shape::search(cx, &shape_, 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 bool
|
|
|
|
JSObject::nativeEmpty() const
|
|
|
|
{
|
|
|
|
return lastProperty()->isEmptyShape();
|
|
|
|
}
|
|
|
|
|
|
|
|
inline bool
|
|
|
|
JSObject::inDictionaryMode() const
|
|
|
|
{
|
|
|
|
return lastProperty()->inDictionary();
|
|
|
|
}
|
|
|
|
|
Bug 708735 - Use <stdint.h> types in JSAPI and throughout SpiderMonkey. Continue to provide the {u,}int{8,16,32,64} and JS{Uint,Int}{8,16,32,64} integer types through a single header, however, for a simpler backout strategy -- and also to ease the transition for embedders. r=timeless on switching the jsd API to use the <stdint.h> types, r=luke, r=dmandelin
2011-12-08 19:54:10 -08:00
|
|
|
inline uint32_t
|
2011-04-08 14:21:08 -07:00
|
|
|
JSObject::propertyCount() const
|
|
|
|
{
|
|
|
|
return lastProperty()->entryCount();
|
|
|
|
}
|
|
|
|
|
|
|
|
inline bool
|
|
|
|
JSObject::hasPropertyTable() const
|
|
|
|
{
|
|
|
|
return lastProperty()->hasTable();
|
|
|
|
}
|
|
|
|
|
2011-10-10 11:41:03 -07:00
|
|
|
inline size_t
|
|
|
|
JSObject::structSize() const
|
2011-04-08 14:21:08 -07:00
|
|
|
{
|
2011-11-21 16:20:39 -08:00
|
|
|
return arenaHeader()->getThingSize();
|
2011-04-08 14:21:08 -07:00
|
|
|
}
|
|
|
|
|
2011-10-10 11:41:03 -07:00
|
|
|
inline size_t
|
|
|
|
JSObject::slotsAndStructSize() const
|
2011-04-08 14:21:08 -07:00
|
|
|
{
|
2011-11-21 17:29:05 -08:00
|
|
|
return structSize() + dynamicSlotSize(NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
inline size_t
|
2011-11-30 12:45:27 -08:00
|
|
|
JSObject::dynamicSlotSize(JSMallocSizeOfFun mallocSizeOf) const
|
2011-11-21 17:29:05 -08:00
|
|
|
{
|
|
|
|
size_t size = 0;
|
|
|
|
if (hasDynamicSlots()) {
|
2011-11-30 12:45:27 -08:00
|
|
|
size_t bytes = numDynamicSlots() * sizeof(js::Value);
|
|
|
|
size += mallocSizeOf ? mallocSizeOf(slots, bytes) : bytes;
|
2011-11-21 17:29:05 -08:00
|
|
|
}
|
|
|
|
if (hasDynamicElements()) {
|
2011-11-30 12:45:27 -08:00
|
|
|
size_t bytes =
|
|
|
|
(js::ObjectElements::VALUES_PER_HEADER +
|
|
|
|
getElementsHeader()->capacity) * sizeof(js::Value);
|
|
|
|
size += mallocSizeOf ? mallocSizeOf(getElementsHeader(), bytes) : bytes;
|
2011-11-21 17:29:05 -08:00
|
|
|
}
|
|
|
|
return size;
|
2011-04-08 14:21:08 -07:00
|
|
|
}
|
|
|
|
|
2011-10-04 18:46:03 -07:00
|
|
|
inline JSBool
|
2011-10-08 15:45:04 -07:00
|
|
|
JSObject::lookupGeneric(JSContext *cx, jsid id, JSObject **objp, JSProperty **propp)
|
2011-10-04 18:46:03 -07:00
|
|
|
{
|
2011-10-08 15:45:04 -07:00
|
|
|
js::LookupGenericOp op = getOps()->lookupGeneric;
|
2011-10-04 18:46:03 -07:00
|
|
|
return (op ? op : js_LookupProperty)(cx, this, id, objp, propp);
|
|
|
|
}
|
|
|
|
|
2011-10-08 15:45:04 -07:00
|
|
|
inline JSBool
|
|
|
|
JSObject::lookupProperty(JSContext *cx, js::PropertyName *name, JSObject **objp, JSProperty **propp)
|
|
|
|
{
|
|
|
|
return lookupGeneric(cx, ATOM_TO_JSID(name), objp, propp);
|
|
|
|
}
|
|
|
|
|
2011-10-05 01:00:23 -07:00
|
|
|
inline JSBool
|
|
|
|
JSObject::defineGeneric(JSContext *cx, jsid id, const js::Value &value,
|
|
|
|
JSPropertyOp getter /* = JS_PropertyStub */,
|
|
|
|
JSStrictPropertyOp setter /* = JS_StrictPropertyStub */,
|
|
|
|
uintN attrs /* = JSPROP_ENUMERATE */)
|
|
|
|
{
|
|
|
|
js::DefineGenericOp op = getOps()->defineGeneric;
|
|
|
|
return (op ? op : js_DefineProperty)(cx, this, id, &value, getter, setter, attrs);
|
|
|
|
}
|
|
|
|
|
|
|
|
inline JSBool
|
|
|
|
JSObject::defineProperty(JSContext *cx, js::PropertyName *name, const js::Value &value,
|
|
|
|
JSPropertyOp getter /* = JS_PropertyStub */,
|
|
|
|
JSStrictPropertyOp setter /* = JS_StrictPropertyStub */,
|
|
|
|
uintN attrs /* = JSPROP_ENUMERATE */)
|
|
|
|
{
|
|
|
|
return defineGeneric(cx, ATOM_TO_JSID(name), value, getter, setter, attrs);
|
|
|
|
}
|
|
|
|
|
|
|
|
inline JSBool
|
Bug 708735 - Use <stdint.h> types in JSAPI and throughout SpiderMonkey. Continue to provide the {u,}int{8,16,32,64} and JS{Uint,Int}{8,16,32,64} integer types through a single header, however, for a simpler backout strategy -- and also to ease the transition for embedders. r=timeless on switching the jsd API to use the <stdint.h> types, r=luke, r=dmandelin
2011-12-08 19:54:10 -08:00
|
|
|
JSObject::defineElement(JSContext *cx, uint32_t index, const js::Value &value,
|
2011-10-05 01:00:23 -07:00
|
|
|
JSPropertyOp getter /* = JS_PropertyStub */,
|
|
|
|
JSStrictPropertyOp setter /* = JS_StrictPropertyStub */,
|
|
|
|
uintN attrs /* = JSPROP_ENUMERATE */)
|
|
|
|
{
|
|
|
|
js::DefineElementOp op = getOps()->defineElement;
|
|
|
|
return (op ? op : js_DefineElement)(cx, this, index, &value, getter, setter, attrs);
|
|
|
|
}
|
|
|
|
|
|
|
|
inline JSBool
|
|
|
|
JSObject::defineSpecial(JSContext *cx, js::SpecialId sid, const js::Value &value,
|
|
|
|
JSPropertyOp getter /* = JS_PropertyStub */,
|
|
|
|
JSStrictPropertyOp setter /* = JS_StrictPropertyStub */,
|
|
|
|
uintN attrs /* = JSPROP_ENUMERATE */)
|
|
|
|
{
|
|
|
|
return defineGeneric(cx, SPECIALID_TO_JSID(sid), value, getter, setter, attrs);
|
|
|
|
}
|
|
|
|
|
2011-08-10 14:54:51 -07:00
|
|
|
inline JSBool
|
Bug 708735 - Use <stdint.h> types in JSAPI and throughout SpiderMonkey. Continue to provide the {u,}int{8,16,32,64} and JS{Uint,Int}{8,16,32,64} integer types through a single header, however, for a simpler backout strategy -- and also to ease the transition for embedders. r=timeless on switching the jsd API to use the <stdint.h> types, r=luke, r=dmandelin
2011-12-08 19:54:10 -08:00
|
|
|
JSObject::lookupElement(JSContext *cx, uint32_t index, JSObject **objp, JSProperty **propp)
|
2011-08-10 14:54:51 -07:00
|
|
|
{
|
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
|
|
|
}
|
|
|
|
|
2011-10-08 15:45:04 -07:00
|
|
|
inline JSBool
|
|
|
|
JSObject::lookupSpecial(JSContext *cx, js::SpecialId sid, JSObject **objp, JSProperty **propp)
|
|
|
|
{
|
|
|
|
return lookupGeneric(cx, SPECIALID_TO_JSID(sid), objp, propp);
|
|
|
|
}
|
|
|
|
|
2011-08-10 14:54:51 -07:00
|
|
|
inline JSBool
|
Bug 708735 - Use <stdint.h> types in JSAPI and throughout SpiderMonkey. Continue to provide the {u,}int{8,16,32,64} and JS{Uint,Int}{8,16,32,64} integer types through a single header, however, for a simpler backout strategy -- and also to ease the transition for embedders. r=timeless on switching the jsd API to use the <stdint.h> types, r=luke, r=dmandelin
2011-12-08 19:54:10 -08:00
|
|
|
JSObject::getElement(JSContext *cx, JSObject *receiver, uint32_t index, js::Value *vp)
|
2011-08-10 14:54:51 -07:00
|
|
|
{
|
2011-11-03 22:32:09 -07:00
|
|
|
js::ElementIdOp op = getOps()->getElement;
|
|
|
|
if (op)
|
|
|
|
return op(cx, this, receiver, index, vp);
|
|
|
|
|
2011-08-10 14:54:51 -07:00
|
|
|
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
|
Bug 708735 - Use <stdint.h> types in JSAPI and throughout SpiderMonkey. Continue to provide the {u,}int{8,16,32,64} and JS{Uint,Int}{8,16,32,64} integer types through a single header, however, for a simpler backout strategy -- and also to ease the transition for embedders. r=timeless on switching the jsd API to use the <stdint.h> types, r=luke, r=dmandelin
2011-12-08 19:54:10 -08:00
|
|
|
JSObject::getElement(JSContext *cx, uint32_t index, js::Value *vp)
|
2011-08-10 14:54:51 -07:00
|
|
|
{
|
2011-11-03 22:32:09 -07:00
|
|
|
return getElement(cx, this, index, vp);
|
2011-08-10 14:54:51 -07:00
|
|
|
}
|
|
|
|
|
2011-11-04 09:18:52 -07:00
|
|
|
inline JSBool
|
Bug 708735 - Use <stdint.h> types in JSAPI and throughout SpiderMonkey. Continue to provide the {u,}int{8,16,32,64} and JS{Uint,Int}{8,16,32,64} integer types through a single header, however, for a simpler backout strategy -- and also to ease the transition for embedders. r=timeless on switching the jsd API to use the <stdint.h> types, r=luke, r=dmandelin
2011-12-08 19:54:10 -08:00
|
|
|
JSObject::getElementIfPresent(JSContext *cx, JSObject *receiver, uint32_t index, js::Value *vp,
|
2011-11-04 09:18:52 -07:00
|
|
|
bool *present)
|
|
|
|
{
|
2011-11-04 09:19:00 -07:00
|
|
|
js::ElementIfPresentOp op = getOps()->getElementIfPresent;
|
|
|
|
if (op)
|
|
|
|
return op(cx, this, receiver, index, vp, present);
|
|
|
|
|
2011-11-04 09:18:52 -07:00
|
|
|
/* For now, do the index-to-id conversion just once, then use
|
|
|
|
* lookupGeneric/getGeneric. Once lookupElement and getElement stop both
|
|
|
|
* doing index-to-id conversions, we can use those here.
|
|
|
|
*/
|
2011-08-10 14:54:51 -07:00
|
|
|
jsid id;
|
|
|
|
if (!js::IndexToId(cx, index, &id))
|
|
|
|
return false;
|
2011-11-04 09:18:52 -07:00
|
|
|
|
|
|
|
JSObject *obj2;
|
|
|
|
JSProperty *prop;
|
|
|
|
if (!lookupGeneric(cx, id, &obj2, &prop))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if (!prop) {
|
|
|
|
*present = false;
|
|
|
|
js::Debug_SetValueRangeToCrashOnTouch(vp, 1);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
*present = true;
|
|
|
|
return getGeneric(cx, receiver, id, vp);
|
2011-08-10 14:54:51 -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
|
|
|
}
|
|
|
|
|
2011-10-04 17:21:06 -07:00
|
|
|
inline JSBool
|
|
|
|
JSObject::getGenericAttributes(JSContext *cx, jsid id, uintN *attrsp)
|
|
|
|
{
|
|
|
|
js::GenericAttributesOp op = getOps()->getGenericAttributes;
|
|
|
|
return (op ? op : js_GetAttributes)(cx, this, id, attrsp);
|
|
|
|
}
|
|
|
|
|
|
|
|
inline JSBool
|
|
|
|
JSObject::getPropertyAttributes(JSContext *cx, js::PropertyName *name, uintN *attrsp)
|
|
|
|
{
|
|
|
|
return getGenericAttributes(cx, ATOM_TO_JSID(name), attrsp);
|
|
|
|
}
|
|
|
|
|
|
|
|
inline JSBool
|
Bug 708735 - Use <stdint.h> types in JSAPI and throughout SpiderMonkey. Continue to provide the {u,}int{8,16,32,64} and JS{Uint,Int}{8,16,32,64} integer types through a single header, however, for a simpler backout strategy -- and also to ease the transition for embedders. r=timeless on switching the jsd API to use the <stdint.h> types, r=luke, r=dmandelin
2011-12-08 19:54:10 -08:00
|
|
|
JSObject::getElementAttributes(JSContext *cx, uint32_t index, uintN *attrsp)
|
2011-08-10 14:54:51 -07:00
|
|
|
{
|
|
|
|
jsid id;
|
|
|
|
if (!js::IndexToId(cx, index, &id))
|
|
|
|
return false;
|
2011-10-04 17:21:06 -07:00
|
|
|
return getGenericAttributes(cx, id, attrsp);
|
2011-08-10 14:54:51 -07:00
|
|
|
}
|
|
|
|
|
2011-08-12 11:26:48 -07:00
|
|
|
inline JSBool
|
2011-10-04 17:21:06 -07:00
|
|
|
JSObject::getSpecialAttributes(JSContext *cx, js::SpecialId sid, uintN *attrsp)
|
2011-08-12 11:26:48 -07:00
|
|
|
{
|
2011-10-04 17:21:06 -07:00
|
|
|
return getGenericAttributes(cx, SPECIALID_TO_JSID(sid), attrsp);
|
2011-08-12 11:26:48 -07:00
|
|
|
}
|
|
|
|
|
2011-10-04 07:06:54 -07:00
|
|
|
inline bool
|
|
|
|
JSObject::isProxy() const
|
|
|
|
{
|
|
|
|
return js::IsProxy(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
inline bool
|
|
|
|
JSObject::isCrossCompartmentWrapper() const
|
|
|
|
{
|
|
|
|
return js::IsCrossCompartmentWrapper(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
inline bool
|
|
|
|
JSObject::isWrapper() const
|
|
|
|
{
|
|
|
|
return js::IsWrapper(this);
|
|
|
|
}
|
|
|
|
|
2011-11-03 09:57:12 -07:00
|
|
|
inline js::GlobalObject *
|
|
|
|
JSObject::getGlobal() const
|
|
|
|
{
|
|
|
|
JSObject *obj = const_cast<JSObject *>(this);
|
2011-11-09 09:52:59 -08:00
|
|
|
while (JSObject *parent = obj->getParent())
|
2011-11-03 09:57:12 -07:00
|
|
|
obj = parent;
|
|
|
|
return obj->asGlobal();
|
|
|
|
}
|
|
|
|
|
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 {
|
|
|
|
|
2011-10-04 18:46:03 -07:00
|
|
|
inline void
|
|
|
|
OBJ_TO_INNER_OBJECT(JSContext *cx, JSObject *&obj)
|
|
|
|
{
|
|
|
|
if (JSObjectOp op = obj->getClass()->ext.innerObject)
|
|
|
|
obj = op(cx, obj);
|
|
|
|
}
|
|
|
|
|
|
|
|
inline void
|
|
|
|
OBJ_TO_OUTER_OBJECT(JSContext *cx, JSObject *&obj)
|
|
|
|
{
|
|
|
|
if (JSObjectOp op = obj->getClass()->ext.outerObject)
|
|
|
|
obj = op(cx, obj);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Methods to test whether an object or a value is of type "xml" (per typeof).
|
|
|
|
*/
|
|
|
|
|
|
|
|
#define VALUE_IS_XML(v) (!JSVAL_IS_PRIMITIVE(v) && JSVAL_TO_OBJECT(v)->isXML())
|
|
|
|
|
|
|
|
static inline bool
|
|
|
|
IsXML(const js::Value &v)
|
|
|
|
{
|
|
|
|
return v.isObject() && v.toObject().isXML();
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline bool
|
|
|
|
IsStopIteration(const js::Value &v)
|
|
|
|
{
|
|
|
|
return v.isObject() && v.toObject().isStopIteration();
|
|
|
|
}
|
|
|
|
|
|
|
|
/* ES5 9.1 ToPrimitive(input). */
|
|
|
|
static JS_ALWAYS_INLINE bool
|
|
|
|
ToPrimitive(JSContext *cx, Value *vp)
|
|
|
|
{
|
|
|
|
if (vp->isPrimitive())
|
|
|
|
return true;
|
|
|
|
return vp->toObject().defaultValue(cx, JSTYPE_VOID, vp);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* ES5 9.1 ToPrimitive(input, PreferredType). */
|
|
|
|
static JS_ALWAYS_INLINE bool
|
|
|
|
ToPrimitive(JSContext *cx, JSType preferredType, Value *vp)
|
|
|
|
{
|
|
|
|
JS_ASSERT(preferredType != JSTYPE_VOID); /* Use the other ToPrimitive! */
|
|
|
|
if (vp->isPrimitive())
|
|
|
|
return true;
|
|
|
|
return vp->toObject().defaultValue(cx, preferredType, vp);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Return true if this is a compiler-created internal function accessed by
|
|
|
|
* its own object. Such a function object must not be accessible to script
|
|
|
|
* or embedding code.
|
|
|
|
*/
|
|
|
|
inline bool
|
|
|
|
IsInternalFunctionObject(JSObject *funobj)
|
|
|
|
{
|
2011-10-11 15:28:54 -07:00
|
|
|
JSFunction *fun = funobj->toFunction();
|
|
|
|
return (fun->flags & JSFUN_LAMBDA) && !funobj->getParent();
|
2011-10-04 18:46:03 -07:00
|
|
|
}
|
|
|
|
|
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);
|
|
|
|
};
|
|
|
|
|
2011-11-18 14:40:14 -08:00
|
|
|
inline bool
|
|
|
|
NewObjectCache::lookup(Class *clasp, gc::Cell *key, gc::AllocKind kind, EntryIndex *pentry)
|
|
|
|
{
|
|
|
|
jsuword hash = (jsuword(clasp) ^ jsuword(key)) + kind;
|
|
|
|
*pentry = hash % js::ArrayLength(entries);
|
|
|
|
|
|
|
|
Entry *entry = &entries[*pentry];
|
|
|
|
|
|
|
|
/* N.B. Lookups with the same clasp/key but different kinds map to different entries. */
|
|
|
|
return (entry->clasp == clasp && entry->key == key);
|
|
|
|
}
|
|
|
|
|
|
|
|
inline bool
|
|
|
|
NewObjectCache::lookupProto(Class *clasp, JSObject *proto, gc::AllocKind kind, EntryIndex *pentry)
|
|
|
|
{
|
|
|
|
JS_ASSERT(!proto->isGlobal());
|
|
|
|
return lookup(clasp, proto, kind, pentry);
|
|
|
|
}
|
|
|
|
|
|
|
|
inline bool
|
|
|
|
NewObjectCache::lookupGlobal(Class *clasp, js::GlobalObject *global, gc::AllocKind kind, EntryIndex *pentry)
|
|
|
|
{
|
|
|
|
return lookup(clasp, global, kind, pentry);
|
|
|
|
}
|
|
|
|
|
|
|
|
inline bool
|
|
|
|
NewObjectCache::lookupType(Class *clasp, js::types::TypeObject *type, gc::AllocKind kind, EntryIndex *pentry)
|
|
|
|
{
|
|
|
|
return lookup(clasp, type, kind, pentry);
|
|
|
|
}
|
|
|
|
|
2011-11-03 09:57:12 -07:00
|
|
|
inline void
|
2011-11-18 14:40:14 -08:00
|
|
|
NewObjectCache::fill(EntryIndex entry_, Class *clasp, gc::Cell *key, gc::AllocKind kind, JSObject *obj)
|
2011-11-03 09:57:12 -07:00
|
|
|
{
|
2011-11-18 14:40:14 -08:00
|
|
|
JS_ASSERT(unsigned(entry_) < ArrayLength(entries));
|
|
|
|
Entry *entry = &entries[entry_];
|
|
|
|
|
2011-11-03 09:57:12 -07:00
|
|
|
JS_ASSERT(!obj->hasDynamicSlots() && !obj->hasDynamicElements());
|
|
|
|
|
2011-11-18 14:40:14 -08:00
|
|
|
entry->clasp = clasp;
|
|
|
|
entry->key = key;
|
|
|
|
entry->kind = kind;
|
|
|
|
|
|
|
|
entry->nbytes = obj->structSize();
|
|
|
|
memcpy(&entry->templateObject, obj, entry->nbytes);
|
|
|
|
}
|
|
|
|
|
|
|
|
inline void
|
|
|
|
NewObjectCache::fillProto(EntryIndex entry, Class *clasp, JSObject *proto, gc::AllocKind kind, JSObject *obj)
|
|
|
|
{
|
|
|
|
JS_ASSERT(!proto->isGlobal());
|
|
|
|
JS_ASSERT(obj->getProto() == proto);
|
|
|
|
return fill(entry, clasp, proto, kind, obj);
|
|
|
|
}
|
|
|
|
|
|
|
|
inline void
|
|
|
|
NewObjectCache::fillGlobal(EntryIndex entry, Class *clasp, js::GlobalObject *global, gc::AllocKind kind, JSObject *obj)
|
|
|
|
{
|
2011-11-18 17:37:37 -08:00
|
|
|
//JS_ASSERT(global == obj->getGlobal());
|
2011-11-18 14:40:14 -08:00
|
|
|
return fill(entry, clasp, global, kind, obj);
|
|
|
|
}
|
2011-11-03 09:57:12 -07:00
|
|
|
|
2011-11-18 14:40:14 -08:00
|
|
|
inline void
|
|
|
|
NewObjectCache::fillType(EntryIndex entry, Class *clasp, js::types::TypeObject *type, gc::AllocKind kind, JSObject *obj)
|
|
|
|
{
|
|
|
|
JS_ASSERT(obj->type() == type);
|
|
|
|
return fill(entry, clasp, type, kind, obj);
|
2011-11-03 09:57:12 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
inline JSObject *
|
2011-11-18 14:40:14 -08:00
|
|
|
NewObjectCache::newObjectFromHit(JSContext *cx, EntryIndex entry_)
|
2011-11-03 09:57:12 -07:00
|
|
|
{
|
2011-11-18 14:40:14 -08:00
|
|
|
JS_ASSERT(unsigned(entry_) < ArrayLength(entries));
|
|
|
|
Entry *entry = &entries[entry_];
|
|
|
|
|
2011-11-03 09:57:12 -07:00
|
|
|
JSObject *obj = js_TryNewGCObject(cx, entry->kind);
|
|
|
|
if (obj) {
|
|
|
|
memcpy(obj, &entry->templateObject, entry->nbytes);
|
|
|
|
Probes::createObject(cx, obj);
|
|
|
|
return obj;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Copy the entry to the stack first in case it is purged by a GC. */
|
|
|
|
size_t nbytes = entry->nbytes;
|
|
|
|
JSObject_Slots16 stackObject;
|
|
|
|
memcpy(&stackObject, &entry->templateObject, nbytes);
|
|
|
|
|
|
|
|
obj = js_NewGCObject(cx, entry->kind);
|
|
|
|
if (obj) {
|
|
|
|
memcpy(obj, &stackObject, nbytes);
|
|
|
|
Probes::createObject(cx, obj);
|
|
|
|
return obj;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
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-10-26 13:02:57 -07:00
|
|
|
JS_ASSERT(kind <= gc::FINALIZE_OBJECT_LAST);
|
2011-04-13 13:43:33 -07:00
|
|
|
/* 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-09-29 20:29:13 -07:00
|
|
|
if (!gc::IsBackgroundAllocKind(kind) && !clasp->finalize)
|
2011-04-13 13:43:33 -07:00
|
|
|
return true;
|
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
|
|
|
/*
|
2011-11-02 13:34:19 -07:00
|
|
|
* Make an object with the specified prototype. If parent is null, it will
|
|
|
|
* default to the prototype's global if the prototype is non-null.
|
2010-06-18 17:43:02 -07:00
|
|
|
*/
|
2011-11-02 13:34:19 -07:00
|
|
|
JSObject *
|
|
|
|
NewObjectWithGivenProto(JSContext *cx, js::Class *clasp, JSObject *proto, JSObject *parent,
|
|
|
|
gc::AllocKind kind);
|
2010-10-13 11:49:22 -07:00
|
|
|
|
2011-11-02 13:34:19 -07:00
|
|
|
inline JSObject *
|
|
|
|
NewObjectWithGivenProto(JSContext *cx, js::Class *clasp, JSObject *proto, JSObject *parent)
|
2010-10-13 11:49:22 -07:00
|
|
|
{
|
2011-10-10 17:14:38 -07:00
|
|
|
gc::AllocKind kind = gc::GetGCObjectKind(clasp);
|
2011-11-02 13:34:19 -07:00
|
|
|
return NewObjectWithGivenProto(cx, clasp, proto, parent, kind);
|
2010-06-18 17:43:02 -07:00
|
|
|
}
|
|
|
|
|
2011-11-02 13:34:19 -07:00
|
|
|
inline JSProtoKey
|
2010-08-09 09:11:22 -07:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2011-11-02 13:34:19 -07:00
|
|
|
inline bool
|
2010-12-18 20:44:51 -08:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2011-11-02 13:34:19 -07:00
|
|
|
/*
|
|
|
|
* Make an object with the prototype set according to the specified prototype or class:
|
|
|
|
*
|
|
|
|
* if proto is non-null:
|
|
|
|
* use the specified proto
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
* The class prototype will be fetched from the parent's global. If global is
|
|
|
|
* null, the context's active global will be used, and the resulting object's
|
|
|
|
* parent will be that global.
|
|
|
|
*/
|
2011-11-03 09:57:12 -07:00
|
|
|
JSObject *
|
2011-11-02 13:34:19 -07:00
|
|
|
NewObjectWithClassProto(JSContext *cx, js::Class *clasp, JSObject *proto, JSObject *parent,
|
2011-11-03 09:57:12 -07:00
|
|
|
gc::AllocKind kind);
|
2010-09-20 11:40:32 -07:00
|
|
|
|
2011-11-02 13:34:19 -07:00
|
|
|
inline JSObject *
|
|
|
|
NewObjectWithClassProto(JSContext *cx, js::Class *clasp, JSObject *proto, JSObject *parent)
|
2011-10-11 15:28:54 -07:00
|
|
|
{
|
|
|
|
gc::AllocKind kind = gc::GetGCObjectKind(clasp);
|
2011-11-02 13:34:19 -07:00
|
|
|
return NewObjectWithClassProto(cx, clasp, proto, parent, kind);
|
2011-10-11 15:28:54 -07:00
|
|
|
}
|
|
|
|
|
2011-11-02 13:34:19 -07:00
|
|
|
/*
|
|
|
|
* Create a native instance of the given class with parent and proto set
|
|
|
|
* according to the context's active global.
|
|
|
|
*/
|
|
|
|
inline JSObject *
|
|
|
|
NewBuiltinClassInstance(JSContext *cx, Class *clasp, gc::AllocKind kind)
|
2010-09-20 11:40:32 -07:00
|
|
|
{
|
2011-11-02 13:34:19 -07:00
|
|
|
return NewObjectWithClassProto(cx, clasp, NULL, NULL, kind);
|
2010-10-13 11:49:22 -07:00
|
|
|
}
|
|
|
|
|
2011-11-02 13:34:19 -07:00
|
|
|
inline JSObject *
|
|
|
|
NewBuiltinClassInstance(JSContext *cx, Class *clasp)
|
2010-10-13 11:49:22 -07:00
|
|
|
{
|
2011-11-02 13:34:19 -07:00
|
|
|
gc::AllocKind kind = gc::GetGCObjectKind(clasp);
|
|
|
|
return NewBuiltinClassInstance(cx, clasp, kind);
|
2010-04-10 16:16:35 -07:00
|
|
|
}
|
|
|
|
|
2011-11-02 13:34:19 -07:00
|
|
|
inline GlobalObject *
|
|
|
|
GetCurrentGlobal(JSContext *cx)
|
2010-04-10 16:16:35 -07:00
|
|
|
{
|
2011-11-02 13:34:19 -07:00
|
|
|
JSObject *scopeChain = (cx->hasfp()) ? &cx->fp()->scopeChain() : cx->globalObject;
|
|
|
|
return scopeChain ? scopeChain->getGlobal() : NULL;
|
2010-10-13 11:49:22 -07:00
|
|
|
}
|
|
|
|
|
2011-11-02 13:34:19 -07:00
|
|
|
bool
|
|
|
|
FindClassPrototype(JSContext *cx, JSObject *scope, JSProtoKey protoKey, JSObject **protop,
|
|
|
|
Class *clasp);
|
|
|
|
|
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'.
|
|
|
|
*/
|
2011-11-02 13:34:19 -07:00
|
|
|
JSObject *
|
|
|
|
NewObjectWithType(JSContext *cx, types::TypeObject *type, JSObject *parent, gc::AllocKind kind);
|
|
|
|
|
|
|
|
/* Make an object with pregenerated shape from a NEWOBJECT bytecode. */
|
|
|
|
static inline JSObject *
|
|
|
|
CopyInitializerObject(JSContext *cx, JSObject *baseobj, types::TypeObject *type)
|
2011-04-12 20:39:16 -07:00
|
|
|
{
|
2011-11-02 13:34:19 -07:00
|
|
|
JS_ASSERT(baseobj->getClass() == &ObjectClass);
|
|
|
|
JS_ASSERT(!baseobj->inDictionaryMode());
|
2011-07-28 14:17:42 -07:00
|
|
|
|
2011-11-02 13:34:19 -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);
|
2011-08-11 20:56:17 -07:00
|
|
|
|
2011-04-12 20:39:16 -07:00
|
|
|
if (!obj)
|
2011-11-02 13:34:19 -07:00
|
|
|
return NULL;
|
2011-10-13 20:21:36 -07:00
|
|
|
|
2011-11-02 13:34:19 -07:00
|
|
|
obj->setType(type);
|
2011-04-12 20:39:16 -07:00
|
|
|
|
2011-11-02 13:34:19 -07:00
|
|
|
if (!obj->setLastProperty(cx, baseobj->lastProperty()))
|
|
|
|
return NULL;
|
2011-04-12 20:39:16 -07:00
|
|
|
|
|
|
|
return obj;
|
|
|
|
}
|
|
|
|
|
2011-11-02 13:34:19 -07:00
|
|
|
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
|
2011-10-10 11:41:03 -07:00
|
|
|
GuessObjectGCKind(size_t numSlots)
|
|
|
|
{
|
|
|
|
if (numSlots)
|
|
|
|
return gc::GetGCObjectKind(numSlots);
|
|
|
|
return gc::FINALIZE_OBJECT4;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline gc::AllocKind
|
|
|
|
GuessArrayGCKind(size_t numSlots)
|
2010-10-13 11:49:22 -07:00
|
|
|
{
|
|
|
|
if (numSlots)
|
2011-10-10 11:41:03 -07:00
|
|
|
return gc::GetGCArrayKind(numSlots);
|
|
|
|
return gc::FINALIZE_OBJECT8;
|
2010-10-13 11:49:22 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* 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-11-02 13:34:19 -07:00
|
|
|
/*
|
|
|
|
* Fill slots with the initial slot array to use for a newborn object which
|
2011-11-18 14:59:31 -08:00
|
|
|
* may or may not need dynamic slots.
|
2011-11-02 13:34:19 -07:00
|
|
|
*/
|
|
|
|
inline bool
|
2011-11-18 14:59:31 -08:00
|
|
|
PreallocateObjectDynamicSlots(JSContext *cx, Shape *shape, HeapValue **slots)
|
2010-11-18 18:14:22 -08:00
|
|
|
{
|
2011-11-18 14:59:31 -08:00
|
|
|
if (size_t count = JSObject::dynamicSlotsCount(shape->numFixedSlots(), shape->slotSpan())) {
|
2011-11-14 09:13:33 -08:00
|
|
|
*slots = (HeapValue *) cx->malloc_(count * sizeof(HeapValue));
|
2011-11-02 13:34:19 -07:00
|
|
|
if (!*slots)
|
|
|
|
return false;
|
|
|
|
Debug_SetValueRangeToCrashOnTouch(*slots, count);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
*slots = NULL;
|
|
|
|
return true;
|
2010-11-18 18:14:22 -08:00
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2011-09-08 21:18:23 -07:00
|
|
|
namespace detail {
|
|
|
|
|
|
|
|
template<typename T> class PrimitiveBehavior { };
|
|
|
|
|
|
|
|
template<>
|
|
|
|
class PrimitiveBehavior<JSString *> {
|
|
|
|
public:
|
|
|
|
static inline bool isType(const Value &v) { return v.isString(); }
|
|
|
|
static inline JSString *extract(const Value &v) { return v.toString(); }
|
|
|
|
static inline Class *getClass() { return &StringClass; }
|
|
|
|
};
|
|
|
|
|
|
|
|
template<>
|
|
|
|
class PrimitiveBehavior<bool> {
|
|
|
|
public:
|
|
|
|
static inline bool isType(const Value &v) { return v.isBoolean(); }
|
|
|
|
static inline bool extract(const Value &v) { return v.toBoolean(); }
|
|
|
|
static inline Class *getClass() { return &BooleanClass; }
|
|
|
|
};
|
|
|
|
|
|
|
|
template<>
|
|
|
|
class PrimitiveBehavior<double> {
|
|
|
|
public:
|
|
|
|
static inline bool isType(const Value &v) { return v.isNumber(); }
|
|
|
|
static inline double extract(const Value &v) { return v.toNumber(); }
|
|
|
|
static inline Class *getClass() { return &NumberClass; }
|
|
|
|
};
|
|
|
|
|
|
|
|
} /* namespace detail */
|
|
|
|
|
|
|
|
inline JSObject *
|
2011-10-04 10:48:36 -07:00
|
|
|
NonGenericMethodGuard(JSContext *cx, CallArgs args, Native native, Class *clasp, bool *ok)
|
2011-09-08 21:18:23 -07:00
|
|
|
{
|
|
|
|
const Value &thisv = args.thisv();
|
|
|
|
if (thisv.isObject()) {
|
|
|
|
JSObject &obj = thisv.toObject();
|
2011-09-27 23:20:46 -07:00
|
|
|
if (obj.getClass() == clasp) {
|
|
|
|
*ok = true; /* quell gcc overwarning */
|
2011-09-08 21:18:23 -07:00
|
|
|
return &obj;
|
2011-09-27 23:20:46 -07:00
|
|
|
}
|
2011-09-08 21:18:23 -07:00
|
|
|
}
|
|
|
|
|
2011-10-04 10:48:36 -07:00
|
|
|
*ok = HandleNonGenericMethodClassMismatch(cx, args, native, clasp);
|
2011-09-08 21:18:23 -07:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename T>
|
|
|
|
inline bool
|
2011-10-04 10:48:36 -07:00
|
|
|
BoxedPrimitiveMethodGuard(JSContext *cx, CallArgs args, Native native, T *v, bool *ok)
|
2011-09-08 21:18:23 -07:00
|
|
|
{
|
|
|
|
typedef detail::PrimitiveBehavior<T> Behavior;
|
|
|
|
|
|
|
|
const Value &thisv = args.thisv();
|
|
|
|
if (Behavior::isType(thisv)) {
|
|
|
|
*v = Behavior::extract(thisv);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2011-10-04 10:48:36 -07:00
|
|
|
if (!NonGenericMethodGuard(cx, args, native, Behavior::getClass(), ok))
|
2011-09-08 21:18:23 -07:00
|
|
|
return false;
|
|
|
|
|
|
|
|
*v = Behavior::extract(thisv.toObject().getPrimitiveThis());
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2011-09-20 16:48:50 -07:00
|
|
|
inline bool
|
|
|
|
ObjectClassIs(JSObject &obj, ESClassValue classValue, JSContext *cx)
|
|
|
|
{
|
|
|
|
if (JS_UNLIKELY(obj.isProxy()))
|
2011-09-28 08:48:16 -07:00
|
|
|
return Proxy::objectClassIs(&obj, classValue, cx);
|
2011-09-20 16:48:50 -07:00
|
|
|
|
|
|
|
switch (classValue) {
|
|
|
|
case ESClass_Array: return obj.isArray();
|
|
|
|
case ESClass_Number: return obj.isNumber();
|
|
|
|
case ESClass_String: return obj.isString();
|
|
|
|
case ESClass_Boolean: return obj.isBoolean();
|
|
|
|
}
|
|
|
|
JS_NOT_REACHED("bad classValue");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2011-08-14 21:12:50 -07:00
|
|
|
static JS_ALWAYS_INLINE bool
|
|
|
|
ValueIsSpecial(JSObject *obj, Value *propval, SpecialId *sidp, JSContext *cx)
|
|
|
|
{
|
|
|
|
if (!propval->isObject())
|
|
|
|
return false;
|
|
|
|
|
|
|
|
#if JS_HAS_XML_SUPPORT
|
|
|
|
if (obj->isXML()) {
|
|
|
|
*sidp = SpecialId(propval->toObject());
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
JSObject &propobj = propval->toObject();
|
|
|
|
JSAtom *name;
|
|
|
|
if (propobj.isQName() && GetLocalNameFromFunctionQName(&propobj, &name, cx)) {
|
|
|
|
propval->setString(name);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2011-10-27 11:14:56 -07:00
|
|
|
JSObject *
|
|
|
|
DefineConstructorAndPrototype(JSContext *cx, JSObject *obj, JSProtoKey key, JSAtom *atom,
|
|
|
|
JSObject *protoProto, Class *clasp,
|
|
|
|
Native constructor, uintN nargs,
|
|
|
|
JSPropertySpec *ps, JSFunctionSpec *fs,
|
|
|
|
JSPropertySpec *static_ps, JSFunctionSpec *static_fs,
|
|
|
|
JSObject **ctorp = NULL,
|
|
|
|
gc::AllocKind ctorKind = JSFunction::FinalizeKind);
|
|
|
|
|
2010-06-18 17:43:02 -07:00
|
|
|
} /* namespace js */
|
2010-03-28 20:32:20 -07:00
|
|
|
|
2011-10-27 11:14:56 -07:00
|
|
|
extern JSObject *
|
|
|
|
js_InitClass(JSContext *cx, JSObject *obj, JSObject *parent_proto,
|
|
|
|
js::Class *clasp, JSNative constructor, uintN nargs,
|
|
|
|
JSPropertySpec *ps, JSFunctionSpec *fs,
|
|
|
|
JSPropertySpec *static_ps, JSFunctionSpec *static_fs,
|
|
|
|
JSObject **ctorp = NULL,
|
|
|
|
js::gc::AllocKind ctorKind = JSFunction::FinalizeKind);
|
|
|
|
|
2010-12-18 20:44:51 -08:00
|
|
|
inline JSObject *
|
|
|
|
js_GetProtoIfDenseArray(JSObject *obj)
|
|
|
|
{
|
|
|
|
return obj->isDenseArray() ? obj->getProto() : obj;
|
|
|
|
}
|
|
|
|
|
2011-10-14 13:51:21 -07:00
|
|
|
/*
|
|
|
|
* js_PurgeScopeChain does nothing if obj is not itself a prototype or parent
|
|
|
|
* scope, else it reshapes the scope and prototype chains it links. It calls
|
|
|
|
* js_PurgeScopeChainHelper, which asserts that obj is flagged as a delegate
|
|
|
|
* (i.e., obj has ever been on a prototype or parent chain).
|
|
|
|
*/
|
|
|
|
extern bool
|
|
|
|
js_PurgeScopeChainHelper(JSContext *cx, JSObject *obj, jsid id);
|
|
|
|
|
|
|
|
inline bool
|
|
|
|
js_PurgeScopeChain(JSContext *cx, JSObject *obj, jsid id)
|
|
|
|
{
|
|
|
|
if (obj->isDelegate())
|
|
|
|
return js_PurgeScopeChainHelper(cx, obj, id);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2011-10-25 16:07:42 -07:00
|
|
|
inline void
|
|
|
|
JSObject::setSlot(uintN slot, const js::Value &value)
|
|
|
|
{
|
2011-11-14 09:13:33 -08:00
|
|
|
JS_ASSERT(slotInRange(slot));
|
2011-10-25 16:07:42 -07:00
|
|
|
getSlotRef(slot).set(compartment(), value);
|
|
|
|
}
|
|
|
|
|
|
|
|
inline void
|
|
|
|
JSObject::initSlot(uintN slot, const js::Value &value)
|
|
|
|
{
|
|
|
|
JS_ASSERT(getSlot(slot).isUndefined() || getSlot(slot).isMagic(JS_ARRAY_HOLE));
|
2011-11-14 18:46:47 -08:00
|
|
|
JS_ASSERT(slotInRange(slot));
|
2011-10-25 16:07:42 -07:00
|
|
|
initSlotUnchecked(slot, value);
|
|
|
|
}
|
|
|
|
|
|
|
|
inline void
|
|
|
|
JSObject::initSlotUnchecked(uintN slot, const js::Value &value)
|
|
|
|
{
|
2011-11-14 18:46:47 -08:00
|
|
|
getSlotAddressUnchecked(slot)->init(value);
|
2011-10-25 16:07:42 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
inline void
|
|
|
|
JSObject::setFixedSlot(uintN slot, const js::Value &value)
|
|
|
|
{
|
|
|
|
JS_ASSERT(slot < numFixedSlots());
|
|
|
|
fixedSlots()[slot] = value;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline void
|
|
|
|
JSObject::initFixedSlot(uintN slot, const js::Value &value)
|
|
|
|
{
|
|
|
|
JS_ASSERT(slot < numFixedSlots());
|
|
|
|
fixedSlots()[slot].init(value);
|
|
|
|
}
|
|
|
|
|
|
|
|
inline void
|
|
|
|
JSObject::privateWriteBarrierPre(void **old)
|
|
|
|
{
|
|
|
|
#ifdef JSGC_INCREMENTAL
|
|
|
|
JSCompartment *comp = compartment();
|
|
|
|
if (comp->needsBarrier()) {
|
2011-11-14 13:03:50 -08:00
|
|
|
if (*old && getClass()->trace)
|
|
|
|
getClass()->trace(comp->barrierTracer(), this);
|
2011-10-25 16:07:42 -07:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
inline void
|
|
|
|
JSObject::privateWriteBarrierPost(void **old)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
inline void
|
|
|
|
JSObject::writeBarrierPre(JSObject *obj)
|
|
|
|
{
|
|
|
|
#ifdef JSGC_INCREMENTAL
|
|
|
|
/*
|
|
|
|
* This would normally be a null test, but TypeScript::global uses 0x1 as a
|
|
|
|
* special value.
|
|
|
|
*/
|
|
|
|
if (uintptr_t(obj) < 32)
|
|
|
|
return;
|
|
|
|
|
|
|
|
JSCompartment *comp = obj->compartment();
|
|
|
|
if (comp->needsBarrier()) {
|
|
|
|
JS_ASSERT(!comp->rt->gcRunning);
|
|
|
|
MarkObjectUnbarriered(comp->barrierTracer(), obj, "write barrier");
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
inline void
|
|
|
|
JSObject::writeBarrierPost(JSObject *obj, void *addr)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2009-11-18 12:29:58 -08:00
|
|
|
#endif /* jsobjinlines_h___ */
|