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:
|
|
|
|
*
|
2012-05-21 04:12:37 -07:00
|
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2009-11-18 12:29:58 -08:00
|
|
|
|
|
|
|
#ifndef jsobjinlines_h___
|
|
|
|
#define jsobjinlines_h___
|
|
|
|
|
2010-08-29 11:57:08 -07:00
|
|
|
#include <new>
|
2011-10-25 16:07:42 -07:00
|
|
|
|
2012-01-11 00:23:08 -08:00
|
|
|
#include "jsapi.h"
|
2010-12-07 17:11:37 -08:00
|
|
|
#include "jsarray.h"
|
2012-01-02 15:02:05 -08:00
|
|
|
#include "jsbool.h"
|
|
|
|
#include "jscntxt.h"
|
2010-08-29 11:57:08 -07:00
|
|
|
#include "jsfun.h"
|
2010-04-14 17:09:17 -07:00
|
|
|
#include "jsiter.h"
|
2010-08-29 11:57:08 -07:00
|
|
|
#include "jslock.h"
|
2012-01-02 15:02:05 -08:00
|
|
|
#include "jsnum.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"
|
2012-01-02 15:02:05 -08:00
|
|
|
#include "jsstr.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
|
|
|
|
2012-07-04 08:24:25 -07:00
|
|
|
#include "builtin/MapObject.h"
|
2011-10-25 16:07:42 -07:00
|
|
|
#include "gc/Barrier.h"
|
2012-05-01 14:30:18 -07:00
|
|
|
#include "gc/Marking.h"
|
2012-06-21 14:19:21 -07:00
|
|
|
#include "gc/Root.h"
|
2011-10-25 16:07:42 -07:00
|
|
|
#include "js/TemplateLib.h"
|
2012-02-16 19:10:45 -08:00
|
|
|
#include "vm/BooleanObject.h"
|
2011-04-28 16:08:22 -07:00
|
|
|
#include "vm/GlobalObject.h"
|
2012-02-16 19:10:45 -08:00
|
|
|
#include "vm/NumberObject.h"
|
2012-01-30 18:12:03 -08:00
|
|
|
#include "vm/RegExpStatics.h"
|
2012-02-16 19:10:45 -08:00
|
|
|
#include "vm/StringObject.h"
|
2011-04-28 16:08:22 -07:00
|
|
|
|
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"
|
2012-01-02 15:02:05 -08:00
|
|
|
#include "jsinferinlines.h"
|
2011-03-14 13:59:53 -07:00
|
|
|
#include "jsscopeinlines.h"
|
2012-01-02 15:02:05 -08:00
|
|
|
#include "jsscriptinlines.h"
|
2010-09-24 10:54:39 -07:00
|
|
|
|
2011-10-25 16:07:42 -07:00
|
|
|
#include "gc/Barrier-inl.h"
|
2012-02-16 15:02:15 -08:00
|
|
|
|
|
|
|
#include "vm/ObjectImpl-inl.h"
|
2012-01-30 18:12:03 -08:00
|
|
|
#include "vm/RegExpStatics-inl.h"
|
2012-02-16 15:02:15 -08:00
|
|
|
#include "vm/String-inl.h"
|
2011-10-25 16:07:42 -07:00
|
|
|
|
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;
|
2012-06-14 19:13:27 -07:00
|
|
|
js::Rooted<JSObject*> obj(cx, this);
|
|
|
|
return (op ? op : JS_EnumerateState)(cx, obj, iterop, statep, idp);
|
2011-10-04 18:46:03 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
inline bool
|
2012-07-30 04:19:09 -07:00
|
|
|
JSObject::defaultValue(JSContext *cx, JSType hint, js::MutableHandleValue vp)
|
2011-10-04 18:46:03 -07:00
|
|
|
{
|
2012-05-24 16:05:18 -07:00
|
|
|
js::RootedObject self(cx, this);
|
2012-05-19 15:03:45 -07:00
|
|
|
|
2011-10-04 18:46:03 -07:00
|
|
|
JSConvertOp op = getClass()->convert;
|
2012-04-12 09:23:51 -07:00
|
|
|
bool ok;
|
|
|
|
if (op == JS_ConvertStub)
|
2012-05-19 15:03:45 -07:00
|
|
|
ok = js::DefaultValue(cx, self, hint, vp);
|
2012-04-12 09:23:51 -07:00
|
|
|
else
|
2012-05-19 15:03:45 -07:00
|
|
|
ok = op(cx, self, hint, vp);
|
2012-07-30 04:19:09 -07:00
|
|
|
JS_ASSERT_IF(ok, vp.isPrimitive());
|
2011-10-04 18:46:03 -07:00
|
|
|
return ok;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline JSType
|
|
|
|
JSObject::typeOf(JSContext *cx)
|
|
|
|
{
|
|
|
|
js::TypeOfOp op = getOps()->typeOf;
|
2012-06-14 19:13:27 -07:00
|
|
|
js::Rooted<JSObject*> obj(cx, this);
|
|
|
|
return (op ? op : js::baseops::TypeOf)(cx, obj);
|
2011-10-04 18:46:03 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
inline JSObject *
|
|
|
|
JSObject::thisObject(JSContext *cx)
|
|
|
|
{
|
|
|
|
JSObjectOp op = getOps()->thisObject;
|
2012-06-14 19:13:27 -07:00
|
|
|
js::Rooted<JSObject*> obj(cx, this);
|
|
|
|
return op ? op(cx, obj) : this;
|
2011-10-04 18:46:03 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
inline JSBool
|
2012-07-30 04:19:09 -07:00
|
|
|
JSObject::setGeneric(JSContext *cx, js::Handle<JSObject*> receiver, js::HandleId id, js::MutableHandleValue vp,
|
2012-06-27 20:21:39 -07:00
|
|
|
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);
|
2012-06-14 19:13:27 -07:00
|
|
|
js::Rooted<JSObject*> obj(cx, this);
|
2012-06-27 20:21:39 -07:00
|
|
|
return js::baseops::SetPropertyHelper(cx, obj, receiver, id, 0, vp, strict);
|
2011-10-04 18:46:03 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
inline JSBool
|
2012-06-27 20:21:39 -07:00
|
|
|
JSObject::setProperty(JSContext *cx, js::Handle<JSObject*> receiver, js::PropertyName *name,
|
2012-07-30 04:19:09 -07:00
|
|
|
js::MutableHandleValue vp, JSBool strict)
|
2011-10-04 18:46:03 -07:00
|
|
|
{
|
2012-06-14 19:13:27 -07:00
|
|
|
js::Rooted<jsid> id(cx, js::NameToId(name));
|
2012-06-27 20:21:39 -07:00
|
|
|
return setGeneric(cx, receiver, id, vp, strict);
|
2011-10-04 18:46:03 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
inline JSBool
|
2012-07-30 04:19:09 -07:00
|
|
|
JSObject::setElement(JSContext *cx, js::Handle<JSObject*> receiver, uint32_t index, js::MutableHandleValue vp,
|
2012-06-27 20:21:39 -07:00
|
|
|
JSBool strict)
|
2011-10-04 18:46:03 -07:00
|
|
|
{
|
|
|
|
if (getOps()->setElement)
|
|
|
|
return nonNativeSetElement(cx, index, vp, strict);
|
2012-06-14 19:13:27 -07:00
|
|
|
js::Rooted<JSObject*> obj(cx, this);
|
2012-06-27 20:21:39 -07:00
|
|
|
return js::baseops::SetElementHelper(cx, obj, receiver, index, 0, vp, strict);
|
2011-10-04 18:46:03 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
inline JSBool
|
2012-07-30 04:19:09 -07:00
|
|
|
JSObject::setSpecial(JSContext *cx, js::HandleObject receiver, js::SpecialId sid, js::MutableHandleValue vp,
|
2012-06-27 20:21:39 -07:00
|
|
|
JSBool strict)
|
2011-10-04 18:46:03 -07:00
|
|
|
{
|
2012-06-14 19:13:27 -07:00
|
|
|
js::Rooted<jsid> id(cx, SPECIALID_TO_JSID(sid));
|
2012-06-27 20:21:39 -07:00
|
|
|
return setGeneric(cx, receiver, id, vp, strict);
|
2011-10-04 18:46:03 -07:00
|
|
|
}
|
|
|
|
|
2011-04-11 20:10:46 -07:00
|
|
|
inline JSBool
|
2012-05-19 15:03:45 -07:00
|
|
|
JSObject::setGenericAttributes(JSContext *cx, js::HandleId id, unsigned *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;
|
2012-06-14 19:13:27 -07:00
|
|
|
js::Rooted<JSObject*> obj(cx, this);
|
|
|
|
return (op ? op : js::baseops::SetAttributes)(cx, obj, id, attrsp);
|
2011-04-11 20:10:46 -07:00
|
|
|
}
|
|
|
|
|
2011-10-04 18:46:03 -07:00
|
|
|
inline JSBool
|
2012-02-28 15:11:11 -08:00
|
|
|
JSObject::setPropertyAttributes(JSContext *cx, js::PropertyName *name, unsigned *attrsp)
|
2011-10-04 18:46:03 -07:00
|
|
|
{
|
2012-06-14 19:13:27 -07:00
|
|
|
js::Rooted<jsid> id(cx, js::NameToId(name));
|
|
|
|
return setGenericAttributes(cx, id, attrsp);
|
2011-10-04 18:46:03 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
inline JSBool
|
2012-02-28 15:11:11 -08:00
|
|
|
JSObject::setElementAttributes(JSContext *cx, uint32_t index, unsigned *attrsp)
|
2011-10-04 18:46:03 -07:00
|
|
|
{
|
|
|
|
js::ElementAttributesOp op = getOps()->setElementAttributes;
|
2012-06-14 19:13:27 -07:00
|
|
|
js::Rooted<JSObject*> obj(cx, this);
|
|
|
|
return (op ? op : js::baseops::SetElementAttributes)(cx, obj, index, attrsp);
|
2011-10-04 18:46:03 -07:00
|
|
|
}
|
|
|
|
|
2011-10-04 17:21:06 -07:00
|
|
|
inline JSBool
|
2012-02-28 15:11:11 -08:00
|
|
|
JSObject::setSpecialAttributes(JSContext *cx, js::SpecialId sid, unsigned *attrsp)
|
2011-10-04 17:21:06 -07:00
|
|
|
{
|
2012-06-14 19:13:27 -07:00
|
|
|
js::Rooted<jsid> id(cx, SPECIALID_TO_JSID(sid));
|
|
|
|
return setGenericAttributes(cx, id, attrsp);
|
2011-10-04 17:21:06 -07:00
|
|
|
}
|
|
|
|
|
2012-03-23 17:59:56 -07:00
|
|
|
inline bool
|
|
|
|
JSObject::changePropertyAttributes(JSContext *cx, js::Shape *shape, unsigned attrs)
|
|
|
|
{
|
|
|
|
return !!changeProperty(cx, shape, attrs, 0, shape->getter(), shape->setter());
|
|
|
|
}
|
|
|
|
|
2011-05-16 16:15:37 -07:00
|
|
|
inline JSBool
|
2012-07-30 04:19:09 -07:00
|
|
|
JSObject::getGeneric(JSContext *cx, js::HandleObject receiver, js::HandleId id, js::MutableHandleValue vp)
|
2011-05-16 16:15:37 -07:00
|
|
|
{
|
2012-05-24 16:05:18 -07:00
|
|
|
js::RootedObject self(cx, this);
|
2012-05-19 15:03:45 -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) {
|
2012-05-19 15:03:45 -07:00
|
|
|
if (!op(cx, self, receiver, id, vp))
|
2011-05-16 16:15:37 -07:00
|
|
|
return false;
|
|
|
|
} else {
|
2012-05-19 15:03:45 -07:00
|
|
|
if (!js::baseops::GetProperty(cx, self, receiver, id, vp))
|
2011-05-16 16:15:37 -07:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline JSBool
|
2012-07-30 04:19:09 -07:00
|
|
|
JSObject::getProperty(JSContext *cx, js::HandleObject receiver, js::PropertyName *name, js::MutableHandleValue vp)
|
2011-05-16 16:15:37 -07:00
|
|
|
{
|
2012-06-14 19:13:27 -07:00
|
|
|
js::Rooted<jsid> id(cx, js::NameToId(name));
|
|
|
|
return getGeneric(cx, receiver, id, vp);
|
2011-09-15 11:44:10 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
inline JSBool
|
2012-07-30 04:19:09 -07:00
|
|
|
JSObject::getGeneric(JSContext *cx, js::HandleId id, js::MutableHandleValue vp)
|
2011-09-15 11:44:10 -07:00
|
|
|
{
|
2012-06-14 19:13:27 -07:00
|
|
|
js::Rooted<JSObject*> obj(cx, this);
|
|
|
|
return getGeneric(cx, obj, id, vp);
|
2011-09-15 11:44:10 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
inline JSBool
|
2012-07-30 04:19:09 -07:00
|
|
|
JSObject::getProperty(JSContext *cx, js::PropertyName *name, js::MutableHandleValue vp)
|
2011-09-15 11:44:10 -07:00
|
|
|
{
|
2012-06-14 19:13:27 -07:00
|
|
|
js::Rooted<jsid> id(cx, js::NameToId(name));
|
|
|
|
return getGeneric(cx, id, vp);
|
2011-05-16 16:15:37 -07:00
|
|
|
}
|
|
|
|
|
2011-12-28 14:33:20 -08:00
|
|
|
inline bool
|
2012-07-30 04:19:09 -07:00
|
|
|
JSObject::deleteProperty(JSContext *cx, js::HandlePropertyName name, js::MutableHandleValue rval, bool strict)
|
2011-03-21 22:55:27 -07:00
|
|
|
{
|
2012-05-06 13:45:19 -07:00
|
|
|
jsid id = js::NameToId(name);
|
2011-12-28 14:33:20 -08:00
|
|
|
js::types::AddTypePropertyId(cx, this, id, js::types::Type::UndefinedType());
|
2011-07-15 10:14:07 -07:00
|
|
|
js::types::MarkTypePropertyConfigured(cx, this, id);
|
2011-12-28 14:33:20 -08:00
|
|
|
js::DeletePropertyOp op = getOps()->deleteProperty;
|
2012-06-14 19:13:27 -07:00
|
|
|
js::Rooted<JSObject*> obj(cx, this);
|
|
|
|
return (op ? op : js::baseops::DeleteProperty)(cx, obj, name, rval, strict);
|
2011-10-04 17:49:57 -07:00
|
|
|
}
|
|
|
|
|
2011-12-28 14:33:20 -08:00
|
|
|
inline bool
|
2012-07-30 04:19:09 -07:00
|
|
|
JSObject::deleteElement(JSContext *cx, uint32_t index, js::MutableHandleValue rval, bool strict)
|
2011-10-04 17:49:57 -07:00
|
|
|
{
|
2012-05-24 16:05:18 -07:00
|
|
|
js::RootedObject self(cx, this);
|
2012-04-30 17:10:30 -07:00
|
|
|
|
2011-10-04 17:49:57 -07:00
|
|
|
jsid id;
|
|
|
|
if (!js::IndexToId(cx, index, &id))
|
|
|
|
return false;
|
2012-04-30 17:10:30 -07:00
|
|
|
js::types::AddTypePropertyId(cx, self, id, js::types::Type::UndefinedType());
|
|
|
|
js::types::MarkTypePropertyConfigured(cx, self, id);
|
|
|
|
js::DeleteElementOp op = self->getOps()->deleteElement;
|
2012-05-19 15:03:45 -07:00
|
|
|
return (op ? op : js::baseops::DeleteElement)(cx, self, index, rval, strict);
|
2011-10-04 17:49:57 -07:00
|
|
|
}
|
|
|
|
|
2011-12-28 14:33:20 -08:00
|
|
|
inline bool
|
2012-07-30 04:19:09 -07:00
|
|
|
JSObject::deleteSpecial(JSContext *cx, js::HandleSpecialId sid, js::MutableHandleValue rval, bool strict)
|
2011-10-04 17:49:57 -07:00
|
|
|
{
|
2011-12-28 14:33:20 -08:00
|
|
|
jsid id = SPECIALID_TO_JSID(sid);
|
|
|
|
js::types::AddTypePropertyId(cx, this, id, js::types::Type::UndefinedType());
|
|
|
|
js::types::MarkTypePropertyConfigured(cx, this, id);
|
|
|
|
js::DeleteSpecialOp op = getOps()->deleteSpecial;
|
2012-06-14 19:13:27 -07:00
|
|
|
js::Rooted<JSObject*> obj(cx, this);
|
|
|
|
return (op ? op : js::baseops::DeleteSpecial)(cx, obj, sid, rval, strict);
|
2011-10-04 17:49:57 -07:00
|
|
|
}
|
|
|
|
|
2010-09-24 10:54:39 -07:00
|
|
|
inline void
|
2012-03-19 07:34:55 -07:00
|
|
|
JSObject::finalize(js::FreeOp *fop)
|
2010-09-24 10:54:39 -07:00
|
|
|
{
|
2010-09-20 12:43:53 -07:00
|
|
|
js::Probes::finalizeObject(this);
|
|
|
|
|
2012-03-19 07:34:55 -07:00
|
|
|
if (!fop->onBackgroundThread()) {
|
2011-09-29 20:29:13 -07:00
|
|
|
/*
|
|
|
|
* 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)
|
2012-03-19 07:34:55 -07:00
|
|
|
clasp->finalize(fop, this);
|
2011-09-29 20:29:13 -07:00
|
|
|
}
|
2010-09-24 10:54:39 -07:00
|
|
|
|
2012-03-19 07:34:55 -07:00
|
|
|
finish(fop);
|
2010-09-24 10:54:39 -07:00
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2011-11-09 09:52:59 -08:00
|
|
|
inline JSObject *
|
2012-01-02 15:02:05 -08:00
|
|
|
JSObject::enclosingScope()
|
2011-10-12 22:29:43 -07:00
|
|
|
{
|
2011-12-20 17:42:45 -08:00
|
|
|
return isScope()
|
|
|
|
? &asScope().enclosingScope()
|
|
|
|
: isDebugScope()
|
|
|
|
? &asDebugScope().enclosingScope()
|
|
|
|
: getParent();
|
2011-10-12 22:29:43 -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();
|
|
|
|
}
|
|
|
|
|
|
|
|
inline void
|
2012-07-04 19:33:41 -07:00
|
|
|
JSObject::setLastPropertyInfallible(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
|
|
|
|
2012-07-04 19:33:41 -07:00
|
|
|
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());
|
2012-07-04 19:33:41 -07:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2012-02-17 18:43:48 -08:00
|
|
|
inline const js::HeapSlot *
|
2011-11-14 09:13:33 -08:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2012-01-02 15:02:05 -08:00
|
|
|
inline const js::Value &
|
2012-02-28 15:11:11 -08:00
|
|
|
JSObject::getReservedSlot(unsigned index) const
|
2010-06-07 18:35:58 -07:00
|
|
|
{
|
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
|
|
|
}
|
|
|
|
|
2012-02-17 18:43:48 -08:00
|
|
|
inline js::HeapSlot &
|
2012-02-28 15:11:11 -08:00
|
|
|
JSObject::getReservedSlotRef(unsigned index)
|
2011-10-25 16:07:42 -07:00
|
|
|
{
|
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
|
2012-02-28 15:11:11 -08:00
|
|
|
JSObject::setReservedSlot(unsigned index, const js::Value &v)
|
2011-04-27 16:22:28 -07:00
|
|
|
{
|
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);
|
|
|
|
}
|
|
|
|
|
2012-02-17 18:43:48 -08:00
|
|
|
inline void
|
2012-02-28 15:11:11 -08:00
|
|
|
JSObject::initReservedSlot(unsigned index, const js::Value &v)
|
2012-02-17 18:43:48 -08:00
|
|
|
{
|
|
|
|
JS_ASSERT(index < JSSLOT_FREE(getClass()));
|
|
|
|
initSlot(index, v);
|
|
|
|
}
|
|
|
|
|
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++)
|
2012-02-17 18:43:48 -08:00
|
|
|
getSlotAddressUnchecked(i)->js::HeapSlot::~HeapSlot();
|
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++)
|
2012-02-17 18:43:48 -08:00
|
|
|
elements[i].js::HeapSlot::~HeapSlot();
|
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);
|
2012-05-06 13:45:19 -07:00
|
|
|
jsid lengthId = js::NameToId(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
|
|
|
}
|
|
|
|
|
2011-10-27 14:16:02 -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::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
|
|
|
}
|
|
|
|
|
|
|
|
inline void
|
2012-02-28 15:11:11 -08:00
|
|
|
JSObject::setDenseArrayElement(unsigned 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());
|
2012-02-17 18:43:48 -08:00
|
|
|
elements[idx].set(this, idx, val);
|
2010-04-26 18:33:36 -07:00
|
|
|
}
|
|
|
|
|
2011-10-25 16:07:42 -07:00
|
|
|
inline void
|
2012-02-28 15:11:11 -08:00
|
|
|
JSObject::initDenseArrayElement(unsigned idx, const js::Value &val)
|
2011-10-25 16:07:42 -07:00
|
|
|
{
|
|
|
|
JS_ASSERT(isDenseArray() && idx < getDenseArrayInitializedLength());
|
2012-02-17 18:43:48 -08:00
|
|
|
elements[idx].init(this, idx, val);
|
2011-10-25 16:07:42 -07:00
|
|
|
}
|
|
|
|
|
2011-05-16 16:15:37 -07:00
|
|
|
inline void
|
2012-02-28 15:11:11 -08:00
|
|
|
JSObject::setDenseArrayElementWithType(JSContext *cx, unsigned idx, const js::Value &val)
|
2011-05-16 16:15:37 -07:00
|
|
|
{
|
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
|
2012-02-28 15:11:11 -08:00
|
|
|
JSObject::initDenseArrayElementWithType(JSContext *cx, unsigned idx, const js::Value &val)
|
2011-10-25 16:07:42 -07:00
|
|
|
{
|
|
|
|
js::types::AddTypePropertyId(cx, this, JSID_VOID, val);
|
|
|
|
initDenseArrayElement(idx, val);
|
|
|
|
}
|
|
|
|
|
2011-07-13 15:43:33 -07:00
|
|
|
inline void
|
2012-02-28 15:11:11 -08:00
|
|
|
JSObject::copyDenseArrayElements(unsigned dstStart, const js::Value *src, unsigned count)
|
2011-10-25 16:07:42 -07:00
|
|
|
{
|
2011-11-14 09:13:33 -08:00
|
|
|
JS_ASSERT(dstStart + count <= getDenseArrayCapacity());
|
2011-12-28 14:06:21 -08:00
|
|
|
JSCompartment *comp = compartment();
|
2011-12-15 15:27:32 -08:00
|
|
|
for (unsigned i = 0; i < count; ++i)
|
2012-02-17 18:43:48 -08:00
|
|
|
elements[dstStart + i].set(comp, this, dstStart + i, src[i]);
|
2011-10-25 16:07:42 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
inline void
|
2012-02-28 15:11:11 -08:00
|
|
|
JSObject::initDenseArrayElements(unsigned dstStart, const js::Value *src, unsigned count)
|
2011-07-13 15:43:33 -07:00
|
|
|
{
|
2011-10-10 11:41:03 -07:00
|
|
|
JS_ASSERT(dstStart + count <= getDenseArrayCapacity());
|
2011-12-28 14:06:21 -08:00
|
|
|
JSCompartment *comp = compartment();
|
2011-12-15 15:27:32 -08:00
|
|
|
for (unsigned i = 0; i < count; ++i)
|
2012-02-17 18:43:48 -08:00
|
|
|
elements[dstStart + i].init(comp, this, dstStart + i, src[i]);
|
2011-07-13 15:43:33 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
inline void
|
2012-02-28 15:11:11 -08:00
|
|
|
JSObject::moveDenseArrayElements(unsigned dstStart, unsigned srcStart, unsigned count)
|
2011-07-13 15:43:33 -07:00
|
|
|
{
|
2011-10-10 11:41:03 -07:00
|
|
|
JS_ASSERT(dstStart + count <= getDenseArrayCapacity());
|
2012-01-30 17:13:07 -08:00
|
|
|
JS_ASSERT(srcStart + count <= getDenseArrayInitializedLength());
|
2011-10-25 16:07:42 -07:00
|
|
|
|
|
|
|
/*
|
2012-02-17 14:35:20 -08:00
|
|
|
* Using memmove here would skip write barriers. Also, we need to consider
|
|
|
|
* an array containing [A, B, C], in the following situation:
|
|
|
|
*
|
|
|
|
* 1. Incremental GC marks slot 0 of array (i.e., A), then returns to JS code.
|
|
|
|
* 2. JS code moves slots 1..2 into slots 0..1, so it contains [B, C, C].
|
|
|
|
* 3. Incremental GC finishes by marking slots 1 and 2 (i.e., C).
|
|
|
|
*
|
|
|
|
* Since normal marking never happens on B, it is very important that the
|
|
|
|
* write barrier is invoked here on B, despite the fact that it exists in
|
|
|
|
* the array before and after the move.
|
|
|
|
*/
|
2012-02-17 18:43:48 -08:00
|
|
|
JSCompartment *comp = compartment();
|
|
|
|
if (comp->needsBarrier()) {
|
2012-02-17 14:35:20 -08:00
|
|
|
if (dstStart < srcStart) {
|
2012-02-17 18:43:48 -08:00
|
|
|
js::HeapSlot *dst = elements + dstStart;
|
|
|
|
js::HeapSlot *src = elements + srcStart;
|
2012-02-17 14:35:20 -08:00
|
|
|
for (unsigned i = 0; i < count; i++, dst++, src++)
|
2012-02-17 18:43:48 -08:00
|
|
|
dst->set(comp, this, dst - elements, *src);
|
2012-02-17 14:35:20 -08:00
|
|
|
} else {
|
2012-02-17 18:43:48 -08:00
|
|
|
js::HeapSlot *dst = elements + dstStart + count - 1;
|
|
|
|
js::HeapSlot *src = elements + srcStart + count - 1;
|
2012-02-17 14:35:20 -08:00
|
|
|
for (unsigned i = 0; i < count; i++, dst--, src--)
|
2012-02-17 18:43:48 -08:00
|
|
|
dst->set(comp, this, dst - elements, *src);
|
2012-02-17 14:35:20 -08:00
|
|
|
}
|
2011-10-25 16:07:42 -07:00
|
|
|
} else {
|
2012-02-17 18:43:48 -08:00
|
|
|
memmove(elements + dstStart, elements + srcStart, count * sizeof(js::HeapSlot));
|
2012-04-05 17:56:53 -07:00
|
|
|
SlotRangeWriteBarrierPost(comp, this, dstStart, count);
|
2011-10-25 16:07:42 -07:00
|
|
|
}
|
2010-04-05 18:32:16 -07:00
|
|
|
}
|
|
|
|
|
2012-01-30 17:13:07 -08:00
|
|
|
inline void
|
2012-02-28 15:11:11 -08:00
|
|
|
JSObject::moveDenseArrayElementsUnbarriered(unsigned dstStart, unsigned srcStart, unsigned count)
|
2012-01-30 17:13:07 -08:00
|
|
|
{
|
|
|
|
JS_ASSERT(!compartment()->needsBarrier());
|
2012-02-03 13:47:39 -08:00
|
|
|
|
|
|
|
JS_ASSERT(dstStart + count <= getDenseArrayCapacity());
|
|
|
|
JS_ASSERT(srcStart + count <= getDenseArrayCapacity());
|
|
|
|
|
2012-01-30 17:13:07 -08:00
|
|
|
memmove(elements + dstStart, elements + srcStart, count * sizeof(js::Value));
|
|
|
|
}
|
|
|
|
|
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 *
|
2012-07-03 10:24:27 -07:00
|
|
|
CallObjectLambdaName(JSFunction &fun)
|
2011-09-01 12:20:30 -07:00
|
|
|
{
|
2012-07-03 10:24:27 -07:00
|
|
|
return (fun.flags & JSFUN_LAMBDA) ? fun.atom.get() : NULL;
|
2011-09-01 12:20:30 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
} /* 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
|
|
|
}
|
|
|
|
|
2012-03-19 17:24:05 -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
|
|
|
}
|
|
|
|
|
2012-05-14 16:53:30 -07:00
|
|
|
#if JS_HAS_XML_SUPPORT
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2012-05-14 16:53:30 -07:00
|
|
|
#endif
|
|
|
|
|
2011-07-15 10:14:07 -07:00
|
|
|
inline bool
|
|
|
|
JSObject::setSingletonType(JSContext *cx)
|
|
|
|
{
|
|
|
|
if (!cx->typeInferenceEnabled())
|
|
|
|
return true;
|
|
|
|
|
2012-06-21 14:19:21 -07:00
|
|
|
JS::Rooted<JSObject*> self(cx, this);
|
2011-07-15 10:14:07 -07:00
|
|
|
JS_ASSERT(!hasLazyType());
|
2012-06-21 14:19:21 -07:00
|
|
|
JS_ASSERT_IF(self->getProto(), self->type() == self->getProto()->getNewType(cx, NULL));
|
2011-07-15 10:14:07 -07:00
|
|
|
|
2012-06-21 14:19:21 -07:00
|
|
|
js::types::TypeObject *type = cx->compartment->getLazyType(cx, self->getProto());
|
2011-10-14 14:54:04 -07:00
|
|
|
if (!type)
|
|
|
|
return false;
|
2011-07-15 10:14:07 -07:00
|
|
|
|
2012-06-21 14:19:21 -07:00
|
|
|
self->type_ = type;
|
2011-07-15 10:14:07 -07:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline js::types::TypeObject *
|
|
|
|
JSObject::getType(JSContext *cx)
|
|
|
|
{
|
2012-06-21 14:19:21 -07:00
|
|
|
JS::RootedObject self(cx, this);
|
|
|
|
if (self->hasLazyType())
|
|
|
|
self->makeLazyType(cx);
|
|
|
|
return self->type_;
|
2011-07-15 10:14:07 -07:00
|
|
|
}
|
|
|
|
|
2012-07-10 18:17:29 -07:00
|
|
|
/* static */ inline bool
|
|
|
|
JSObject::clearType(JSContext *cx, js::HandleObject obj)
|
2010-12-18 20:44:51 -08:00
|
|
|
{
|
2012-07-10 18:17:29 -07:00
|
|
|
JS_ASSERT(!obj->hasSingletonType());
|
2011-10-07 20:09:09 -07:00
|
|
|
|
|
|
|
js::types::TypeObject *type = cx->compartment->getEmptyType(cx);
|
|
|
|
if (!type)
|
|
|
|
return false;
|
|
|
|
|
2012-07-10 18:17:29 -07:00
|
|
|
obj->type_ = type;
|
2011-10-07 20:09:09 -07:00
|
|
|
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::setDelegate(JSContext *cx)
|
|
|
|
{
|
2011-10-14 13:51:21 -07:00
|
|
|
return setFlag(cx, js::BaseShape::DELEGATE, GENERATE_SHAPE);
|
|
|
|
}
|
|
|
|
|
2011-12-20 17:42:45 -08:00
|
|
|
inline bool JSObject::isVarObj()
|
2011-11-16 12:52:47 -08:00
|
|
|
{
|
2011-12-20 17:42:45 -08:00
|
|
|
if (isDebugScope())
|
|
|
|
return asDebugScope().scope().isVarObj();
|
2011-11-16 12:52:47 -08:00
|
|
|
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::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::isBlock() const { return hasClass(&js::BlockClass); }
|
2012-01-02 15:02:05 -08:00
|
|
|
inline bool JSObject::isBoolean() const { return hasClass(&js::BooleanClass); }
|
2011-10-04 18:46:03 -07:00
|
|
|
inline bool JSObject::isCall() const { return hasClass(&js::CallClass); }
|
2012-01-02 15:02:05 -08:00
|
|
|
inline bool JSObject::isClonedBlock() const { return isBlock() && !!getProto(); }
|
2012-03-25 19:14:27 -07:00
|
|
|
inline bool JSObject::isDataView() const { return hasClass(&js::DataViewClass); }
|
2012-01-02 15:02:05 -08:00
|
|
|
inline bool JSObject::isDate() const { return hasClass(&js::DateClass); }
|
2011-10-04 18:46:03 -07:00
|
|
|
inline bool JSObject::isDeclEnv() const { return hasClass(&js::DeclEnvClass); }
|
2012-02-07 10:57:16 -08:00
|
|
|
inline bool JSObject::isElementIterator() const { return hasClass(&js::ElementIteratorClass); }
|
2012-01-02 15:02:05 -08:00
|
|
|
inline bool JSObject::isError() const { return hasClass(&js::ErrorClass); }
|
|
|
|
inline bool JSObject::isFunction() const { return hasClass(&js::FunctionClass); }
|
|
|
|
inline bool JSObject::isFunctionProxy() const { return hasClass(&js::FunctionProxyClass); }
|
2011-10-04 18:46:03 -07:00
|
|
|
inline bool JSObject::isGenerator() const { return hasClass(&js::GeneratorClass); }
|
2012-07-04 08:24:25 -07:00
|
|
|
inline bool JSObject::isMapIterator() const { return hasClass(&js::MapIteratorClass); }
|
2012-01-02 15:02:05 -08:00
|
|
|
inline bool JSObject::isNestedScope() const { return isBlock() || isWith(); }
|
|
|
|
inline bool JSObject::isNormalArguments() const { return hasClass(&js::NormalArgumentsObjectClass); }
|
|
|
|
inline bool JSObject::isNumber() const { return hasClass(&js::NumberClass); }
|
|
|
|
inline bool JSObject::isObject() const { return hasClass(&js::ObjectClass); }
|
|
|
|
inline bool JSObject::isPrimitive() const { return isNumber() || isString() || isBoolean(); }
|
|
|
|
inline bool JSObject::isRegExp() const { return hasClass(&js::RegExpClass); }
|
2012-01-30 18:12:03 -08:00
|
|
|
inline bool JSObject::isRegExpStatics() const { return hasClass(&js::RegExpStaticsClass); }
|
2012-01-02 15:02:05 -08:00
|
|
|
inline bool JSObject::isScope() const { return isCall() || isDeclEnv() || isNestedScope(); }
|
2012-07-04 08:24:25 -07:00
|
|
|
inline bool JSObject::isSetIterator() const { return hasClass(&js::SetIteratorClass); }
|
2012-01-02 15:02:05 -08:00
|
|
|
inline bool JSObject::isStaticBlock() const { return isBlock() && !getProto(); }
|
|
|
|
inline bool JSObject::isStopIteration() const { return hasClass(&js::StopIterationClass); }
|
|
|
|
inline bool JSObject::isStrictArguments() const { return hasClass(&js::StrictArgumentsObjectClass); }
|
|
|
|
inline bool JSObject::isString() const { return hasClass(&js::StringClass); }
|
2012-04-23 15:13:02 -07:00
|
|
|
inline bool JSObject::isTypedArray() const { return IsTypedArrayClass(getClass()); }
|
2011-10-04 18:46:03 -07:00
|
|
|
inline bool JSObject::isWeakMap() const { return hasClass(&js::WeakMapClass); }
|
2012-01-02 15:02:05 -08:00
|
|
|
inline bool JSObject::isWith() const { return hasClass(&js::WithClass); }
|
2012-05-14 16:53:30 -07:00
|
|
|
|
2011-12-20 17:42:45 -08:00
|
|
|
inline bool
|
|
|
|
JSObject::isDebugScope() const
|
|
|
|
{
|
2012-07-23 13:37:31 -07:00
|
|
|
extern bool js_IsDebugScopeSlow(JS::RawObject obj);
|
|
|
|
return getClass() == &js::ObjectProxyClass && js_IsDebugScopeSlow(const_cast<JSObject*>(this));
|
2011-12-20 17:42:45 -08:00
|
|
|
}
|
|
|
|
|
2012-05-14 16:53:30 -07:00
|
|
|
#if JS_HAS_XML_SUPPORT
|
|
|
|
inline bool JSObject::isNamespace() const { return hasClass(&js::NamespaceClass); }
|
2012-01-02 15:02:05 -08:00
|
|
|
inline bool JSObject::isXML() const { return hasClass(&js::XMLClass); }
|
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);
|
|
|
|
}
|
2012-05-14 16:53:30 -07:00
|
|
|
#endif /* JS_HAS_XML_SUPPORT */
|
2011-10-04 18:46:03 -07:00
|
|
|
|
2011-11-18 14:59:31 -08:00
|
|
|
/* static */ inline JSObject *
|
|
|
|
JSObject::create(JSContext *cx, js::gc::AllocKind kind,
|
2012-02-17 18:43:48 -08:00
|
|
|
js::HandleShape shape, js::HandleTypeObject type, js::HeapSlot *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
|
|
|
|
2012-05-16 12:01:50 -07:00
|
|
|
const js::Class *clasp = shape->getObjectClass();
|
|
|
|
if (clasp->hasPrivate())
|
2011-11-22 15:21:10 -08:00
|
|
|
obj->privateRef(shape->numFixedSlots()) = NULL;
|
2011-11-18 14:59:31 -08:00
|
|
|
|
2012-05-16 12:01:50 -07:00
|
|
|
size_t span = shape->slotSpan();
|
|
|
|
if (span && clasp != &js::ArrayBufferClass)
|
2011-11-18 14:59:31 -08:00
|
|
|
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,
|
2011-12-31 06:32:04 -08:00
|
|
|
js::HandleShape shape, js::HandleTypeObject 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);
|
2012-03-10 12:52:28 -08:00
|
|
|
if (!obj) {
|
|
|
|
js_ReportOutOfMemory(cx);
|
2011-11-18 14:59:31 -08:00
|
|
|
return NULL;
|
2012-03-10 12:52:28 -08:00
|
|
|
}
|
2011-11-18 14:59:31 -08:00
|
|
|
|
|
|
|
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
|
2012-03-19 07:34:55 -07:00
|
|
|
JSObject::finish(js::FreeOp *fop)
|
2009-11-18 12:29:58 -08:00
|
|
|
{
|
2011-10-10 11:41:03 -07:00
|
|
|
if (hasDynamicSlots())
|
2012-03-19 07:34:55 -07:00
|
|
|
fop->free_(slots);
|
2011-10-10 11:41:03 -07:00
|
|
|
if (hasDynamicElements())
|
2012-03-19 07:34:55 -07:00
|
|
|
fop->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
|
2012-05-19 15:03:45 -07:00
|
|
|
JSObject::hasProperty(JSContext *cx, js::HandleId id, bool *foundp, unsigned flags)
|
2010-08-29 11:57:08 -07:00
|
|
|
{
|
2012-07-04 11:12:16 -07:00
|
|
|
js::RootedObject pobj(cx);
|
2012-07-04 19:34:06 -07:00
|
|
|
js::RootedShape prop(cx);
|
2010-08-29 11:57:08 -07:00
|
|
|
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)
|
|
|
|
{
|
2012-03-09 01:48:50 -08:00
|
|
|
if (JSObjectPrincipalsFinder find = cx->runtime->securityCallbacks->findObjectPrincipals)
|
|
|
|
return find(this);
|
2011-07-22 15:22:05 -07:00
|
|
|
return cx->compartment ? cx->compartment->principals : NULL;
|
2011-04-08 10:52:51 -07:00
|
|
|
}
|
|
|
|
|
2011-04-08 14:21:08 -07:00
|
|
|
inline void
|
2012-02-28 15:11:11 -08:00
|
|
|
JSObject::nativeSetSlot(unsigned slot, const js::Value &value)
|
2011-04-08 14:21:08 -07:00
|
|
|
{
|
|
|
|
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
|
2012-07-04 19:33:41 -07:00
|
|
|
JSObject::nativeSetSlotWithType(JSContext *cx, js::Shape *shape, const js::Value &value)
|
2011-05-18 10:43:08 -07:00
|
|
|
{
|
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
|
2012-07-10 18:17:29 -07:00
|
|
|
JSObject::nativeContains(JSContext *cx, js::HandleId 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
|
2012-07-10 18:17:29 -07:00
|
|
|
JSObject::nativeContains(JSContext *cx, js::HandleShape shape)
|
|
|
|
{
|
|
|
|
return nativeLookup(cx, shape->propid()) == shape;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline bool
|
|
|
|
JSObject::nativeContainsNoAllocation(jsid id)
|
|
|
|
{
|
|
|
|
return nativeLookupNoAllocation(id) != NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline bool
|
|
|
|
JSObject::nativeContainsNoAllocation(const js::Shape &shape)
|
2011-04-08 14:21:08 -07:00
|
|
|
{
|
2012-07-10 18:17:29 -07:00
|
|
|
return nativeLookupNoAllocation(shape.propid()) == &shape;
|
2011-04-08 14:21:08 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
inline bool
|
|
|
|
JSObject::nativeEmpty() const
|
|
|
|
{
|
|
|
|
return lastProperty()->isEmptyShape();
|
|
|
|
}
|
|
|
|
|
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
|
2012-05-02 14:33:17 -07:00
|
|
|
JSObject::hasShapeTable() const
|
2011-04-08 14:21:08 -07:00
|
|
|
{
|
|
|
|
return lastProperty()->hasTable();
|
|
|
|
}
|
|
|
|
|
2011-10-10 11:41:03 -07:00
|
|
|
inline size_t
|
2012-01-30 18:12:03 -08:00
|
|
|
JSObject::computedSizeOfThisSlotsElements() const
|
2011-04-08 14:21:08 -07:00
|
|
|
{
|
2012-01-30 18:12:03 -08:00
|
|
|
size_t n = sizeOfThis();
|
|
|
|
|
|
|
|
if (hasDynamicSlots())
|
|
|
|
n += numDynamicSlots() * sizeof(js::Value);
|
|
|
|
|
|
|
|
if (hasDynamicElements())
|
|
|
|
n += (js::ObjectElements::VALUES_PER_HEADER + getElementsHeader()->capacity) *
|
|
|
|
sizeof(js::Value);
|
|
|
|
|
|
|
|
return n;
|
2011-11-21 17:29:05 -08:00
|
|
|
}
|
|
|
|
|
2012-01-23 15:35:37 -08:00
|
|
|
inline void
|
|
|
|
JSObject::sizeOfExcludingThis(JSMallocSizeOfFun mallocSizeOf,
|
2012-01-30 18:12:03 -08:00
|
|
|
size_t *slotsSize, size_t *elementsSize,
|
|
|
|
size_t *miscSize) const
|
2011-11-21 17:29:05 -08:00
|
|
|
{
|
2012-01-30 18:12:03 -08:00
|
|
|
*slotsSize = 0;
|
2011-11-21 17:29:05 -08:00
|
|
|
if (hasDynamicSlots()) {
|
2012-01-30 18:12:03 -08:00
|
|
|
*slotsSize += mallocSizeOf(slots);
|
2011-11-21 17:29:05 -08:00
|
|
|
}
|
2012-01-30 18:12:03 -08:00
|
|
|
|
|
|
|
*elementsSize = 0;
|
2011-11-21 17:29:05 -08:00
|
|
|
if (hasDynamicElements()) {
|
2012-01-30 18:12:03 -08:00
|
|
|
*elementsSize += mallocSizeOf(getElementsHeader());
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Other things may be measured in the future if DMD indicates it is worthwhile. */
|
|
|
|
*miscSize = 0;
|
2012-02-27 23:49:02 -08:00
|
|
|
if (isArguments()) {
|
2012-01-30 18:12:03 -08:00
|
|
|
*miscSize += asArguments().sizeOfMisc(mallocSizeOf);
|
|
|
|
} else if (isRegExpStatics()) {
|
|
|
|
*miscSize += js::SizeOfRegExpStaticsData(this, mallocSizeOf);
|
2011-11-21 17:29:05 -08:00
|
|
|
}
|
2011-04-08 14:21:08 -07:00
|
|
|
}
|
|
|
|
|
2011-10-04 18:46:03 -07:00
|
|
|
inline JSBool
|
2012-07-04 19:34:06 -07:00
|
|
|
JSObject::lookupGeneric(JSContext *cx, js::HandleId id,
|
|
|
|
js::MutableHandleObject objp, js::MutableHandleShape propp)
|
2011-10-04 18:46:03 -07:00
|
|
|
{
|
2012-05-24 16:05:18 -07:00
|
|
|
js::RootedObject self(cx, this);
|
2012-05-19 15:03:45 -07:00
|
|
|
|
2011-10-08 15:45:04 -07:00
|
|
|
js::LookupGenericOp op = getOps()->lookupGeneric;
|
2012-05-19 15:03:45 -07:00
|
|
|
if (op)
|
|
|
|
return op(cx, self, id, objp, propp);
|
|
|
|
return js::baseops::LookupProperty(cx, self, id, objp, propp);
|
2011-10-04 18:46:03 -07:00
|
|
|
}
|
|
|
|
|
2011-10-08 15:45:04 -07:00
|
|
|
inline JSBool
|
2012-07-04 19:34:06 -07:00
|
|
|
JSObject::lookupProperty(JSContext *cx, js::PropertyName *name,
|
|
|
|
js::MutableHandleObject objp, js::MutableHandleShape propp)
|
2011-10-08 15:45:04 -07:00
|
|
|
{
|
2012-06-14 19:13:27 -07:00
|
|
|
js::Rooted<jsid> id(cx, js::NameToId(name));
|
|
|
|
return lookupGeneric(cx, id, objp, propp);
|
2011-10-08 15:45:04 -07:00
|
|
|
}
|
|
|
|
|
2011-10-05 01:00:23 -07:00
|
|
|
inline JSBool
|
2012-07-30 04:19:09 -07:00
|
|
|
JSObject::defineGeneric(JSContext *cx, js::HandleId id, js::HandleValue value,
|
2011-10-05 01:00:23 -07:00
|
|
|
JSPropertyOp getter /* = JS_PropertyStub */,
|
|
|
|
JSStrictPropertyOp setter /* = JS_StrictPropertyStub */,
|
2012-02-28 15:11:11 -08:00
|
|
|
unsigned attrs /* = JSPROP_ENUMERATE */)
|
2011-10-05 01:00:23 -07:00
|
|
|
{
|
2012-05-24 16:05:18 -07:00
|
|
|
js::RootedObject self(cx, this);
|
2012-05-19 15:03:45 -07:00
|
|
|
|
2012-03-29 13:34:36 -07:00
|
|
|
JS_ASSERT(!(attrs & JSPROP_NATIVE_ACCESSORS));
|
2011-10-05 01:00:23 -07:00
|
|
|
js::DefineGenericOp op = getOps()->defineGeneric;
|
2012-07-30 04:19:09 -07:00
|
|
|
return (op ? op : js::baseops::DefineGeneric)(cx, self, id, value, getter, setter, attrs);
|
2011-10-05 01:00:23 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
inline JSBool
|
2012-07-30 04:19:09 -07:00
|
|
|
JSObject::defineProperty(JSContext *cx, js::PropertyName *name, js::HandleValue value,
|
2011-10-05 01:00:23 -07:00
|
|
|
JSPropertyOp getter /* = JS_PropertyStub */,
|
|
|
|
JSStrictPropertyOp setter /* = JS_StrictPropertyStub */,
|
2012-02-28 15:11:11 -08:00
|
|
|
unsigned attrs /* = JSPROP_ENUMERATE */)
|
2011-10-05 01:00:23 -07:00
|
|
|
{
|
2012-06-14 19:13:27 -07:00
|
|
|
js::Rooted<jsid> id(cx, js::NameToId(name));
|
|
|
|
return defineGeneric(cx, id, value, getter, setter, attrs);
|
2011-10-05 01:00:23 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
inline JSBool
|
2012-07-30 04:19:09 -07:00
|
|
|
JSObject::defineElement(JSContext *cx, uint32_t index, js::HandleValue value,
|
2011-10-05 01:00:23 -07:00
|
|
|
JSPropertyOp getter /* = JS_PropertyStub */,
|
|
|
|
JSStrictPropertyOp setter /* = JS_StrictPropertyStub */,
|
2012-02-28 15:11:11 -08:00
|
|
|
unsigned attrs /* = JSPROP_ENUMERATE */)
|
2011-10-05 01:00:23 -07:00
|
|
|
{
|
2012-05-24 16:05:18 -07:00
|
|
|
js::RootedObject self(cx, this);
|
2012-05-19 15:03:45 -07:00
|
|
|
|
2011-10-05 01:00:23 -07:00
|
|
|
js::DefineElementOp op = getOps()->defineElement;
|
2012-07-30 04:19:09 -07:00
|
|
|
return (op ? op : js::baseops::DefineElement)(cx, self, index, value, getter, setter, attrs);
|
2011-10-05 01:00:23 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
inline JSBool
|
2012-07-30 04:19:09 -07:00
|
|
|
JSObject::defineSpecial(JSContext *cx, js::SpecialId sid, js::HandleValue value,
|
2011-10-05 01:00:23 -07:00
|
|
|
JSPropertyOp getter /* = JS_PropertyStub */,
|
|
|
|
JSStrictPropertyOp setter /* = JS_StrictPropertyStub */,
|
2012-02-28 15:11:11 -08:00
|
|
|
unsigned attrs /* = JSPROP_ENUMERATE */)
|
2011-10-05 01:00:23 -07:00
|
|
|
{
|
2012-06-14 19:13:27 -07:00
|
|
|
js::Rooted<jsid> id(cx, SPECIALID_TO_JSID(sid));
|
|
|
|
return defineGeneric(cx, id, value, getter, setter, attrs);
|
2011-10-05 01:00:23 -07:00
|
|
|
}
|
|
|
|
|
2011-08-10 14:54:51 -07:00
|
|
|
inline JSBool
|
2012-07-04 19:34:06 -07:00
|
|
|
JSObject::lookupElement(JSContext *cx, uint32_t index,
|
|
|
|
js::MutableHandleObject objp, js::MutableHandleShape propp)
|
2011-08-10 14:54:51 -07:00
|
|
|
{
|
2012-05-24 16:05:18 -07:00
|
|
|
js::RootedObject self(cx, this);
|
2012-05-19 15:03:45 -07:00
|
|
|
|
2011-08-10 14:54:52 -07:00
|
|
|
js::LookupElementOp op = getOps()->lookupElement;
|
2012-05-19 15:03:45 -07:00
|
|
|
return (op ? op : js::baseops::LookupElement)(cx, self, index, objp, propp);
|
2011-08-10 14:54:51 -07:00
|
|
|
}
|
|
|
|
|
2011-10-08 15:45:04 -07:00
|
|
|
inline JSBool
|
2012-07-04 19:34:06 -07:00
|
|
|
JSObject::lookupSpecial(JSContext *cx, js::SpecialId sid,
|
|
|
|
js::MutableHandleObject objp, js::MutableHandleShape propp)
|
2011-10-08 15:45:04 -07:00
|
|
|
{
|
2012-06-14 19:13:27 -07:00
|
|
|
js::Rooted<jsid> id(cx, SPECIALID_TO_JSID(sid));
|
|
|
|
return lookupGeneric(cx, id, objp, propp);
|
2011-10-08 15:45:04 -07:00
|
|
|
}
|
|
|
|
|
2011-08-10 14:54:51 -07:00
|
|
|
inline JSBool
|
2012-07-30 04:19:09 -07:00
|
|
|
JSObject::getElement(JSContext *cx, js::HandleObject receiver, uint32_t index, js::MutableHandleValue vp)
|
2011-08-10 14:54:51 -07:00
|
|
|
{
|
2012-05-24 16:05:18 -07:00
|
|
|
js::RootedObject self(cx, this);
|
2012-05-19 15:03:45 -07:00
|
|
|
|
2011-11-03 22:32:09 -07:00
|
|
|
js::ElementIdOp op = getOps()->getElement;
|
|
|
|
if (op)
|
2012-05-19 15:03:45 -07:00
|
|
|
return op(cx, self, receiver, index, vp);
|
2012-04-30 17:10:30 -07:00
|
|
|
|
2012-05-24 16:05:18 -07:00
|
|
|
js::RootedId id(cx);
|
2012-05-19 15:03:45 -07:00
|
|
|
if (!js::IndexToId(cx, index, id.address()))
|
2011-08-10 14:54:51 -07:00
|
|
|
return false;
|
2012-04-30 17:10:30 -07:00
|
|
|
return self->getGeneric(cx, receiver, id, vp);
|
2011-08-10 14:54:51 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
inline JSBool
|
2012-07-30 04:19:09 -07:00
|
|
|
JSObject::getElement(JSContext *cx, uint32_t index, js::MutableHandleValue vp)
|
2011-08-10 14:54:51 -07:00
|
|
|
{
|
2012-06-14 19:13:27 -07:00
|
|
|
js::Rooted<JSObject*> obj(cx, this);
|
|
|
|
return getElement(cx, obj, index, vp);
|
2011-08-10 14:54:51 -07:00
|
|
|
}
|
|
|
|
|
2011-11-04 09:18:52 -07:00
|
|
|
inline JSBool
|
2012-07-30 04:19:09 -07:00
|
|
|
JSObject::getElementIfPresent(JSContext *cx, js::HandleObject receiver, uint32_t index, js::MutableHandleValue vp,
|
2011-11-04 09:18:52 -07:00
|
|
|
bool *present)
|
|
|
|
{
|
2012-05-24 16:05:18 -07:00
|
|
|
js::RootedObject self(cx, this);
|
2012-04-30 17:10:30 -07:00
|
|
|
|
2011-11-04 09:19:00 -07:00
|
|
|
js::ElementIfPresentOp op = getOps()->getElementIfPresent;
|
|
|
|
if (op)
|
2012-05-19 15:03:45 -07:00
|
|
|
return op(cx, self, receiver, index, vp, present);
|
2011-11-04 09:19:00 -07:00
|
|
|
|
2012-04-30 17:10:30 -07:00
|
|
|
/*
|
|
|
|
* For now, do the index-to-id conversion just once, then use
|
2011-11-04 09:18:52 -07:00
|
|
|
* lookupGeneric/getGeneric. Once lookupElement and getElement stop both
|
|
|
|
* doing index-to-id conversions, we can use those here.
|
|
|
|
*/
|
2012-05-24 16:05:18 -07:00
|
|
|
js::RootedId id(cx);
|
2012-05-19 15:03:45 -07:00
|
|
|
if (!js::IndexToId(cx, index, id.address()))
|
2011-08-10 14:54:51 -07:00
|
|
|
return false;
|
2011-11-04 09:18:52 -07:00
|
|
|
|
2012-07-04 11:12:16 -07:00
|
|
|
js::RootedObject obj2(cx);
|
2012-07-04 19:34:06 -07:00
|
|
|
js::RootedShape prop(cx);
|
2012-04-30 17:10:30 -07:00
|
|
|
if (!self->lookupGeneric(cx, id, &obj2, &prop))
|
2011-11-04 09:18:52 -07:00
|
|
|
return false;
|
|
|
|
|
|
|
|
if (!prop) {
|
|
|
|
*present = false;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
*present = true;
|
2012-04-30 17:10:30 -07:00
|
|
|
return self->getGeneric(cx, receiver, id, vp);
|
2011-08-10 14:54:51 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
inline JSBool
|
2012-07-30 04:19:09 -07:00
|
|
|
JSObject::getSpecial(JSContext *cx, js::HandleObject receiver, js::SpecialId sid, js::MutableHandleValue vp)
|
2011-08-12 11:26:48 -07:00
|
|
|
{
|
2012-06-14 19:13:27 -07:00
|
|
|
js::Rooted<jsid> id(cx, SPECIALID_TO_JSID(sid));
|
|
|
|
return getGeneric(cx, receiver, id, vp);
|
2011-08-12 11:26:48 -07:00
|
|
|
}
|
|
|
|
|
2011-10-04 17:21:06 -07:00
|
|
|
inline JSBool
|
2012-05-19 15:03:45 -07:00
|
|
|
JSObject::getGenericAttributes(JSContext *cx, js::HandleId id, unsigned *attrsp)
|
2011-10-04 17:21:06 -07:00
|
|
|
{
|
|
|
|
js::GenericAttributesOp op = getOps()->getGenericAttributes;
|
2012-06-14 19:13:27 -07:00
|
|
|
js::Rooted<JSObject*> obj(cx, this);
|
|
|
|
return (op ? op : js::baseops::GetAttributes)(cx, obj, id, attrsp);
|
2011-10-04 17:21:06 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
inline JSBool
|
2012-02-28 15:11:11 -08:00
|
|
|
JSObject::getPropertyAttributes(JSContext *cx, js::PropertyName *name, unsigned *attrsp)
|
2011-10-04 17:21:06 -07:00
|
|
|
{
|
2012-06-14 19:13:27 -07:00
|
|
|
js::Rooted<jsid> id(cx, js::NameToId(name));
|
|
|
|
return getGenericAttributes(cx, id, attrsp);
|
2011-10-04 17:21:06 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
inline JSBool
|
2012-02-28 15:11:11 -08:00
|
|
|
JSObject::getElementAttributes(JSContext *cx, uint32_t index, unsigned *attrsp)
|
2011-08-10 14:54:51 -07:00
|
|
|
{
|
2012-05-24 16:05:18 -07:00
|
|
|
js::RootedId id(cx);
|
2012-05-19 15:03:45 -07:00
|
|
|
if (!js::IndexToId(cx, index, id.address()))
|
2011-08-10 14:54:51 -07:00
|
|
|
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
|
2012-02-28 15:11:11 -08:00
|
|
|
JSObject::getSpecialAttributes(JSContext *cx, js::SpecialId sid, unsigned *attrsp)
|
2011-08-12 11:26:48 -07:00
|
|
|
{
|
2012-06-14 19:13:27 -07:00
|
|
|
js::Rooted<jsid> id(cx, SPECIALID_TO_JSID(sid));
|
|
|
|
return getGenericAttributes(cx, id, attrsp);
|
2011-08-12 11:26:48 -07:00
|
|
|
}
|
|
|
|
|
2011-10-04 07:06:54 -07:00
|
|
|
inline bool
|
|
|
|
JSObject::isProxy() const
|
|
|
|
{
|
2012-07-23 13:37:31 -07:00
|
|
|
return js::IsProxy(const_cast<JSObject*>(this));
|
2011-10-04 07:06:54 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
inline bool
|
|
|
|
JSObject::isCrossCompartmentWrapper() const
|
|
|
|
{
|
2012-07-23 13:37:31 -07:00
|
|
|
return js::IsCrossCompartmentWrapper(const_cast<JSObject*>(this));
|
2011-10-04 07:06:54 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
inline bool
|
|
|
|
JSObject::isWrapper() const
|
|
|
|
{
|
2012-07-23 13:37:31 -07:00
|
|
|
return js::IsWrapper(const_cast<JSObject*>(this));
|
2011-10-04 07:06:54 -07:00
|
|
|
}
|
|
|
|
|
2012-01-02 15:02:05 -08:00
|
|
|
inline js::GlobalObject &
|
|
|
|
JSObject::global() const
|
2011-11-03 09:57:12 -07:00
|
|
|
{
|
|
|
|
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;
|
2012-07-03 17:25:15 -07:00
|
|
|
JS_ASSERT(&obj->asGlobal() == compartment()->maybeGlobal());
|
2011-11-03 09:57:12 -07:00
|
|
|
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-03-28 20:32:20 -07:00
|
|
|
namespace js {
|
|
|
|
|
2012-05-17 11:38:25 -07:00
|
|
|
PropDesc::PropDesc(const Value &getter, const Value &setter,
|
|
|
|
Enumerability enumerable, Configurability configurable)
|
|
|
|
: pd_(UndefinedValue()),
|
|
|
|
value_(UndefinedValue()),
|
|
|
|
get_(getter), set_(setter),
|
|
|
|
attrs(JSPROP_GETTER | JSPROP_SETTER | JSPROP_SHARED |
|
|
|
|
(enumerable ? JSPROP_ENUMERATE : 0) |
|
|
|
|
(configurable ? 0 : JSPROP_PERMANENT)),
|
|
|
|
hasGet_(true), hasSet_(true),
|
|
|
|
hasValue_(false), hasWritable_(false), hasEnumerable_(true), hasConfigurable_(true),
|
|
|
|
isUndefined_(false)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(getter.isUndefined() || js_IsCallable(getter));
|
|
|
|
MOZ_ASSERT(setter.isUndefined() || js_IsCallable(setter));
|
|
|
|
}
|
|
|
|
|
2012-05-19 15:03:45 -07:00
|
|
|
inline JSObject *
|
|
|
|
GetInnerObject(JSContext *cx, HandleObject obj)
|
2011-10-04 18:46:03 -07:00
|
|
|
{
|
|
|
|
if (JSObjectOp op = obj->getClass()->ext.innerObject)
|
2012-05-19 15:03:45 -07:00
|
|
|
return op(cx, obj);
|
|
|
|
return obj;
|
2011-10-04 18:46:03 -07:00
|
|
|
}
|
|
|
|
|
2012-05-19 15:03:45 -07:00
|
|
|
inline JSObject *
|
|
|
|
GetOuterObject(JSContext *cx, HandleObject obj)
|
2011-10-04 18:46:03 -07:00
|
|
|
{
|
|
|
|
if (JSObjectOp op = obj->getClass()->ext.outerObject)
|
2012-05-19 15:03:45 -07:00
|
|
|
return op(cx, obj);
|
|
|
|
return obj;
|
2011-10-04 18:46:03 -07:00
|
|
|
}
|
|
|
|
|
2012-05-14 16:53:30 -07:00
|
|
|
#if JS_HAS_XML_SUPPORT
|
2011-10-04 18:46:03 -07:00
|
|
|
/*
|
|
|
|
* Methods to test whether an object or a value is of type "xml" (per typeof).
|
|
|
|
*/
|
|
|
|
|
2012-05-14 16:53:30 -07:00
|
|
|
#define VALUE_IS_XML(v) ((v).isObject() && (v).toObject().isXML())
|
2011-10-04 18:46:03 -07:00
|
|
|
|
|
|
|
static inline bool
|
|
|
|
IsXML(const js::Value &v)
|
|
|
|
{
|
|
|
|
return v.isObject() && v.toObject().isXML();
|
|
|
|
}
|
|
|
|
|
2012-05-14 16:53:30 -07:00
|
|
|
#else
|
|
|
|
|
|
|
|
#define VALUE_IS_XML(v) false
|
|
|
|
|
|
|
|
#endif /* JS_HAS_XML_SUPPORT */
|
|
|
|
|
2011-10-04 18:46:03 -07:00
|
|
|
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;
|
2012-07-30 04:19:09 -07:00
|
|
|
RootedValue value(cx, *vp);
|
|
|
|
if (!vp->toObject().defaultValue(cx, JSTYPE_VOID, &value))
|
|
|
|
return false;
|
|
|
|
*vp = value;
|
|
|
|
return true;
|
2011-10-04 18:46:03 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/* 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;
|
2012-07-30 04:19:09 -07:00
|
|
|
RootedValue value(cx, *vp);
|
|
|
|
if (!vp->toObject().defaultValue(cx, preferredType, &value))
|
|
|
|
return false;
|
|
|
|
*vp = value;
|
|
|
|
return true;
|
2011-10-04 18:46:03 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* 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)
|
2012-04-30 17:10:30 -07:00
|
|
|
: AutoGCRooter(cx, DESCRIPTORS), descriptors(cx), skip(cx, &descriptors)
|
2010-03-28 20:32:20 -07:00
|
|
|
{ }
|
|
|
|
|
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();
|
|
|
|
}
|
|
|
|
|
2012-04-10 11:08:28 -07:00
|
|
|
bool reserve(size_t n) {
|
|
|
|
return descriptors.reserve(n);
|
|
|
|
}
|
|
|
|
|
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;
|
2012-04-30 17:10:30 -07:00
|
|
|
SkipRoot skip;
|
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
|
|
|
{
|
2012-05-03 19:03:13 -07:00
|
|
|
SkipRoot skip;
|
|
|
|
|
|
|
|
AutoPropertyDescriptorRooter *thisDuringConstruction() { return this; }
|
|
|
|
|
2010-05-18 19:21:43 -07:00
|
|
|
public:
|
2012-04-30 17:10:30 -07:00
|
|
|
AutoPropertyDescriptorRooter(JSContext *cx)
|
2012-05-03 19:03:13 -07:00
|
|
|
: AutoGCRooter(cx, DESCRIPTOR), skip(cx, thisDuringConstruction())
|
2012-04-30 17:10:30 -07:00
|
|
|
{
|
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)
|
2012-05-03 19:03:13 -07:00
|
|
|
: AutoGCRooter(cx, DESCRIPTOR), skip(cx, thisDuringConstruction())
|
2010-08-29 11:57:08 -07:00
|
|
|
{
|
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);
|
|
|
|
};
|
|
|
|
|
2012-01-12 19:03:25 -08:00
|
|
|
inline void
|
|
|
|
NewObjectCache::copyCachedToObject(JSObject *dst, JSObject *src)
|
|
|
|
{
|
|
|
|
js_memcpy(dst, src, dst->sizeOfThis());
|
|
|
|
#ifdef JSGC_GENERATIONAL
|
|
|
|
Shape::writeBarrierPost(dst->shape_, &dst->shape_);
|
|
|
|
types::TypeObject::writeBarrierPost(dst->type_, &dst->type_);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
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-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
|
|
|
*/
|
2012-06-13 02:27:45 -07:00
|
|
|
return (!gc::IsBackgroundAllocKind(kind) && !clasp->finalize);
|
2011-04-13 13:43:33 -07:00
|
|
|
}
|
|
|
|
|
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
|
2012-07-04 11:12:16 -07:00
|
|
|
FindProto(JSContext *cx, js::Class *clasp, HandleObject parent, MutableHandleObject proto)
|
2010-12-18 20:44:51 -08:00
|
|
|
{
|
|
|
|
JSProtoKey protoKey = GetClassProtoKey(clasp);
|
|
|
|
if (!js_GetClassPrototype(cx, parent, protoKey, proto, clasp))
|
|
|
|
return false;
|
2012-07-04 11:12:16 -07:00
|
|
|
if (!proto && !js_GetClassPrototype(cx, parent, JSProto_Object, proto))
|
2010-12-18 20:44:51 -08:00
|
|
|
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
|
|
|
{
|
2012-04-13 18:06:40 -07:00
|
|
|
JSObject *scopeChain = (cx->hasfp()) ? cx->fp()->scopeChain() : cx->globalObject;
|
2012-01-02 15:02:05 -08:00
|
|
|
return scopeChain ? &scopeChain->global() : NULL;
|
2010-10-13 11:49:22 -07:00
|
|
|
}
|
|
|
|
|
2011-11-02 13:34:19 -07:00
|
|
|
bool
|
2012-07-04 11:12:16 -07:00
|
|
|
FindClassPrototype(JSContext *cx, HandleObject scope, JSProtoKey protoKey,
|
|
|
|
MutableHandleObject protop, Class *clasp);
|
2011-11-02 13:34:19 -07:00
|
|
|
|
2011-04-12 20:39:16 -07:00
|
|
|
/*
|
|
|
|
* Create a plain object with the specified type. This bypasses getNewType to
|
|
|
|
* avoid losing creation site information for objects made by scripted 'new'.
|
|
|
|
*/
|
2011-11-02 13:34:19 -07:00
|
|
|
JSObject *
|
2012-04-12 09:23:51 -07:00
|
|
|
NewObjectWithType(JSContext *cx, HandleTypeObject type, JSObject *parent, gc::AllocKind kind);
|
2011-11-02 13:34:19 -07:00
|
|
|
|
|
|
|
/* Make an object with pregenerated shape from a NEWOBJECT bytecode. */
|
|
|
|
static inline JSObject *
|
2012-04-12 09:23:51 -07:00
|
|
|
CopyInitializerObject(JSContext *cx, HandleObject baseobj)
|
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());
|
|
|
|
kind = gc::GetBackgroundAllocKind(kind);
|
|
|
|
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
|
|
|
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 *
|
2012-04-12 09:23:51 -07:00
|
|
|
NewReshapedObject(JSContext *cx, HandleTypeObject type, JSObject *parent,
|
2012-07-12 11:36:27 -07:00
|
|
|
gc::AllocKind kind, HandleShape 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
|
2012-02-17 18:43:48 -08:00
|
|
|
PreallocateObjectDynamicSlots(JSContext *cx, Shape *shape, HeapSlot **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())) {
|
2012-02-17 18:43:48 -08:00
|
|
|
*slots = (HeapSlot *) cx->malloc_(count * sizeof(HeapSlot));
|
2011-11-02 13:34:19 -07:00
|
|
|
if (!*slots)
|
|
|
|
return false;
|
2012-02-17 18:43:48 -08:00
|
|
|
Debug_SetSlotRangeToCrashOnTouch(*slots, count);
|
2011-11-02 13:34:19 -07:00
|
|
|
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);
|
|
|
|
|
2012-05-06 13:45:19 -07:00
|
|
|
jsid id = NameToId(cx->runtime->atomState.classAtoms[key]);
|
2012-07-10 18:17:29 -07:00
|
|
|
JS_ASSERT(!global->nativeLookupNoAllocation(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-12-31 06:32:04 -08:00
|
|
|
global->setSlot(key + JSProto_LIMIT * 2, ObjectValue(*ctor));
|
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-12-31 06:32:04 -08:00
|
|
|
global->setSlot(key + JSProto_LIMIT * 2, 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
|
|
|
|
|
|
|
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();
|
2012-02-01 13:36:48 -08:00
|
|
|
case ESClass_RegExp: return obj.isRegExp();
|
2012-03-28 14:43:02 -07:00
|
|
|
case ESClass_ArrayBuffer: return obj.isArrayBuffer();
|
2011-09-20 16:48:50 -07:00
|
|
|
}
|
|
|
|
JS_NOT_REACHED("bad classValue");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2012-02-01 13:36:48 -08:00
|
|
|
inline bool
|
|
|
|
IsObjectWithClass(const Value &v, ESClassValue classValue, JSContext *cx)
|
|
|
|
{
|
|
|
|
if (!v.isObject())
|
|
|
|
return false;
|
|
|
|
return ObjectClassIs(v.toObject(), classValue, cx);
|
|
|
|
}
|
|
|
|
|
2011-08-14 21:12:50 -07:00
|
|
|
static JS_ALWAYS_INLINE bool
|
2012-07-30 04:19:09 -07:00
|
|
|
ValueIsSpecial(JSObject *obj, MutableHandleValue propval, SpecialId *sidp, JSContext *cx)
|
2011-08-14 21:12:50 -07:00
|
|
|
{
|
2012-05-14 16:53:30 -07:00
|
|
|
#if JS_HAS_XML_SUPPORT
|
2012-07-30 04:19:09 -07:00
|
|
|
if (!propval.isObject())
|
2011-08-14 21:12:50 -07:00
|
|
|
return false;
|
|
|
|
|
|
|
|
if (obj->isXML()) {
|
2012-07-30 04:19:09 -07:00
|
|
|
*sidp = SpecialId(propval.toObject());
|
2011-08-14 21:12:50 -07:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2012-07-30 04:19:09 -07:00
|
|
|
JSObject &propobj = propval.toObject();
|
2011-08-14 21:12:50 -07:00
|
|
|
JSAtom *name;
|
|
|
|
if (propobj.isQName() && GetLocalNameFromFunctionQName(&propobj, &name, cx)) {
|
2012-07-30 04:19:09 -07:00
|
|
|
propval.setString(name);
|
2011-08-14 21:12:50 -07:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2011-10-27 11:14:56 -07:00
|
|
|
JSObject *
|
2011-12-31 06:32:04 -08:00
|
|
|
DefineConstructorAndPrototype(JSContext *cx, HandleObject obj, JSProtoKey key, HandleAtom atom,
|
2011-10-27 11:14:56 -07:00
|
|
|
JSObject *protoProto, Class *clasp,
|
2012-02-28 15:11:11 -08:00
|
|
|
Native constructor, unsigned nargs,
|
2011-10-27 11:14:56 -07:00
|
|
|
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 *
|
2011-12-31 06:32:04 -08:00
|
|
|
js_InitClass(JSContext *cx, js::HandleObject obj, JSObject *parent_proto,
|
2012-02-28 15:11:11 -08:00
|
|
|
js::Class *clasp, JSNative constructor, unsigned nargs,
|
2011-10-27 11:14:56 -07:00
|
|
|
JSPropertySpec *ps, JSFunctionSpec *fs,
|
|
|
|
JSPropertySpec *static_ps, JSFunctionSpec *static_fs,
|
|
|
|
JSObject **ctorp = NULL,
|
|
|
|
js::gc::AllocKind ctorKind = JSFunction::FinalizeKind);
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2012-03-20 03:22:05 -07:00
|
|
|
inline void
|
|
|
|
js::DestroyIdArray(FreeOp *fop, JSIdArray *ida)
|
|
|
|
{
|
|
|
|
fop->free_(ida);
|
|
|
|
}
|
|
|
|
|
2009-11-18 12:29:58 -08:00
|
|
|
#endif /* jsobjinlines_h___ */
|