2010-02-03 02:42:07 -08:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
* Menu of -D flags for enabling instrumentation, as a commented-out CFLAGS += setting for convenient testing. * js_FindProperty and js_LookupPropertyWithFlags return indexes into the scope and prototype chains, respectively, to support internal instrumentation, and to pave the way for the return of the property cache (bug 365851).. * jsutil.[ch] JSBasicStats struct and functions for computing mean/sigma/max and auto-scaling histogram. * JS_SCOPE_DEPTH_METER instrumentation for compile- and run-time scope chain length instrumentation: + At compile time, rt->hostenvScopeDepthStats and rt->lexicalScopeDepthStats meter scope chains passed into the compile and evaluate APIs. + At runtime, rt->protoLookupDepthStats and rt->scopeSearchDepthStats track steps along the prototype and scope chains until the sought-after property is found. * JS_ARENAMETER uses JSBasicStats now. * Added rt->liveScopePropsPreSweep to fix the property tree stats code that rotted when property tree sweeping moved to after the finalization phase. * Un-bitrotted some DEBUG_brendan code, turned some off for myself via XXX. * Mac OS X toolchain requires initialized data shared across dynamic library member files, outlaws common data, so initialize extern metering vars. * Old HASHMETER code in jshash.[ch] is now JS_HASHMETER-controlled and based on JSBasicStats. * DEBUG_scopemeters macro renamed JS_DUMP_SCOPE_METERS; uses JSBasicStats now. * Disentangle DEBUG and DUMP_SCOPE_STATS (now JS_DUMP_PROPTREE_STATS) and fix inconsistent thread safety for liveScopeProps (sometimes atomic-incremented, sometimes runtime-locked). * Compiler-modeled maxScopeDepth will propagate via JSScript to runtime for capability-based, interpreter-inlined cache hit qualifier bits, to bypass scope and prototype chain lookup by optimizing for common monomorphic get, set, and call site referencing a prototype property in a well-named object (no shadowing or mutation in 99.9% of the cases).
2008-01-12 16:31:31 -08:00
|
|
|
* vim: set ts=8 sw=4 et tw=78:
|
2007-03-22 10:30:00 -07:00
|
|
|
*
|
|
|
|
* ***** 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 jsobj_h___
|
|
|
|
#define jsobj_h___
|
2011-01-18 14:25:46 -08:00
|
|
|
|
|
|
|
/* Gross special case for Gecko, which defines malloc/calloc/free. */
|
|
|
|
#ifdef mozilla_mozalloc_macro_wrappers_h
|
|
|
|
# define JS_OBJ_UNDEFD_MOZALLOC_WRAPPERS
|
|
|
|
/* The "anti-header" */
|
|
|
|
# include "mozilla/mozalloc_undef_macro_wrappers.h"
|
|
|
|
#endif
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
/*
|
|
|
|
* JS object definitions.
|
|
|
|
*
|
|
|
|
* A JS object consists of a possibly-shared object descriptor containing
|
|
|
|
* ordered property names, called the map; and a dense vector of property
|
|
|
|
* values, called slots. The map/slot pointer pair is GC'ed, while the map
|
|
|
|
* is reference counted and the slot vector is malloc'ed.
|
|
|
|
*/
|
2010-04-14 18:57:30 -07:00
|
|
|
#include "jsapi.h"
|
2010-10-01 16:46:54 -07:00
|
|
|
#include "jshash.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
#include "jspubtd.h"
|
2009-06-05 12:56:45 -07:00
|
|
|
#include "jsprvtd.h"
|
2010-08-29 11:57:08 -07:00
|
|
|
#include "jslock.h"
|
2010-07-14 23:19:36 -07:00
|
|
|
#include "jsvalue.h"
|
2010-06-16 14:13:01 -07:00
|
|
|
#include "jsvector.h"
|
2010-09-24 10:54:39 -07:00
|
|
|
#include "jscell.h"
|
2009-06-05 12:56:45 -07:00
|
|
|
|
2010-07-14 23:19:36 -07:00
|
|
|
namespace js {
|
|
|
|
|
|
|
|
class JSProxyHandler;
|
|
|
|
class AutoPropDescArrayRooter;
|
|
|
|
|
2010-08-30 15:13:32 -07:00
|
|
|
namespace mjit {
|
|
|
|
class Compiler;
|
|
|
|
}
|
|
|
|
|
2010-07-14 23:19:36 -07:00
|
|
|
static inline PropertyOp
|
|
|
|
CastAsPropertyOp(JSObject *object)
|
|
|
|
{
|
|
|
|
return JS_DATA_TO_FUNC_PTR(PropertyOp, object);
|
|
|
|
}
|
|
|
|
|
2011-02-09 11:31:40 -08:00
|
|
|
static inline StrictPropertyOp
|
|
|
|
CastAsStrictPropertyOp(JSObject *object)
|
|
|
|
{
|
|
|
|
return JS_DATA_TO_FUNC_PTR(StrictPropertyOp, object);
|
|
|
|
}
|
|
|
|
|
2010-07-14 23:19:36 -07:00
|
|
|
static inline JSPropertyOp
|
|
|
|
CastAsJSPropertyOp(JSObject *object)
|
|
|
|
{
|
|
|
|
return JS_DATA_TO_FUNC_PTR(JSPropertyOp, object);
|
|
|
|
}
|
|
|
|
|
2011-02-09 11:31:40 -08:00
|
|
|
static inline JSStrictPropertyOp
|
|
|
|
CastAsJSStrictPropertyOp(JSObject *object)
|
|
|
|
{
|
|
|
|
return JS_DATA_TO_FUNC_PTR(JSStrictPropertyOp, object);
|
|
|
|
}
|
|
|
|
|
2010-07-14 23:19:36 -07:00
|
|
|
inline JSObject *
|
|
|
|
CastAsObject(PropertyOp op)
|
|
|
|
{
|
|
|
|
return JS_FUNC_TO_DATA_PTR(JSObject *, op);
|
|
|
|
}
|
|
|
|
|
2011-02-09 11:31:40 -08:00
|
|
|
inline JSObject *
|
|
|
|
CastAsObject(StrictPropertyOp op)
|
|
|
|
{
|
|
|
|
return JS_FUNC_TO_DATA_PTR(JSObject *, op);
|
|
|
|
}
|
|
|
|
|
2010-07-14 23:19:36 -07:00
|
|
|
inline Value
|
|
|
|
CastAsObjectJsval(PropertyOp op)
|
|
|
|
{
|
2010-07-16 11:14:05 -07:00
|
|
|
return ObjectOrNullValue(CastAsObject(op));
|
2010-07-14 23:19:36 -07:00
|
|
|
}
|
|
|
|
|
2011-02-09 11:31:40 -08:00
|
|
|
inline Value
|
|
|
|
CastAsObjectJsval(StrictPropertyOp op)
|
|
|
|
{
|
|
|
|
return ObjectOrNullValue(CastAsObject(op));
|
|
|
|
}
|
|
|
|
|
2010-07-14 23:19:36 -07:00
|
|
|
} /* namespace js */
|
2010-03-28 20:32:20 -07:00
|
|
|
|
2009-06-05 12:56:45 -07:00
|
|
|
/*
|
|
|
|
* A representation of ECMA-262 ed. 5's internal property descriptor data
|
|
|
|
* structure.
|
|
|
|
*/
|
2010-07-14 23:19:36 -07:00
|
|
|
struct PropDesc {
|
|
|
|
friend class js::AutoPropDescArrayRooter;
|
2009-12-30 12:25:27 -08:00
|
|
|
|
2010-07-14 23:19:36 -07:00
|
|
|
PropDesc();
|
2010-05-18 19:21:43 -07:00
|
|
|
|
2010-05-30 11:40:14 -07:00
|
|
|
public:
|
2009-06-05 12:56:45 -07:00
|
|
|
/* 8.10.5 ToPropertyDescriptor(Obj) */
|
2010-07-14 23:19:36 -07:00
|
|
|
bool initialize(JSContext* cx, jsid id, const js::Value &v);
|
2009-06-05 12:56:45 -07:00
|
|
|
|
|
|
|
/* 8.10.1 IsAccessorDescriptor(desc) */
|
|
|
|
bool isAccessorDescriptor() const {
|
|
|
|
return hasGet || hasSet;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* 8.10.2 IsDataDescriptor(desc) */
|
|
|
|
bool isDataDescriptor() const {
|
|
|
|
return hasValue || hasWritable;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* 8.10.3 IsGenericDescriptor(desc) */
|
|
|
|
bool isGenericDescriptor() const {
|
|
|
|
return !isAccessorDescriptor() && !isDataDescriptor();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool configurable() const {
|
|
|
|
return (attrs & JSPROP_PERMANENT) == 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool enumerable() const {
|
|
|
|
return (attrs & JSPROP_ENUMERATE) != 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool writable() const {
|
|
|
|
return (attrs & JSPROP_READONLY) == 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
JSObject* getterObject() const {
|
2010-07-14 23:19:36 -07:00
|
|
|
return get.isUndefined() ? NULL : &get.toObject();
|
2009-06-05 12:56:45 -07:00
|
|
|
}
|
|
|
|
JSObject* setterObject() const {
|
2010-07-14 23:19:36 -07:00
|
|
|
return set.isUndefined() ? NULL : &set.toObject();
|
2009-06-05 12:56:45 -07:00
|
|
|
}
|
|
|
|
|
2010-07-14 23:19:36 -07:00
|
|
|
const js::Value &getterValue() const {
|
2009-06-05 12:56:45 -07:00
|
|
|
return get;
|
|
|
|
}
|
2010-07-14 23:19:36 -07:00
|
|
|
const js::Value &setterValue() const {
|
2009-06-05 12:56:45 -07:00
|
|
|
return set;
|
|
|
|
}
|
|
|
|
|
2010-07-14 23:19:36 -07:00
|
|
|
js::PropertyOp getter() const {
|
2010-04-30 16:03:37 -07:00
|
|
|
return js::CastAsPropertyOp(getterObject());
|
2009-06-05 12:56:45 -07:00
|
|
|
}
|
2011-02-09 11:31:40 -08:00
|
|
|
js::StrictPropertyOp setter() const {
|
|
|
|
return js::CastAsStrictPropertyOp(setterObject());
|
2009-06-05 12:56:45 -07:00
|
|
|
}
|
|
|
|
|
2010-07-14 23:19:36 -07:00
|
|
|
js::Value pd;
|
2009-06-05 12:56:45 -07:00
|
|
|
jsid id;
|
2010-07-14 23:19:36 -07:00
|
|
|
js::Value value, get, set;
|
2009-06-05 12:56:45 -07:00
|
|
|
|
|
|
|
/* Property descriptor boolean fields. */
|
2009-12-29 11:13:49 -08:00
|
|
|
uint8 attrs;
|
2009-06-05 12:56:45 -07:00
|
|
|
|
|
|
|
/* Bits indicating which values are set. */
|
|
|
|
bool hasGet : 1;
|
|
|
|
bool hasSet : 1;
|
|
|
|
bool hasValue : 1;
|
|
|
|
bool hasWritable : 1;
|
|
|
|
bool hasEnumerable : 1;
|
|
|
|
bool hasConfigurable : 1;
|
|
|
|
};
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-06-16 14:13:01 -07:00
|
|
|
namespace js {
|
2010-07-07 00:53:50 -07:00
|
|
|
|
|
|
|
typedef Vector<PropDesc, 1> PropDescArray;
|
|
|
|
|
|
|
|
} /* namespace js */
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
struct JSObjectMap {
|
2010-08-29 11:57:08 -07:00
|
|
|
uint32 shape; /* shape identifier */
|
2010-09-03 11:05:43 -07:00
|
|
|
uint32 slotSpan; /* one more than maximum live slot number */
|
2009-09-14 17:29:46 -07:00
|
|
|
|
2010-11-04 15:53:50 -07:00
|
|
|
static JS_FRIEND_DATA(const JSObjectMap) sharedNonNative;
|
|
|
|
|
2010-12-29 17:46:14 -08:00
|
|
|
explicit JSObjectMap(uint32 shape) : shape(shape), slotSpan(0) {}
|
|
|
|
JSObjectMap(uint32 shape, uint32 slotSpan) : shape(shape), slotSpan(slotSpan) {}
|
2009-09-14 17:29:46 -07:00
|
|
|
|
2010-06-12 19:00:30 -07:00
|
|
|
enum { INVALID_SHAPE = 0x8fffffff, SHAPELESS = 0xffffffff };
|
2010-03-04 20:44:09 -08:00
|
|
|
|
2010-06-12 09:29:04 -07:00
|
|
|
bool isNative() const { return this != &sharedNonNative; }
|
|
|
|
|
|
|
|
private:
|
2010-03-04 20:44:09 -08:00
|
|
|
/* No copy or assignment semantics. */
|
|
|
|
JSObjectMap(JSObjectMap &);
|
|
|
|
void operator=(JSObjectMap &);
|
2007-03-22 10:30:00 -07:00
|
|
|
};
|
|
|
|
|
2010-06-12 09:29:04 -07:00
|
|
|
/*
|
|
|
|
* Unlike js_DefineNativeProperty, propp must be non-null. On success, and if
|
2010-10-22 17:04:22 -07:00
|
|
|
* id was found, return true with *objp non-null and with a property of *objp
|
|
|
|
* stored in *propp. If successful but id was not found, return true with both
|
|
|
|
* *objp and *propp null.
|
2010-06-12 09:29:04 -07:00
|
|
|
*/
|
|
|
|
extern JS_FRIEND_API(JSBool)
|
|
|
|
js_LookupProperty(JSContext *cx, JSObject *obj, jsid id, JSObject **objp,
|
|
|
|
JSProperty **propp);
|
|
|
|
|
|
|
|
extern JSBool
|
|
|
|
js_DefineProperty(JSContext *cx, JSObject *obj, jsid id, const js::Value *value,
|
2011-02-09 11:31:40 -08:00
|
|
|
js::PropertyOp getter, js::StrictPropertyOp setter, uintN attrs);
|
2010-06-12 09:29:04 -07:00
|
|
|
|
|
|
|
extern JSBool
|
2010-10-29 10:42:35 -07:00
|
|
|
js_GetProperty(JSContext *cx, JSObject *obj, JSObject *receiver, jsid id, js::Value *vp);
|
|
|
|
|
|
|
|
inline JSBool
|
|
|
|
js_GetProperty(JSContext *cx, JSObject *obj, jsid id, js::Value *vp)
|
|
|
|
{
|
|
|
|
return js_GetProperty(cx, obj, obj, id, vp);
|
|
|
|
}
|
2010-06-12 09:29:04 -07:00
|
|
|
|
2010-10-19 09:00:51 -07:00
|
|
|
namespace js {
|
|
|
|
|
|
|
|
extern JSBool
|
2010-11-08 14:35:06 -08:00
|
|
|
GetPropertyDefault(JSContext *cx, JSObject *obj, jsid id, const Value &def, Value *vp);
|
2010-10-19 09:00:51 -07:00
|
|
|
|
|
|
|
} /* namespace js */
|
|
|
|
|
2010-06-12 09:29:04 -07:00
|
|
|
extern JSBool
|
2010-09-15 13:43:55 -07:00
|
|
|
js_SetProperty(JSContext *cx, JSObject *obj, jsid id, js::Value *vp, JSBool strict);
|
2010-06-12 09:29:04 -07:00
|
|
|
|
|
|
|
extern JSBool
|
|
|
|
js_GetAttributes(JSContext *cx, JSObject *obj, jsid id, uintN *attrsp);
|
2010-05-07 17:52:52 -07:00
|
|
|
|
2010-06-12 09:29:04 -07:00
|
|
|
extern JSBool
|
|
|
|
js_SetAttributes(JSContext *cx, JSObject *obj, jsid id, uintN *attrsp);
|
|
|
|
|
|
|
|
extern JSBool
|
2010-09-15 13:43:55 -07:00
|
|
|
js_DeleteProperty(JSContext *cx, JSObject *obj, jsid id, js::Value *rval, JSBool strict);
|
2010-06-12 09:29:04 -07:00
|
|
|
|
|
|
|
extern JS_FRIEND_API(JSBool)
|
|
|
|
js_Enumerate(JSContext *cx, JSObject *obj, JSIterateOp enum_op,
|
|
|
|
js::Value *statep, jsid *idp);
|
|
|
|
|
|
|
|
extern JSType
|
|
|
|
js_TypeOf(JSContext *cx, JSObject *obj);
|
|
|
|
|
2010-10-10 15:37:22 -07:00
|
|
|
namespace js {
|
|
|
|
|
2010-05-07 17:52:52 -07:00
|
|
|
struct NativeIterator;
|
2009-08-04 14:06:55 -07:00
|
|
|
|
2010-10-10 15:37:22 -07:00
|
|
|
}
|
|
|
|
|
2010-07-27 11:48:08 -07:00
|
|
|
struct JSFunction;
|
2010-07-23 14:41:56 -07:00
|
|
|
|
2010-10-18 12:55:56 -07:00
|
|
|
namespace nanojit {
|
|
|
|
class ValidateWriter;
|
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
/*
|
2009-04-05 21:17:22 -07:00
|
|
|
* JSObject struct, with members sized to fit in 32 bytes on 32-bit targets,
|
|
|
|
* 64 bytes on 64-bit systems. The JSFunction struct is an extension of this
|
|
|
|
* struct allocated from a larger GC size-class.
|
|
|
|
*
|
2010-08-29 11:57:08 -07:00
|
|
|
* The clasp member stores the js::Class pointer for this object. We do *not*
|
|
|
|
* synchronize updates of clasp or flags -- API clients must take care.
|
|
|
|
*
|
2010-07-29 10:11:27 -07:00
|
|
|
* An object is a delegate if it is on another object's prototype (the proto
|
|
|
|
* field) or scope chain (the parent field), and therefore the delegate might
|
|
|
|
* be asked implicitly to get or set a property on behalf of another object.
|
|
|
|
* Delegates may be accessed directly too, as may any object, but only those
|
|
|
|
* objects linked after the head of any prototype or scope chain are flagged
|
|
|
|
* as delegates. This definition helps to optimize shape-based property cache
|
|
|
|
* invalidation (see Purge{Scope,Proto}Chain in jsobj.cpp).
|
2009-04-05 21:17:22 -07:00
|
|
|
*
|
|
|
|
* The meaning of the system object bit is defined by the API client. It is
|
|
|
|
* set in JS_NewSystemObject and is queried by JS_IsSystemObject (jsdbgapi.h),
|
|
|
|
* but it has no intrinsic meaning to SpiderMonkey. Further, JSFILENAME_SYSTEM
|
|
|
|
* and JS_FlagScriptFilenamePrefix (also exported via jsdbgapi.h) are intended
|
|
|
|
* to be complementary to this bit, but it is up to the API client to implement
|
|
|
|
* any such association.
|
|
|
|
*
|
2010-08-29 11:57:08 -07:00
|
|
|
* Both these flag bits are initially zero; they may be set or queried using
|
|
|
|
* the (is|set)(Delegate|System) inline methods.
|
2009-04-05 21:17:22 -07:00
|
|
|
*
|
2010-10-13 11:49:22 -07:00
|
|
|
* The slots member is a pointer to the slot vector for the object.
|
|
|
|
* This can be either a fixed array allocated immediately after the object,
|
|
|
|
* or a dynamically allocated array. A dynamic array can be tested for with
|
|
|
|
* hasSlotsArray(). In all cases, capacity gives the number of usable slots.
|
|
|
|
* Two objects with the same shape have the same number of fixed slots,
|
|
|
|
* and either both have or neither have dynamically allocated slot arrays.
|
2010-10-18 12:55:56 -07:00
|
|
|
*
|
|
|
|
* If you change this struct, you'll probably need to change the AccSet values
|
|
|
|
* in jsbuiltins.h.
|
2007-03-22 10:30:00 -07:00
|
|
|
*/
|
2010-09-24 10:54:39 -07:00
|
|
|
struct JSObject : js::gc::Cell {
|
2010-04-05 18:32:16 -07:00
|
|
|
/*
|
|
|
|
* TraceRecorder must be a friend because it generates code that
|
|
|
|
* manipulates JSObjects, which requires peeking under any encapsulation.
|
2010-10-18 12:55:56 -07:00
|
|
|
* ValidateWriter must be a friend because it works in tandem with
|
|
|
|
* TraceRecorder.
|
2010-04-05 18:32:16 -07:00
|
|
|
*/
|
|
|
|
friend class js::TraceRecorder;
|
2010-10-18 12:55:56 -07:00
|
|
|
friend class nanojit::ValidateWriter;
|
2010-12-30 11:25:03 -08:00
|
|
|
friend class GetPropCompiler;
|
2010-04-05 18:32:16 -07:00
|
|
|
|
2010-08-29 11:57:08 -07:00
|
|
|
/*
|
|
|
|
* Private pointer to the last added property and methods to manipulate the
|
|
|
|
* list it links among properties in this scope. The {remove,insert} pair
|
|
|
|
* for DictionaryProperties assert that the scope is in dictionary mode and
|
|
|
|
* any reachable properties are flagged as dictionary properties.
|
|
|
|
*
|
2011-02-04 10:59:07 -08:00
|
|
|
* For native objects, this field is always a Shape. For non-native objects,
|
|
|
|
* it points to the singleton sharedNonNative JSObjectMap, whose shape field
|
|
|
|
* is SHAPELESS.
|
|
|
|
*
|
2010-08-29 11:57:08 -07:00
|
|
|
* NB: these private methods do *not* update this scope's shape to track
|
|
|
|
* lastProp->shape after they finish updating the linked list in the case
|
|
|
|
* where lastProp is updated. It is up to calling code in jsscope.cpp to
|
|
|
|
* call updateShape(cx) after updating lastProp.
|
|
|
|
*/
|
|
|
|
union {
|
|
|
|
js::Shape *lastProp;
|
|
|
|
JSObjectMap *map;
|
|
|
|
};
|
|
|
|
|
|
|
|
js::Class *clasp;
|
|
|
|
|
|
|
|
private:
|
|
|
|
inline void setLastProperty(const js::Shape *shape);
|
|
|
|
inline void removeLastProperty();
|
|
|
|
|
2010-09-02 18:46:11 -07:00
|
|
|
#ifdef DEBUG
|
|
|
|
void checkShapeConsistency();
|
|
|
|
#endif
|
|
|
|
|
2010-08-29 11:57:08 -07:00
|
|
|
public:
|
|
|
|
inline const js::Shape *lastProperty() const;
|
|
|
|
|
|
|
|
inline js::Shape **nativeSearch(jsid id, bool adding = false);
|
|
|
|
inline const js::Shape *nativeLookup(jsid id);
|
|
|
|
|
|
|
|
inline bool nativeContains(jsid id);
|
|
|
|
inline bool nativeContains(const js::Shape &shape);
|
|
|
|
|
|
|
|
enum {
|
2010-11-22 17:58:53 -08:00
|
|
|
DELEGATE = 0x01,
|
|
|
|
SYSTEM = 0x02,
|
|
|
|
NOT_EXTENSIBLE = 0x04,
|
|
|
|
BRANDED = 0x08,
|
|
|
|
GENERIC = 0x10,
|
|
|
|
METHOD_BARRIER = 0x20,
|
|
|
|
INDEXED = 0x40,
|
|
|
|
OWN_SHAPE = 0x80,
|
|
|
|
BOUND_FUNCTION = 0x100,
|
|
|
|
HAS_EQUALITY = 0x200,
|
|
|
|
METHOD_THRASH_COUNT_MASK = 0xc00,
|
|
|
|
METHOD_THRASH_COUNT_SHIFT = 10,
|
|
|
|
METHOD_THRASH_COUNT_MAX = METHOD_THRASH_COUNT_MASK >> METHOD_THRASH_COUNT_SHIFT
|
2010-08-29 11:57:08 -07:00
|
|
|
};
|
|
|
|
|
2010-09-02 14:50:44 -07:00
|
|
|
/*
|
|
|
|
* Impose a sane upper bound, originally checked only for dense arrays, on
|
|
|
|
* number of slots in an object.
|
|
|
|
*/
|
2010-08-29 11:57:08 -07:00
|
|
|
enum {
|
2010-09-02 14:50:44 -07:00
|
|
|
NSLOTS_BITS = 29,
|
|
|
|
NSLOTS_LIMIT = JS_BIT(NSLOTS_BITS)
|
2010-08-29 11:57:08 -07:00
|
|
|
};
|
|
|
|
|
2010-09-02 14:50:44 -07:00
|
|
|
uint32 flags; /* flags */
|
2010-08-29 11:57:08 -07:00
|
|
|
uint32 objShape; /* copy of lastProp->shape, or override if different */
|
|
|
|
|
2010-10-13 11:49:22 -07:00
|
|
|
/* If prototype, lazily filled array of empty shapes for each object size. */
|
|
|
|
js::EmptyShape **emptyShapes;
|
|
|
|
|
|
|
|
JSObject *proto; /* object's prototype */
|
|
|
|
JSObject *parent; /* object's parent */
|
|
|
|
void *privateData; /* private data */
|
|
|
|
jsuword capacity; /* capacity of slots */
|
|
|
|
js::Value *slots; /* dynamically allocated slots,
|
|
|
|
or pointer to fixedSlots() */
|
|
|
|
|
2010-08-29 11:57:08 -07:00
|
|
|
/*
|
2010-09-03 11:05:43 -07:00
|
|
|
* Return an immutable, shareable, empty shape with the same clasp as this
|
|
|
|
* and the same slotSpan as this had when empty.
|
2010-08-29 11:57:08 -07:00
|
|
|
*
|
|
|
|
* If |this| is the scope of an object |proto|, the resulting scope can be
|
|
|
|
* used as the scope of a new object whose prototype is |proto|.
|
|
|
|
*/
|
|
|
|
inline bool canProvideEmptyShape(js::Class *clasp);
|
2010-10-13 11:49:22 -07:00
|
|
|
inline js::EmptyShape *getEmptyShape(JSContext *cx, js::Class *aclasp,
|
|
|
|
/* gc::FinalizeKind */ unsigned kind);
|
2010-02-03 02:42:07 -08:00
|
|
|
|
2010-08-29 11:57:08 -07:00
|
|
|
bool isNative() const { return map->isNative(); }
|
2010-07-14 23:19:36 -07:00
|
|
|
|
2010-08-29 11:57:08 -07:00
|
|
|
js::Class *getClass() const { return clasp; }
|
|
|
|
JSClass *getJSClass() const { return Jsvalify(clasp); }
|
2009-08-04 14:06:55 -07:00
|
|
|
|
2010-07-14 23:19:36 -07:00
|
|
|
bool hasClass(const js::Class *c) const {
|
|
|
|
return c == clasp;
|
2010-01-15 11:32:14 -08:00
|
|
|
}
|
|
|
|
|
2010-06-12 09:29:04 -07:00
|
|
|
const js::ObjectOps *getOps() const {
|
|
|
|
return &getClass()->ops;
|
|
|
|
}
|
|
|
|
|
2010-08-29 11:57:08 -07:00
|
|
|
inline void trace(JSTracer *trc);
|
2010-04-08 11:22:04 -07:00
|
|
|
|
2010-08-29 11:57:08 -07:00
|
|
|
uint32 shape() const {
|
|
|
|
JS_ASSERT(objShape != JSObjectMap::INVALID_SHAPE);
|
|
|
|
return objShape;
|
2009-08-27 22:53:26 -07:00
|
|
|
}
|
|
|
|
|
2010-08-29 11:57:08 -07:00
|
|
|
bool isDelegate() const { return !!(flags & DELEGATE); }
|
|
|
|
void setDelegate() { flags |= DELEGATE; }
|
2010-11-10 10:59:02 -08:00
|
|
|
void clearDelegate() { flags &= ~DELEGATE; }
|
2009-08-27 22:53:26 -07:00
|
|
|
|
2010-09-16 19:31:11 -07:00
|
|
|
bool isBoundFunction() const { return !!(flags & BOUND_FUNCTION); }
|
|
|
|
|
2009-08-27 22:53:26 -07:00
|
|
|
static void setDelegateNullSafe(JSObject *obj) {
|
|
|
|
if (obj)
|
|
|
|
obj->setDelegate();
|
|
|
|
}
|
|
|
|
|
2010-08-29 11:57:08 -07:00
|
|
|
bool isSystem() const { return !!(flags & SYSTEM); }
|
|
|
|
void setSystem() { flags |= SYSTEM; }
|
|
|
|
|
|
|
|
/*
|
|
|
|
* A branded object contains plain old methods (function-valued properties
|
|
|
|
* without magic getters and setters), and its shape evolves whenever a
|
|
|
|
* function value changes.
|
|
|
|
*/
|
|
|
|
bool branded() { return !!(flags & BRANDED); }
|
|
|
|
|
2010-11-22 17:58:53 -08:00
|
|
|
/*
|
|
|
|
* NB: these return false on shape overflow but do not report any error.
|
|
|
|
* Callers who depend on shape guarantees should therefore bail off trace,
|
|
|
|
* e.g., on false returns.
|
|
|
|
*/
|
2010-11-09 11:40:56 -08:00
|
|
|
bool brand(JSContext *cx);
|
2010-08-29 11:57:08 -07:00
|
|
|
bool unbrand(JSContext *cx);
|
|
|
|
|
|
|
|
bool generic() { return !!(flags & GENERIC); }
|
|
|
|
void setGeneric() { flags |= GENERIC; }
|
|
|
|
|
2010-11-22 17:58:53 -08:00
|
|
|
uintN getMethodThrashCount() const {
|
|
|
|
return (flags & METHOD_THRASH_COUNT_MASK) >> METHOD_THRASH_COUNT_SHIFT;
|
|
|
|
}
|
|
|
|
|
|
|
|
void setMethodThrashCount(uintN count) {
|
|
|
|
JS_ASSERT(count <= METHOD_THRASH_COUNT_MAX);
|
|
|
|
flags = (flags & ~METHOD_THRASH_COUNT_MASK) | (count << METHOD_THRASH_COUNT_SHIFT);
|
|
|
|
}
|
|
|
|
|
2010-11-12 10:40:12 -08:00
|
|
|
bool hasSpecialEquality() const { return !!(flags & HAS_EQUALITY); }
|
|
|
|
void assertSpecialEqualitySynced() const {
|
|
|
|
JS_ASSERT(!!clasp->ext.equality == hasSpecialEquality());
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Sets an object's HAS_EQUALITY flag based on its clasp. */
|
|
|
|
inline void syncSpecialEquality();
|
|
|
|
|
2010-08-29 11:57:08 -07:00
|
|
|
private:
|
|
|
|
void generateOwnShape(JSContext *cx);
|
|
|
|
|
|
|
|
void setOwnShape(uint32 s) { flags |= OWN_SHAPE; objShape = s; }
|
|
|
|
void clearOwnShape() { flags &= ~OWN_SHAPE; objShape = map->shape; }
|
|
|
|
|
|
|
|
public:
|
|
|
|
inline bool nativeEmpty() const;
|
|
|
|
|
|
|
|
bool hasOwnShape() const { return !!(flags & OWN_SHAPE); }
|
|
|
|
|
2011-01-31 16:48:26 -08:00
|
|
|
void setMap(const JSObjectMap *amap) {
|
2010-08-29 11:57:08 -07:00
|
|
|
JS_ASSERT(!hasOwnShape());
|
2011-01-31 16:48:26 -08:00
|
|
|
map = const_cast<JSObjectMap *>(amap);
|
2010-08-29 11:57:08 -07:00
|
|
|
objShape = map->shape;
|
2009-08-27 22:53:26 -07:00
|
|
|
}
|
|
|
|
|
2010-08-29 11:57:08 -07:00
|
|
|
void setSharedNonNativeMap() {
|
2011-01-31 16:48:26 -08:00
|
|
|
setMap(&JSObjectMap::sharedNonNative);
|
2010-03-15 16:13:49 -07:00
|
|
|
}
|
2009-08-27 22:53:26 -07:00
|
|
|
|
2010-08-29 11:57:08 -07:00
|
|
|
void deletingShapeChange(JSContext *cx, const js::Shape &shape);
|
2011-01-17 09:30:08 -08:00
|
|
|
const js::Shape *methodShapeChange(JSContext *cx, const js::Shape &shape);
|
2010-08-29 11:57:08 -07:00
|
|
|
bool methodShapeChange(JSContext *cx, uint32 slot);
|
|
|
|
void protoShapeChange(JSContext *cx);
|
|
|
|
void shadowingShapeChange(JSContext *cx, const js::Shape &shape);
|
|
|
|
bool globalObjectOwnShapeChange(JSContext *cx);
|
2011-02-08 13:45:13 -08:00
|
|
|
void watchpointOwnShapeChange(JSContext *cx) { generateOwnShape(cx); }
|
2010-08-29 11:57:08 -07:00
|
|
|
|
2010-09-21 11:35:29 -07:00
|
|
|
void extensibleShapeChange(JSContext *cx) {
|
|
|
|
/* This will do for now. */
|
|
|
|
generateOwnShape(cx);
|
|
|
|
}
|
|
|
|
|
2010-08-29 11:57:08 -07:00
|
|
|
/*
|
|
|
|
* A scope has a method barrier when some compiler-created "null closure"
|
|
|
|
* function objects (functions that do not use lexical bindings above their
|
|
|
|
* scope, only free variable names) that have a correct JSSLOT_PARENT value
|
|
|
|
* thanks to the COMPILE_N_GO optimization are stored as newly added direct
|
|
|
|
* property values of the scope's object.
|
|
|
|
*
|
|
|
|
* The de-facto standard JS language requires each evaluation of such a
|
|
|
|
* closure to result in a unique (according to === and observable effects)
|
|
|
|
* function object. ES3 tried to allow implementations to "join" such
|
|
|
|
* objects to a single compiler-created object, but this makes an overt
|
|
|
|
* mutation hazard, also an "identity hazard" against interoperation among
|
|
|
|
* implementations that join and do not join.
|
|
|
|
*
|
|
|
|
* To stay compatible with the de-facto standard, we store the compiler-
|
|
|
|
* created function object as the method value and set the METHOD_BARRIER
|
|
|
|
* flag.
|
|
|
|
*
|
|
|
|
* The method value is part of the method property tree node's identity, so
|
|
|
|
* it effectively brands the scope with a predictable shape corresponding
|
|
|
|
* to the method value, but without the overhead of setting the BRANDED
|
|
|
|
* flag, which requires assigning a new shape peculiar to each branded
|
|
|
|
* scope. Instead the shape is shared via the property tree among all the
|
|
|
|
* scopes referencing the method property tree node.
|
|
|
|
*
|
|
|
|
* Then when reading from a scope for which scope->hasMethodBarrier() is
|
|
|
|
* true, we count on the scope's qualified/guarded shape being unique and
|
|
|
|
* add a read barrier that clones the compiler-created function object on
|
|
|
|
* demand, reshaping the scope.
|
|
|
|
*
|
|
|
|
* This read barrier is bypassed when evaluating the callee sub-expression
|
|
|
|
* of a call expression (see the JOF_CALLOP opcodes in jsopcode.tbl), since
|
|
|
|
* such ops do not present an identity or mutation hazard. The compiler
|
|
|
|
* performs this optimization only for null closures that do not use their
|
|
|
|
* own name or equivalent built-in references (arguments.callee).
|
|
|
|
*
|
|
|
|
* The BRANDED write barrier, JSObject::methodWriteBarrer, must check for
|
|
|
|
* METHOD_BARRIER too, and regenerate this scope's shape if the method's
|
|
|
|
* value is in fact changing.
|
|
|
|
*/
|
|
|
|
bool hasMethodBarrier() { return !!(flags & METHOD_BARRIER); }
|
|
|
|
void setMethodBarrier() { flags |= METHOD_BARRIER; }
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Test whether this object may be branded due to method calls, which means
|
|
|
|
* any assignment to a function-valued property must regenerate shape; else
|
|
|
|
* test whether this object has method properties, which require a method
|
|
|
|
* write barrier.
|
|
|
|
*/
|
|
|
|
bool brandedOrHasMethodBarrier() { return !!(flags & (BRANDED | METHOD_BARRIER)); }
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Read barrier to clone a joined function object stored as a method.
|
|
|
|
* Defined in jsobjinlines.h, but not declared inline per standard style in
|
|
|
|
* order to avoid gcc warnings.
|
|
|
|
*/
|
2011-02-15 12:11:04 -08:00
|
|
|
const js::Shape *methodReadBarrier(JSContext *cx, const js::Shape &shape, js::Value *vp);
|
2010-08-29 11:57:08 -07:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Write barrier to check for a change of method value. Defined inline in
|
|
|
|
* jsobjinlines.h after methodReadBarrier. The slot flavor is required by
|
|
|
|
* JSOP_*GVAR, which deals in slots not shapes, while not deoptimizing to
|
|
|
|
* map slot to shape unless JSObject::flags show that this is necessary.
|
2011-01-17 09:30:08 -08:00
|
|
|
* The methodShapeChange overload (above) parallels this.
|
2010-08-29 11:57:08 -07:00
|
|
|
*/
|
2011-01-17 09:30:08 -08:00
|
|
|
const js::Shape *methodWriteBarrier(JSContext *cx, const js::Shape &shape, const js::Value &v);
|
2010-08-29 11:57:08 -07:00
|
|
|
bool methodWriteBarrier(JSContext *cx, uint32 slot, const js::Value &v);
|
|
|
|
|
|
|
|
bool isIndexed() const { return !!(flags & INDEXED); }
|
|
|
|
void setIndexed() { flags |= INDEXED; }
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Return true if this object is a native one that has been converted from
|
|
|
|
* shared-immutable prototype-rooted shape storage to dictionary-shapes in
|
|
|
|
* a doubly-linked list.
|
|
|
|
*/
|
|
|
|
inline bool inDictionaryMode() const;
|
|
|
|
|
|
|
|
inline uint32 propertyCount() const;
|
|
|
|
|
|
|
|
inline bool hasPropertyTable() const;
|
|
|
|
|
2010-11-15 17:21:25 -08:00
|
|
|
/* gc::FinalizeKind */ unsigned finalizeKind() const;
|
|
|
|
|
2010-10-13 11:49:22 -07:00
|
|
|
uint32 numSlots() const { return capacity; }
|
2010-03-30 14:42:48 -07:00
|
|
|
|
2010-09-01 14:09:54 -07:00
|
|
|
size_t slotsAndStructSize(uint32 nslots) const;
|
|
|
|
size_t slotsAndStructSize() const { return slotsAndStructSize(numSlots()); }
|
|
|
|
|
2010-10-13 11:49:22 -07:00
|
|
|
inline js::Value* fixedSlots() const;
|
|
|
|
inline size_t numFixedSlots() const;
|
2010-09-20 12:05:21 -07:00
|
|
|
|
2010-10-13 11:49:22 -07:00
|
|
|
static inline size_t getFixedSlotOffset(size_t slot);
|
2010-05-04 20:28:38 -07:00
|
|
|
|
|
|
|
public:
|
2010-10-13 11:49:22 -07:00
|
|
|
/* Minimum size for dynamically allocated slots. */
|
|
|
|
static const uint32 SLOT_CAPACITY_MIN = 8;
|
|
|
|
|
2010-05-04 20:28:38 -07:00
|
|
|
bool allocSlots(JSContext *cx, size_t nslots);
|
|
|
|
bool growSlots(JSContext *cx, size_t nslots);
|
|
|
|
void shrinkSlots(JSContext *cx, size_t nslots);
|
|
|
|
|
2010-10-13 11:49:22 -07:00
|
|
|
bool ensureSlots(JSContext *cx, size_t nslots) {
|
|
|
|
if (numSlots() < nslots)
|
|
|
|
return growSlots(cx, nslots);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2010-08-29 11:57:08 -07:00
|
|
|
/*
|
|
|
|
* Ensure that the object has at least JSCLASS_RESERVED_SLOTS(clasp) +
|
|
|
|
* nreserved slots.
|
|
|
|
*
|
|
|
|
* This method may be called only for native objects freshly created using
|
|
|
|
* NewObject or one of its variant where the new object will both (a) never
|
|
|
|
* escape to script and (b) never be extended with ad-hoc properties that
|
|
|
|
* would try to allocate higher slots without the fresh object first having
|
|
|
|
* its map set to a shape path that maps those slots.
|
|
|
|
*
|
|
|
|
* Block objects satisfy (a) and (b), as there is no evil eval-based way to
|
|
|
|
* add ad-hoc properties to a Block instance. Call objects satisfy (a) and
|
|
|
|
* (b) as well, because the compiler-created Shape path that covers args,
|
|
|
|
* vars, and upvars, stored in their callee function in u.i.names, becomes
|
|
|
|
* their initial map.
|
|
|
|
*/
|
|
|
|
bool ensureInstanceReservedSlots(JSContext *cx, size_t nreserved);
|
|
|
|
|
2010-10-13 11:49:22 -07:00
|
|
|
/*
|
|
|
|
* Get a direct pointer to the object's slots.
|
|
|
|
* This can be reallocated if the object is modified, watch out!
|
|
|
|
*/
|
|
|
|
js::Value *getSlots() const {
|
|
|
|
return slots;
|
|
|
|
}
|
|
|
|
|
2010-08-29 11:57:08 -07:00
|
|
|
/*
|
|
|
|
* NB: ensureClassReservedSlotsForEmptyObject asserts that nativeEmpty()
|
|
|
|
* Use ensureClassReservedSlots for any object, either empty or already
|
|
|
|
* extended with properties.
|
|
|
|
*/
|
|
|
|
bool ensureClassReservedSlotsForEmptyObject(JSContext *cx);
|
|
|
|
|
|
|
|
inline bool ensureClassReservedSlots(JSContext *cx);
|
|
|
|
|
2010-09-03 11:05:43 -07:00
|
|
|
uint32 slotSpan() const { return map->slotSpan; }
|
2010-09-02 14:50:44 -07:00
|
|
|
|
2010-09-03 11:05:43 -07:00
|
|
|
bool containsSlot(uint32 slot) const { return slot < slotSpan(); }
|
2010-08-29 11:57:08 -07:00
|
|
|
|
2010-07-14 23:19:36 -07:00
|
|
|
js::Value& getSlotRef(uintN slot) {
|
2010-10-13 11:49:22 -07:00
|
|
|
JS_ASSERT(slot < capacity);
|
|
|
|
return slots[slot];
|
2010-03-30 14:42:48 -07:00
|
|
|
}
|
|
|
|
|
2010-10-22 17:04:22 -07:00
|
|
|
js::Value &nativeGetSlotRef(uintN slot) {
|
|
|
|
JS_ASSERT(isNative());
|
|
|
|
JS_ASSERT(containsSlot(slot));
|
|
|
|
return getSlotRef(slot);
|
|
|
|
}
|
|
|
|
|
2010-07-14 23:19:36 -07:00
|
|
|
const js::Value &getSlot(uintN slot) const {
|
2010-10-13 11:49:22 -07:00
|
|
|
JS_ASSERT(slot < capacity);
|
|
|
|
return slots[slot];
|
2010-03-30 14:42:48 -07:00
|
|
|
}
|
|
|
|
|
2010-10-22 17:04:22 -07:00
|
|
|
const js::Value &nativeGetSlot(uintN slot) const {
|
|
|
|
JS_ASSERT(isNative());
|
|
|
|
JS_ASSERT(containsSlot(slot));
|
|
|
|
return getSlot(slot);
|
|
|
|
}
|
|
|
|
|
2010-07-14 23:19:36 -07:00
|
|
|
void setSlot(uintN slot, const js::Value &value) {
|
2010-10-13 11:49:22 -07:00
|
|
|
JS_ASSERT(slot < capacity);
|
|
|
|
slots[slot] = value;
|
2010-03-30 14:42:48 -07:00
|
|
|
}
|
|
|
|
|
2010-10-22 17:04:22 -07:00
|
|
|
void nativeSetSlot(uintN slot, const js::Value &value) {
|
|
|
|
JS_ASSERT(isNative());
|
|
|
|
JS_ASSERT(containsSlot(slot));
|
|
|
|
return setSlot(slot, value);
|
|
|
|
}
|
2010-03-30 14:42:48 -07:00
|
|
|
|
2010-07-14 23:19:36 -07:00
|
|
|
inline js::Value getReservedSlot(uintN index) const;
|
2010-06-07 18:35:58 -07:00
|
|
|
|
2010-08-29 11:57:08 -07:00
|
|
|
/* Defined in jsscopeinlines.h to avoid including implementation dependencies here. */
|
|
|
|
inline void updateShape(JSContext *cx);
|
|
|
|
inline void updateFlags(const js::Shape *shape, bool isDefinitelyAtom = false);
|
2009-08-27 22:53:26 -07:00
|
|
|
|
2010-08-29 11:57:08 -07:00
|
|
|
/* Extend this object to have shape as its last-added property. */
|
|
|
|
inline void extend(JSContext *cx, const js::Shape *shape, bool isDefinitelyAtom = false);
|
|
|
|
|
|
|
|
JSObject *getProto() const { return proto; }
|
|
|
|
void clearProto() { proto = NULL; }
|
2009-08-27 22:53:26 -07:00
|
|
|
|
|
|
|
void setProto(JSObject *newProto) {
|
2010-06-23 16:57:52 -07:00
|
|
|
#ifdef DEBUG
|
|
|
|
for (JSObject *obj = newProto; obj; obj = obj->getProto())
|
|
|
|
JS_ASSERT(obj != this);
|
|
|
|
#endif
|
2009-08-27 22:53:26 -07:00
|
|
|
setDelegateNullSafe(newProto);
|
2010-06-17 15:23:17 -07:00
|
|
|
proto = newProto;
|
2009-08-27 22:53:26 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
JSObject *getParent() const {
|
2010-07-29 10:11:27 -07:00
|
|
|
return parent;
|
2009-08-27 22:53:26 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void clearParent() {
|
2010-07-29 10:11:27 -07:00
|
|
|
parent = NULL;
|
2009-08-27 22:53:26 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void setParent(JSObject *newParent) {
|
2010-06-23 16:57:52 -07:00
|
|
|
#ifdef DEBUG
|
|
|
|
for (JSObject *obj = newParent; obj; obj = obj->getParent())
|
|
|
|
JS_ASSERT(obj != this);
|
|
|
|
#endif
|
2009-08-27 22:53:26 -07:00
|
|
|
setDelegateNullSafe(newParent);
|
2010-07-29 10:11:27 -07:00
|
|
|
parent = newParent;
|
2009-08-27 22:53:26 -07:00
|
|
|
}
|
|
|
|
|
2010-09-22 17:34:20 -07:00
|
|
|
JS_FRIEND_API(JSObject *) getGlobal() const;
|
2010-03-31 15:57:03 -07:00
|
|
|
|
2010-08-21 16:03:07 -07:00
|
|
|
bool isGlobal() const {
|
|
|
|
return !!(getClass()->flags & JSCLASS_IS_GLOBAL);
|
|
|
|
}
|
|
|
|
|
2009-09-05 08:59:11 -07:00
|
|
|
void *getPrivate() const {
|
2009-08-04 14:06:55 -07:00
|
|
|
JS_ASSERT(getClass()->flags & JSCLASS_HAS_PRIVATE);
|
2010-10-13 11:49:22 -07:00
|
|
|
return privateData;
|
2009-08-04 14:06:55 -07:00
|
|
|
}
|
|
|
|
|
2009-09-05 08:59:11 -07:00
|
|
|
void setPrivate(void *data) {
|
2009-08-04 14:06:55 -07:00
|
|
|
JS_ASSERT(getClass()->flags & JSCLASS_HAS_PRIVATE);
|
2010-10-13 11:49:22 -07:00
|
|
|
privateData = data;
|
2009-08-04 14:06:55 -07:00
|
|
|
}
|
|
|
|
|
2010-09-21 11:35:29 -07:00
|
|
|
|
|
|
|
/*
|
|
|
|
* ES5 meta-object properties and operations.
|
|
|
|
*/
|
|
|
|
|
|
|
|
private:
|
2010-11-12 16:15:55 -08:00
|
|
|
enum ImmutabilityType { SEAL, FREEZE };
|
|
|
|
|
2010-09-21 11:35:29 -07:00
|
|
|
/*
|
|
|
|
* The guts of Object.seal (ES5 15.2.3.8) and Object.freeze (ES5 15.2.3.9): mark the
|
|
|
|
* object as non-extensible, and adjust each property's attributes appropriately: each
|
|
|
|
* property becomes non-configurable, and if |freeze|, data properties become
|
|
|
|
* read-only as well.
|
|
|
|
*/
|
2010-11-12 16:15:55 -08:00
|
|
|
bool sealOrFreeze(JSContext *cx, ImmutabilityType it);
|
2010-09-21 11:35:29 -07:00
|
|
|
|
|
|
|
public:
|
|
|
|
bool isExtensible() const { return !(flags & NOT_EXTENSIBLE); }
|
|
|
|
bool preventExtensions(JSContext *cx, js::AutoIdVector *props);
|
2010-11-12 16:15:55 -08:00
|
|
|
|
2010-09-21 11:35:29 -07:00
|
|
|
/* ES5 15.2.3.8: non-extensible, all props non-configurable */
|
2010-11-12 16:15:55 -08:00
|
|
|
inline bool seal(JSContext *cx) { return sealOrFreeze(cx, SEAL); }
|
2010-09-21 11:35:29 -07:00
|
|
|
/* ES5 15.2.3.9: non-extensible, all properties non-configurable, all data props read-only */
|
2010-11-12 16:15:55 -08:00
|
|
|
bool freeze(JSContext *cx) { return sealOrFreeze(cx, FREEZE); }
|
2010-09-21 11:35:29 -07:00
|
|
|
|
2010-04-14 18:57:30 -07:00
|
|
|
/*
|
|
|
|
* Primitive-specific getters and setters.
|
|
|
|
*/
|
|
|
|
|
|
|
|
private:
|
2010-10-13 11:49:22 -07:00
|
|
|
static const uint32 JSSLOT_PRIMITIVE_THIS = 0;
|
2010-04-14 18:57:30 -07:00
|
|
|
|
|
|
|
public:
|
2010-07-14 23:19:36 -07:00
|
|
|
inline const js::Value &getPrimitiveThis() const;
|
|
|
|
inline void setPrimitiveThis(const js::Value &pthis);
|
2010-04-14 18:57:30 -07:00
|
|
|
|
2010-04-05 18:32:16 -07:00
|
|
|
/*
|
|
|
|
* Array-specific getters and setters (for both dense and slow arrays).
|
|
|
|
*/
|
|
|
|
|
|
|
|
inline uint32 getArrayLength() const;
|
2010-07-22 18:45:21 -07:00
|
|
|
inline void setArrayLength(uint32 length);
|
2010-04-11 16:45:20 -07:00
|
|
|
|
2010-10-13 11:49:22 -07:00
|
|
|
inline uint32 getDenseArrayCapacity();
|
|
|
|
inline js::Value* getDenseArrayElements();
|
|
|
|
inline const js::Value &getDenseArrayElement(uintN idx);
|
|
|
|
inline js::Value* addressOfDenseArrayElement(uintN idx);
|
|
|
|
inline void setDenseArrayElement(uintN idx, const js::Value &val);
|
|
|
|
inline void shrinkDenseArrayElements(JSContext *cx, uintN cap);
|
2010-04-29 20:22:33 -07:00
|
|
|
|
2010-10-14 07:12:19 -07:00
|
|
|
/*
|
|
|
|
* ensureDenseArrayElements ensures that the dense array can hold at least
|
|
|
|
* index + extra elements. It returns ED_OK on success, ED_FAILED on
|
|
|
|
* failure to grow the array, ED_SPARSE when the array is too sparse to
|
|
|
|
* grow (this includes the case of index + extra overflow). In the last
|
|
|
|
* two cases the array is kept intact.
|
|
|
|
*/
|
|
|
|
enum EnsureDenseResult { ED_OK, ED_FAILED, ED_SPARSE };
|
|
|
|
inline EnsureDenseResult ensureDenseArrayElements(JSContext *cx, uintN index, uintN extra);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Check if after growing the dense array will be too sparse.
|
|
|
|
* newElementsHint is an estimated number of elements to be added.
|
|
|
|
*/
|
|
|
|
bool willBeSparseDenseArray(uintN requiredCapacity, uintN newElementsHint);
|
|
|
|
|
2010-06-02 23:44:24 -07:00
|
|
|
JSBool makeDenseArraySlow(JSContext *cx);
|
|
|
|
|
2010-04-11 16:45:20 -07:00
|
|
|
/*
|
|
|
|
* Arguments-specific getters and setters.
|
|
|
|
*/
|
|
|
|
|
2010-05-30 11:40:14 -07:00
|
|
|
private:
|
2010-04-11 16:45:20 -07:00
|
|
|
/*
|
2010-12-29 14:45:44 -08:00
|
|
|
* We represent arguments objects using js_ArgumentsClass and
|
|
|
|
* js::StrictArgumentsClass. The two are structured similarly, and methods
|
|
|
|
* valid on arguments objects of one class are also generally valid on
|
|
|
|
* arguments objects of the other.
|
|
|
|
*
|
|
|
|
* Arguments objects of either class store arguments length in a slot:
|
2010-04-11 16:45:20 -07:00
|
|
|
*
|
|
|
|
* JSSLOT_ARGS_LENGTH - the number of actual arguments and a flag
|
|
|
|
* indicating whether arguments.length was
|
2010-08-29 11:57:08 -07:00
|
|
|
* overwritten. This slot is not used to represent
|
2010-08-04 14:39:45 -07:00
|
|
|
* arguments.length after that property has been
|
2010-08-11 23:26:59 -07:00
|
|
|
* assigned, even if the new value is integral: it's
|
|
|
|
* always the original length.
|
2010-04-11 16:45:20 -07:00
|
|
|
*
|
2010-12-29 14:45:44 -08:00
|
|
|
* Both arguments classes use a slot for storing arguments data:
|
|
|
|
*
|
|
|
|
* JSSLOT_ARGS_DATA - pointer to an ArgumentsData structure
|
|
|
|
*
|
|
|
|
* ArgumentsData for normal arguments stores the value of arguments.callee,
|
|
|
|
* as long as that property has not been overwritten. If arguments.callee
|
|
|
|
* is overwritten, the corresponding value in ArgumentsData is set to
|
|
|
|
* MagicValue(JS_ARGS_HOLE). Strict arguments do not store this value
|
|
|
|
* because arguments.callee is a poison pill for strict mode arguments.
|
|
|
|
*
|
|
|
|
* The ArgumentsData structure also stores argument values. For normal
|
|
|
|
* arguments this occurs after the corresponding function has returned, and
|
|
|
|
* for strict arguments this occurs when the arguments object is created,
|
|
|
|
* or sometimes shortly after (but not observably so). arguments[i] is
|
|
|
|
* stored in ArgumentsData.slots[i], accessible via getArgsElement() and
|
|
|
|
* setArgsElement(). Deletion of arguments[i] overwrites that slot with
|
|
|
|
* MagicValue(JS_ARGS_HOLE); subsequent redefinition of arguments[i] will
|
|
|
|
* use a normal property to store the value, ignoring the slot.
|
|
|
|
*
|
|
|
|
* Non-strict arguments have a private:
|
|
|
|
*
|
|
|
|
* private - the function's stack frame until the function
|
|
|
|
* returns, when it is replaced with null; also,
|
|
|
|
* JS_ARGUMENTS_OBJECT_ON_TRACE while on trace, if
|
|
|
|
* arguments was created on trace
|
|
|
|
*
|
|
|
|
* Technically strict arguments have a private, but it's always null.
|
|
|
|
* Conceptually it would be better to remove this oddity, but preserving it
|
|
|
|
* allows us to work with arguments objects of either kind more abstractly,
|
|
|
|
* so we keep it for now.
|
2010-04-11 16:45:20 -07:00
|
|
|
*/
|
2010-10-13 11:49:22 -07:00
|
|
|
static const uint32 JSSLOT_ARGS_DATA = 1;
|
2010-04-11 16:45:20 -07:00
|
|
|
|
|
|
|
public:
|
2010-08-29 11:57:08 -07:00
|
|
|
/* Number of extra fixed arguments object slots besides JSSLOT_PRIVATE. */
|
2010-10-13 11:49:22 -07:00
|
|
|
static const uint32 JSSLOT_ARGS_LENGTH = 0;
|
2010-08-29 11:57:08 -07:00
|
|
|
static const uint32 ARGS_CLASS_RESERVED_SLOTS = 2;
|
2010-10-13 11:49:22 -07:00
|
|
|
static const uint32 ARGS_FIRST_FREE_SLOT = ARGS_CLASS_RESERVED_SLOTS + 1;
|
2010-04-11 16:45:20 -07:00
|
|
|
|
2010-08-11 23:26:59 -07:00
|
|
|
/* Lower-order bit stolen from the length slot. */
|
2010-08-04 14:39:45 -07:00
|
|
|
static const uint32 ARGS_LENGTH_OVERRIDDEN_BIT = 0x1;
|
2010-08-11 23:26:59 -07:00
|
|
|
static const uint32 ARGS_PACKED_BITS_COUNT = 1;
|
2010-08-04 14:39:45 -07:00
|
|
|
|
|
|
|
/*
|
2010-08-11 23:26:59 -07:00
|
|
|
* Set the initial length of the arguments, and mark it as not overridden.
|
2010-08-04 14:39:45 -07:00
|
|
|
*/
|
2010-04-11 16:45:20 -07:00
|
|
|
inline void setArgsLength(uint32 argc);
|
2010-08-04 14:39:45 -07:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Return the initial length of the arguments. This may differ from the
|
|
|
|
* current value of arguments.length!
|
|
|
|
*/
|
|
|
|
inline uint32 getArgsInitialLength() const;
|
|
|
|
|
2010-04-11 16:45:20 -07:00
|
|
|
inline void setArgsLengthOverridden();
|
2010-05-02 21:42:09 -07:00
|
|
|
inline bool isArgsLengthOverridden() const;
|
2010-04-11 16:45:20 -07:00
|
|
|
|
2010-08-29 11:57:08 -07:00
|
|
|
inline js::ArgumentsData *getArgsData() const;
|
|
|
|
inline void setArgsData(js::ArgumentsData *data);
|
|
|
|
|
2010-07-14 23:19:36 -07:00
|
|
|
inline const js::Value &getArgsCallee() const;
|
|
|
|
inline void setArgsCallee(const js::Value &callee);
|
2010-04-11 16:45:20 -07:00
|
|
|
|
2010-07-14 23:19:36 -07:00
|
|
|
inline const js::Value &getArgsElement(uint32 i) const;
|
2010-10-20 23:52:55 -07:00
|
|
|
inline js::Value *getArgsElements() const;
|
2010-10-13 11:49:22 -07:00
|
|
|
inline js::Value *addressOfArgsElement(uint32 i);
|
2010-07-14 23:19:36 -07:00
|
|
|
inline void setArgsElement(uint32 i, const js::Value &v);
|
2010-05-02 21:42:09 -07:00
|
|
|
|
2010-08-09 22:43:33 -07:00
|
|
|
private:
|
|
|
|
/*
|
2010-10-12 11:38:06 -07:00
|
|
|
* Reserved slot structure for Call objects:
|
|
|
|
*
|
|
|
|
* private - the stack frame corresponding to the Call object
|
|
|
|
* until js_PutCallObject or its on-trace analog
|
|
|
|
* is called, null thereafter
|
|
|
|
* JSSLOT_CALL_CALLEE - callee function for the stack frame, or null if
|
|
|
|
* the stack frame is for strict mode eval code
|
|
|
|
* JSSLOT_CALL_ARGUMENTS - arguments object for non-strict mode eval stack
|
|
|
|
* frames (not valid for strict mode eval frames)
|
2010-08-09 22:43:33 -07:00
|
|
|
*/
|
2010-10-13 11:49:22 -07:00
|
|
|
static const uint32 JSSLOT_CALL_CALLEE = 0;
|
|
|
|
static const uint32 JSSLOT_CALL_ARGUMENTS = 1;
|
2010-08-09 22:43:33 -07:00
|
|
|
|
|
|
|
public:
|
2010-10-13 11:49:22 -07:00
|
|
|
/* Number of reserved slots. */
|
2010-08-09 22:43:33 -07:00
|
|
|
static const uint32 CALL_RESERVED_SLOTS = 2;
|
|
|
|
|
2011-01-05 12:54:04 -08:00
|
|
|
/* True if this is for a strict mode eval frame or for a function call. */
|
|
|
|
inline bool callIsForEval() const;
|
|
|
|
|
2010-12-29 20:21:18 -08:00
|
|
|
/* The stack frame for this Call object, if the frame is still active. */
|
|
|
|
inline JSStackFrame *maybeCallObjStackFrame() const;
|
|
|
|
|
2010-10-12 11:38:06 -07:00
|
|
|
/*
|
|
|
|
* The callee function if this Call object was created for a function
|
|
|
|
* invocation, or null if it was created for a strict mode eval frame.
|
|
|
|
*/
|
|
|
|
inline JSObject *getCallObjCallee() const;
|
2010-08-09 22:43:33 -07:00
|
|
|
inline JSFunction *getCallObjCalleeFunction() const;
|
2010-10-12 11:38:06 -07:00
|
|
|
inline void setCallObjCallee(JSObject *callee);
|
2010-08-09 22:43:33 -07:00
|
|
|
|
|
|
|
inline const js::Value &getCallObjArguments() const;
|
|
|
|
inline void setCallObjArguments(const js::Value &v);
|
|
|
|
|
2010-12-29 20:21:18 -08:00
|
|
|
/* Returns the formal argument at the given index. */
|
|
|
|
inline const js::Value &callObjArg(uintN i) const;
|
|
|
|
inline js::Value &callObjArg(uintN i);
|
|
|
|
|
|
|
|
/* Returns the variable at the given index. */
|
|
|
|
inline const js::Value &callObjVar(uintN i) const;
|
|
|
|
inline js::Value &callObjVar(uintN i);
|
|
|
|
|
2010-04-14 18:57:30 -07:00
|
|
|
/*
|
|
|
|
* Date-specific getters and setters.
|
|
|
|
*/
|
|
|
|
|
2010-10-13 11:49:22 -07:00
|
|
|
static const uint32 JSSLOT_DATE_UTC_TIME = 0;
|
2010-04-14 18:57:30 -07:00
|
|
|
|
2010-08-17 10:42:57 -07:00
|
|
|
/*
|
|
|
|
* Cached slots holding local properties of the date.
|
|
|
|
* These are undefined until the first actual lookup occurs
|
|
|
|
* and are reset to undefined whenever the date's time is modified.
|
|
|
|
*/
|
2010-10-13 11:49:22 -07:00
|
|
|
static const uint32 JSSLOT_DATE_COMPONENTS_START = 1;
|
2010-04-14 18:57:30 -07:00
|
|
|
|
2010-10-13 11:49:22 -07:00
|
|
|
static const uint32 JSSLOT_DATE_LOCAL_TIME = 1;
|
|
|
|
static const uint32 JSSLOT_DATE_LOCAL_YEAR = 2;
|
|
|
|
static const uint32 JSSLOT_DATE_LOCAL_MONTH = 3;
|
|
|
|
static const uint32 JSSLOT_DATE_LOCAL_DATE = 4;
|
|
|
|
static const uint32 JSSLOT_DATE_LOCAL_DAY = 5;
|
|
|
|
static const uint32 JSSLOT_DATE_LOCAL_HOURS = 6;
|
|
|
|
static const uint32 JSSLOT_DATE_LOCAL_MINUTES = 7;
|
|
|
|
static const uint32 JSSLOT_DATE_LOCAL_SECONDS = 8;
|
2010-08-17 10:42:57 -07:00
|
|
|
|
|
|
|
static const uint32 DATE_CLASS_RESERVED_SLOTS = 9;
|
2010-04-14 18:57:30 -07:00
|
|
|
|
2010-07-14 23:19:36 -07:00
|
|
|
inline const js::Value &getDateUTCTime() const;
|
|
|
|
inline void setDateUTCTime(const js::Value &pthis);
|
2010-04-14 18:57:30 -07:00
|
|
|
|
2010-07-23 14:41:56 -07:00
|
|
|
/*
|
|
|
|
* Function-specific getters and setters.
|
|
|
|
*/
|
|
|
|
|
|
|
|
private:
|
2010-07-27 11:48:08 -07:00
|
|
|
friend struct JSFunction;
|
2010-08-30 15:13:32 -07:00
|
|
|
friend class js::mjit::Compiler;
|
2010-07-23 14:41:56 -07:00
|
|
|
|
2010-08-29 11:57:08 -07:00
|
|
|
/*
|
|
|
|
* Flat closures with one or more upvars snapshot the upvars' values into a
|
|
|
|
* vector of js::Values referenced from this slot.
|
|
|
|
*/
|
2010-10-13 11:49:22 -07:00
|
|
|
static const uint32 JSSLOT_FLAT_CLOSURE_UPVARS = 0;
|
2010-07-23 14:41:56 -07:00
|
|
|
|
2010-08-29 11:57:08 -07:00
|
|
|
/*
|
|
|
|
* Null closures set or initialized as methods have these slots. See the
|
|
|
|
* "method barrier" comments and methods.
|
|
|
|
*/
|
2010-07-23 14:41:56 -07:00
|
|
|
|
2010-10-13 11:49:22 -07:00
|
|
|
static const uint32 JSSLOT_FUN_METHOD_ATOM = 0;
|
|
|
|
static const uint32 JSSLOT_FUN_METHOD_OBJ = 1;
|
|
|
|
|
|
|
|
static const uint32 JSSLOT_BOUND_FUNCTION_THIS = 0;
|
|
|
|
static const uint32 JSSLOT_BOUND_FUNCTION_ARGS_COUNT = 1;
|
2010-08-13 10:42:33 -07:00
|
|
|
|
2010-07-23 14:41:56 -07:00
|
|
|
public:
|
2010-08-29 11:57:08 -07:00
|
|
|
static const uint32 FUN_CLASS_RESERVED_SLOTS = 2;
|
|
|
|
|
|
|
|
inline JSFunction *getFunctionPrivate() const;
|
|
|
|
|
|
|
|
inline js::Value *getFlatClosureUpvars() const;
|
|
|
|
inline js::Value getFlatClosureUpvar(uint32 i) const;
|
2010-12-29 20:21:18 -08:00
|
|
|
inline js::Value &getFlatClosureUpvar(uint32 i);
|
2010-08-29 11:57:08 -07:00
|
|
|
inline void setFlatClosureUpvars(js::Value *upvars);
|
2010-07-23 14:41:56 -07:00
|
|
|
|
|
|
|
inline bool hasMethodObj(const JSObject& obj) const;
|
|
|
|
inline void setMethodObj(JSObject& obj);
|
|
|
|
|
2010-08-29 11:57:08 -07:00
|
|
|
inline bool initBoundFunction(JSContext *cx, const js::Value &thisArg,
|
|
|
|
const js::Value *args, uintN argslen);
|
2010-08-13 10:42:33 -07:00
|
|
|
|
|
|
|
inline JSObject *getBoundFunctionTarget() const;
|
|
|
|
inline const js::Value &getBoundFunctionThis() const;
|
|
|
|
inline const js::Value *getBoundFunctionArguments(uintN &argslen) const;
|
|
|
|
|
2010-04-14 18:57:30 -07:00
|
|
|
/*
|
|
|
|
* RegExp-specific getters and setters.
|
|
|
|
*/
|
|
|
|
|
|
|
|
private:
|
2010-10-13 11:49:22 -07:00
|
|
|
static const uint32 JSSLOT_REGEXP_LAST_INDEX = 0;
|
2010-04-14 18:57:30 -07:00
|
|
|
|
|
|
|
public:
|
2010-08-29 11:57:08 -07:00
|
|
|
static const uint32 REGEXP_CLASS_RESERVED_SLOTS = 1;
|
2010-04-14 18:57:30 -07:00
|
|
|
|
2010-07-14 23:19:36 -07:00
|
|
|
inline const js::Value &getRegExpLastIndex() const;
|
|
|
|
inline void setRegExpLastIndex(const js::Value &v);
|
2010-07-12 13:40:44 -07:00
|
|
|
inline void setRegExpLastIndex(jsdouble d);
|
2010-04-14 18:57:30 -07:00
|
|
|
inline void zeroRegExpLastIndex();
|
|
|
|
|
2010-05-07 17:52:52 -07:00
|
|
|
/*
|
|
|
|
* Iterator-specific getters and setters.
|
|
|
|
*/
|
|
|
|
|
2010-10-10 15:37:22 -07:00
|
|
|
inline js::NativeIterator *getNativeIterator() const;
|
|
|
|
inline void setNativeIterator(js::NativeIterator *);
|
2010-05-07 17:52:52 -07:00
|
|
|
|
2011-02-03 05:06:21 -08:00
|
|
|
/*
|
|
|
|
* Script-related getters.
|
|
|
|
*/
|
|
|
|
|
|
|
|
inline JSScript *getScript() const;
|
|
|
|
|
2010-05-12 18:57:36 -07:00
|
|
|
/*
|
|
|
|
* XML-related getters and setters.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Slots for XML-related classes are as follows:
|
|
|
|
* - js_NamespaceClass.base reserves the *_NAME_* and *_NAMESPACE_* slots.
|
|
|
|
* - js_QNameClass.base, js_AttributeNameClass, js_AnyNameClass reserve
|
|
|
|
* the *_NAME_* and *_QNAME_* slots.
|
|
|
|
* - Others (js_XMLClass, js_XMLFilterClass) don't reserve any slots.
|
|
|
|
*/
|
|
|
|
private:
|
2010-10-13 11:49:22 -07:00
|
|
|
static const uint32 JSSLOT_NAME_PREFIX = 0; // shared
|
|
|
|
static const uint32 JSSLOT_NAME_URI = 1; // shared
|
2010-05-12 18:57:36 -07:00
|
|
|
|
2010-10-13 11:49:22 -07:00
|
|
|
static const uint32 JSSLOT_NAMESPACE_DECLARED = 2;
|
2010-05-12 18:57:36 -07:00
|
|
|
|
2010-10-13 11:49:22 -07:00
|
|
|
static const uint32 JSSLOT_QNAME_LOCAL_NAME = 2;
|
2010-05-12 18:57:36 -07:00
|
|
|
|
|
|
|
public:
|
2010-08-29 11:57:08 -07:00
|
|
|
static const uint32 NAMESPACE_CLASS_RESERVED_SLOTS = 3;
|
|
|
|
static const uint32 QNAME_CLASS_RESERVED_SLOTS = 3;
|
2010-05-12 18:57:36 -07:00
|
|
|
|
2010-12-06 10:26:58 -08:00
|
|
|
inline JSLinearString *getNamePrefix() const;
|
|
|
|
inline jsval getNamePrefixVal() const;
|
|
|
|
inline void setNamePrefix(JSLinearString *prefix);
|
|
|
|
inline void clearNamePrefix();
|
2010-05-12 18:57:36 -07:00
|
|
|
|
2010-12-06 10:26:58 -08:00
|
|
|
inline JSLinearString *getNameURI() const;
|
|
|
|
inline jsval getNameURIVal() const;
|
|
|
|
inline void setNameURI(JSLinearString *uri);
|
2010-05-12 18:57:36 -07:00
|
|
|
|
|
|
|
inline jsval getNamespaceDeclared() const;
|
|
|
|
inline void setNamespaceDeclared(jsval decl);
|
|
|
|
|
2010-12-06 10:26:58 -08:00
|
|
|
inline JSLinearString *getQNameLocalName() const;
|
|
|
|
inline jsval getQNameLocalNameVal() const;
|
|
|
|
inline void setQNameLocalName(JSLinearString *name);
|
2010-05-12 18:57:36 -07:00
|
|
|
|
2010-05-18 19:21:43 -07:00
|
|
|
/*
|
|
|
|
* Proxy-specific getters and setters.
|
|
|
|
*/
|
|
|
|
|
2010-06-23 14:35:10 -07:00
|
|
|
inline js::JSProxyHandler *getProxyHandler() const;
|
2010-07-14 23:19:36 -07:00
|
|
|
inline const js::Value &getProxyPrivate() const;
|
|
|
|
inline void setProxyPrivate(const js::Value &priv);
|
2010-09-20 14:48:01 -07:00
|
|
|
inline const js::Value &getProxyExtra() const;
|
|
|
|
inline void setProxyExtra(const js::Value &extra);
|
2010-05-18 19:21:43 -07:00
|
|
|
|
2010-06-08 14:09:40 -07:00
|
|
|
/*
|
|
|
|
* With object-specific getters and setters.
|
|
|
|
*/
|
|
|
|
inline JSObject *getWithThis() const;
|
|
|
|
inline void setWithThis(JSObject *thisp);
|
|
|
|
|
2010-04-05 18:32:16 -07:00
|
|
|
/*
|
|
|
|
* Back to generic stuff.
|
|
|
|
*/
|
2010-05-18 19:21:43 -07:00
|
|
|
inline bool isCallable();
|
2010-02-22 14:07:50 -08:00
|
|
|
|
2009-09-05 08:59:11 -07:00
|
|
|
/* The map field is not initialized here and should be set separately. */
|
2010-10-13 11:49:22 -07:00
|
|
|
void init(JSContext *cx, js::Class *aclasp, JSObject *proto, JSObject *parent,
|
|
|
|
void *priv, bool useHoles);
|
2010-08-29 11:57:08 -07:00
|
|
|
|
|
|
|
inline void finish(JSContext *cx);
|
2010-11-15 12:39:00 -08:00
|
|
|
JS_ALWAYS_INLINE void finalize(JSContext *cx);
|
2009-08-11 13:05:44 -07:00
|
|
|
|
2009-11-18 12:29:58 -08:00
|
|
|
/*
|
|
|
|
* Like init, but also initializes map. The catch: proto must be the result
|
|
|
|
* of a call to js_InitClass(...clasp, ...).
|
|
|
|
*/
|
2010-10-13 11:49:22 -07:00
|
|
|
inline bool initSharingEmptyShape(JSContext *cx,
|
|
|
|
js::Class *clasp,
|
2010-09-10 17:06:30 -07:00
|
|
|
JSObject *proto,
|
|
|
|
JSObject *parent,
|
|
|
|
void *priv,
|
2010-10-13 11:49:22 -07:00
|
|
|
/* gc::FinalizeKind */ unsigned kind);
|
2009-11-18 12:29:58 -08:00
|
|
|
|
2010-10-13 11:49:22 -07:00
|
|
|
inline bool hasSlotsArray() const;
|
2009-12-30 03:06:26 -08:00
|
|
|
|
|
|
|
/* This method can only be called when hasSlotsArray() returns true. */
|
|
|
|
inline void freeSlotsArray(JSContext *cx);
|
|
|
|
|
2010-10-13 11:49:22 -07:00
|
|
|
/* Free the slots array and copy slots that fit into the fixed array. */
|
|
|
|
inline void revertToFixedSlots(JSContext *cx);
|
|
|
|
|
2010-08-29 11:57:08 -07:00
|
|
|
inline bool hasProperty(JSContext *cx, jsid id, bool *foundp, uintN flags = 0);
|
|
|
|
|
2010-12-06 16:27:39 -08:00
|
|
|
/*
|
2010-12-07 08:36:21 -08:00
|
|
|
* Allocate and free an object slot. Note that freeSlot is infallible: it
|
|
|
|
* returns true iff this is a dictionary-mode object and the freed slot was
|
|
|
|
* added to the freelist.
|
|
|
|
*
|
|
|
|
* FIXME: bug 593129 -- slot allocation should be done by object methods
|
|
|
|
* after calling object-parameter-free shape methods, avoiding coupling
|
|
|
|
* logic across the object vs. shape module wall.
|
|
|
|
*/
|
|
|
|
bool allocSlot(JSContext *cx, uint32 *slotp);
|
2010-12-06 16:27:39 -08:00
|
|
|
bool freeSlot(JSContext *cx, uint32 slot);
|
2010-08-29 11:57:08 -07:00
|
|
|
|
2011-01-14 14:18:53 -08:00
|
|
|
public:
|
2010-09-16 11:56:54 -07:00
|
|
|
bool reportReadOnly(JSContext* cx, jsid id, uintN report = JSREPORT_ERROR);
|
|
|
|
bool reportNotConfigurable(JSContext* cx, jsid id, uintN report = JSREPORT_ERROR);
|
|
|
|
bool reportNotExtensible(JSContext *cx, uintN report = JSREPORT_ERROR);
|
2010-08-29 11:57:08 -07:00
|
|
|
|
2010-09-16 11:56:54 -07:00
|
|
|
private:
|
2010-08-29 11:57:08 -07:00
|
|
|
js::Shape *getChildProperty(JSContext *cx, js::Shape *parent, js::Shape &child);
|
|
|
|
|
2010-09-16 11:56:54 -07:00
|
|
|
/*
|
|
|
|
* Internal helper that adds a shape not yet mapped by this object.
|
|
|
|
*
|
|
|
|
* Notes:
|
|
|
|
* 1. getter and setter must be normalized based on flags (see jsscope.cpp).
|
|
|
|
* 2. !isExtensible() checking must be done by callers.
|
|
|
|
*/
|
|
|
|
const js::Shape *addPropertyInternal(JSContext *cx, jsid id,
|
2011-02-09 11:31:40 -08:00
|
|
|
js::PropertyOp getter, js::StrictPropertyOp setter,
|
2010-09-16 11:56:54 -07:00
|
|
|
uint32 slot, uintN attrs,
|
|
|
|
uintN flags, intN shortid,
|
|
|
|
js::Shape **spp);
|
2010-08-29 11:57:08 -07:00
|
|
|
|
|
|
|
bool toDictionaryMode(JSContext *cx);
|
|
|
|
|
|
|
|
public:
|
|
|
|
/* Add a property whose id is not yet in this scope. */
|
|
|
|
const js::Shape *addProperty(JSContext *cx, jsid id,
|
2011-02-09 11:31:40 -08:00
|
|
|
js::PropertyOp getter, js::StrictPropertyOp setter,
|
2010-08-29 11:57:08 -07:00
|
|
|
uint32 slot, uintN attrs,
|
|
|
|
uintN flags, intN shortid);
|
|
|
|
|
|
|
|
/* Add a data property whose id is not yet in this scope. */
|
|
|
|
const js::Shape *addDataProperty(JSContext *cx, jsid id, uint32 slot, uintN attrs) {
|
|
|
|
JS_ASSERT(!(attrs & (JSPROP_GETTER | JSPROP_SETTER)));
|
|
|
|
return addProperty(cx, id, NULL, NULL, slot, attrs, 0, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Add or overwrite a property for id in this scope. */
|
|
|
|
const js::Shape *putProperty(JSContext *cx, jsid id,
|
2011-02-09 11:31:40 -08:00
|
|
|
js::PropertyOp getter, js::StrictPropertyOp setter,
|
2010-08-29 11:57:08 -07:00
|
|
|
uint32 slot, uintN attrs,
|
|
|
|
uintN flags, intN shortid);
|
|
|
|
|
|
|
|
/* Change the given property into a sibling with the same id in this scope. */
|
|
|
|
const js::Shape *changeProperty(JSContext *cx, const js::Shape *shape, uintN attrs, uintN mask,
|
2011-02-09 11:31:40 -08:00
|
|
|
js::PropertyOp getter, js::StrictPropertyOp setter);
|
2010-08-29 11:57:08 -07:00
|
|
|
|
2010-09-16 11:56:54 -07:00
|
|
|
/* Remove the property named by id from this object. */
|
2010-08-29 11:57:08 -07:00
|
|
|
bool removeProperty(JSContext *cx, jsid id);
|
|
|
|
|
|
|
|
/* Clear the scope, making it empty. */
|
|
|
|
void clear(JSContext *cx);
|
|
|
|
|
2010-06-12 09:29:04 -07:00
|
|
|
JSBool lookupProperty(JSContext *cx, jsid id, JSObject **objp, JSProperty **propp) {
|
2010-09-28 02:59:25 -07:00
|
|
|
js::LookupPropOp op = getOps()->lookupProperty;
|
2010-06-12 09:29:04 -07:00
|
|
|
return (op ? op : js_LookupProperty)(cx, this, id, objp, propp);
|
2009-08-11 13:05:44 -07:00
|
|
|
}
|
|
|
|
|
2010-07-14 23:19:36 -07:00
|
|
|
JSBool defineProperty(JSContext *cx, jsid id, const js::Value &value,
|
|
|
|
js::PropertyOp getter = js::PropertyStub,
|
2011-02-09 11:31:40 -08:00
|
|
|
js::StrictPropertyOp setter = js::StrictPropertyStub,
|
2009-09-23 08:54:50 -07:00
|
|
|
uintN attrs = JSPROP_ENUMERATE) {
|
2010-06-12 09:29:04 -07:00
|
|
|
js::DefinePropOp op = getOps()->defineProperty;
|
|
|
|
return (op ? op : js_DefineProperty)(cx, this, id, &value, getter, setter, attrs);
|
2009-08-11 13:05:44 -07:00
|
|
|
}
|
|
|
|
|
2010-10-29 10:42:35 -07:00
|
|
|
JSBool getProperty(JSContext *cx, JSObject *receiver, jsid id, js::Value *vp) {
|
2010-06-12 09:29:04 -07:00
|
|
|
js::PropertyIdOp op = getOps()->getProperty;
|
2010-10-29 10:42:35 -07:00
|
|
|
return (op ? op : (js::PropertyIdOp)js_GetProperty)(cx, this, receiver, id, vp);
|
|
|
|
}
|
|
|
|
|
|
|
|
JSBool getProperty(JSContext *cx, jsid id, js::Value *vp) {
|
|
|
|
return getProperty(cx, this, id, vp);
|
2009-08-11 13:05:44 -07:00
|
|
|
}
|
|
|
|
|
2010-09-15 13:43:55 -07:00
|
|
|
JSBool setProperty(JSContext *cx, jsid id, js::Value *vp, JSBool strict) {
|
|
|
|
js::StrictPropertyIdOp op = getOps()->setProperty;
|
|
|
|
return (op ? op : js_SetProperty)(cx, this, id, vp, strict);
|
2009-08-11 13:05:44 -07:00
|
|
|
}
|
|
|
|
|
2010-06-05 14:24:54 -07:00
|
|
|
JSBool getAttributes(JSContext *cx, jsid id, uintN *attrsp) {
|
2010-09-28 02:59:25 -07:00
|
|
|
js::AttributesOp op = getOps()->getAttributes;
|
2010-06-12 09:29:04 -07:00
|
|
|
return (op ? op : js_GetAttributes)(cx, this, id, attrsp);
|
2009-08-11 13:05:44 -07:00
|
|
|
}
|
|
|
|
|
2010-06-05 14:24:54 -07:00
|
|
|
JSBool setAttributes(JSContext *cx, jsid id, uintN *attrsp) {
|
2010-09-28 02:59:25 -07:00
|
|
|
js::AttributesOp op = getOps()->setAttributes;
|
2010-06-12 09:29:04 -07:00
|
|
|
return (op ? op : js_SetAttributes)(cx, this, id, attrsp);
|
2009-08-11 13:05:44 -07:00
|
|
|
}
|
|
|
|
|
2010-09-15 13:43:55 -07:00
|
|
|
JSBool deleteProperty(JSContext *cx, jsid id, js::Value *rval, JSBool strict) {
|
2010-10-29 10:42:35 -07:00
|
|
|
js::DeleteIdOp op = getOps()->deleteProperty;
|
2010-09-15 13:43:55 -07:00
|
|
|
return (op ? op : js_DeleteProperty)(cx, this, id, rval, strict);
|
2009-08-11 13:05:44 -07:00
|
|
|
}
|
|
|
|
|
2010-06-12 09:29:04 -07:00
|
|
|
JSBool enumerate(JSContext *cx, JSIterateOp iterop, js::Value *statep, jsid *idp) {
|
|
|
|
js::NewEnumerateOp op = getOps()->enumerate;
|
|
|
|
return (op ? op : js_Enumerate)(cx, this, iterop, statep, idp);
|
2009-08-11 13:05:44 -07:00
|
|
|
}
|
|
|
|
|
2010-02-22 16:30:22 -08:00
|
|
|
JSType typeOf(JSContext *cx) {
|
2010-09-28 02:59:25 -07:00
|
|
|
js::TypeOfOp op = getOps()->typeOf;
|
2010-06-12 09:29:04 -07:00
|
|
|
return (op ? op : js_TypeOf)(cx, this);
|
2010-02-22 16:30:22 -08:00
|
|
|
}
|
|
|
|
|
2009-08-11 13:05:44 -07:00
|
|
|
/* These four are time-optimized to avoid stub calls. */
|
2010-05-12 07:34:03 -07:00
|
|
|
JSObject *thisObject(JSContext *cx) {
|
2010-06-12 09:29:04 -07:00
|
|
|
JSObjectOp op = getOps()->thisObject;
|
|
|
|
return op ? op(cx, this) : this;
|
2009-08-11 13:05:44 -07:00
|
|
|
}
|
2010-06-12 09:29:04 -07:00
|
|
|
|
2010-07-14 23:19:36 -07:00
|
|
|
static bool thisObject(JSContext *cx, const js::Value &v, js::Value *vp);
|
2009-08-11 13:05:44 -07:00
|
|
|
|
2010-09-27 13:49:09 -07:00
|
|
|
inline JSCompartment *getCompartment() const;
|
2010-06-04 16:32:10 -07:00
|
|
|
|
2010-08-02 23:52:12 -07:00
|
|
|
inline JSObject *getThrowTypeError() const;
|
|
|
|
|
2010-11-15 17:21:25 -08:00
|
|
|
JS_FRIEND_API(JSObject *) clone(JSContext *cx, JSObject *proto, JSObject *parent);
|
|
|
|
JS_FRIEND_API(bool) copyPropertiesFrom(JSContext *cx, JSObject *obj);
|
|
|
|
bool swap(JSContext *cx, JSObject *other);
|
2010-05-18 19:21:43 -07:00
|
|
|
|
2010-10-13 11:49:22 -07:00
|
|
|
const js::Shape *defineBlockVariable(JSContext *cx, jsid id, intN index);
|
2010-09-20 12:05:21 -07:00
|
|
|
|
2010-07-23 14:41:56 -07:00
|
|
|
inline bool canHaveMethodBarrier() const;
|
|
|
|
|
2010-03-30 00:44:28 -07:00
|
|
|
inline bool isArguments() const;
|
2010-08-11 23:26:59 -07:00
|
|
|
inline bool isNormalArguments() const;
|
|
|
|
inline bool isStrictArguments() const;
|
2009-12-30 13:49:26 -08:00
|
|
|
inline bool isArray() const;
|
|
|
|
inline bool isDenseArray() const;
|
2010-04-05 18:32:16 -07:00
|
|
|
inline bool isSlowArray() const;
|
2010-04-14 18:57:30 -07:00
|
|
|
inline bool isNumber() const;
|
|
|
|
inline bool isBoolean() const;
|
|
|
|
inline bool isString() const;
|
|
|
|
inline bool isPrimitive() const;
|
|
|
|
inline bool isDate() const;
|
2009-12-30 13:49:26 -08:00
|
|
|
inline bool isFunction() const;
|
2010-07-23 14:41:56 -07:00
|
|
|
inline bool isObject() const;
|
|
|
|
inline bool isWith() const;
|
|
|
|
inline bool isBlock() const;
|
2010-09-02 14:50:44 -07:00
|
|
|
inline bool isStaticBlock() const;
|
|
|
|
inline bool isClonedBlock() const;
|
2010-08-29 11:57:08 -07:00
|
|
|
inline bool isCall() const;
|
2009-12-30 13:49:26 -08:00
|
|
|
inline bool isRegExp() const;
|
2011-02-03 05:06:21 -08:00
|
|
|
inline bool isScript() const;
|
2009-12-30 13:49:26 -08:00
|
|
|
inline bool isXML() const;
|
2010-07-26 17:05:17 -07:00
|
|
|
inline bool isXMLId() const;
|
2010-05-12 18:57:36 -07:00
|
|
|
inline bool isNamespace() const;
|
|
|
|
inline bool isQName() const;
|
2010-01-14 09:33:14 -08:00
|
|
|
|
2010-05-18 19:21:43 -07:00
|
|
|
inline bool isProxy() const;
|
|
|
|
inline bool isObjectProxy() const;
|
|
|
|
inline bool isFunctionProxy() const;
|
|
|
|
|
2010-07-02 13:54:53 -07:00
|
|
|
JS_FRIEND_API(bool) isWrapper() const;
|
|
|
|
JS_FRIEND_API(JSObject *) unwrap(uintN *flagsp = NULL);
|
2010-06-24 14:45:32 -07:00
|
|
|
|
2010-07-14 23:19:36 -07:00
|
|
|
inline void initArrayClass();
|
2009-08-27 22:53:26 -07:00
|
|
|
};
|
2009-08-11 13:05:44 -07:00
|
|
|
|
2010-10-13 11:49:22 -07:00
|
|
|
/* Check alignment for any fixed slots allocated after the object. */
|
|
|
|
JS_STATIC_ASSERT(sizeof(JSObject) % sizeof(js::Value) == 0);
|
2010-09-20 12:05:21 -07:00
|
|
|
|
2010-10-13 11:49:22 -07:00
|
|
|
inline js::Value*
|
|
|
|
JSObject::fixedSlots() const {
|
|
|
|
return (js::Value*) (jsuword(this) + sizeof(JSObject));
|
|
|
|
}
|
2010-09-20 11:40:32 -07:00
|
|
|
|
2010-10-13 11:49:22 -07:00
|
|
|
inline bool
|
|
|
|
JSObject::hasSlotsArray() const { return this->slots != fixedSlots(); }
|
2010-09-20 11:40:32 -07:00
|
|
|
|
2010-10-13 11:49:22 -07:00
|
|
|
/* static */ inline size_t
|
|
|
|
JSObject::getFixedSlotOffset(size_t slot) {
|
|
|
|
return sizeof(JSObject) + (slot * sizeof(js::Value));
|
|
|
|
}
|
|
|
|
|
|
|
|
struct JSObject_Slots2 : JSObject { js::Value fslots[2]; };
|
|
|
|
struct JSObject_Slots4 : JSObject { js::Value fslots[4]; };
|
|
|
|
struct JSObject_Slots8 : JSObject { js::Value fslots[8]; };
|
|
|
|
struct JSObject_Slots12 : JSObject { js::Value fslots[12]; };
|
|
|
|
struct JSObject_Slots16 : JSObject { js::Value fslots[16]; };
|
|
|
|
|
|
|
|
#define JSSLOT_FREE(clasp) JSCLASS_RESERVED_SLOTS(clasp)
|
2009-04-24 16:28:21 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
#ifdef JS_THREADSAFE
|
|
|
|
|
|
|
|
/*
|
|
|
|
* The GC runs only when all threads except the one on which the GC is active
|
2010-03-30 14:42:48 -07:00
|
|
|
* are suspended at GC-safe points, so calling obj->getSlot() from the GC's
|
2010-05-14 06:55:17 -07:00
|
|
|
* thread is safe when rt->gcRunning is set. See jsgc.cpp for details.
|
2007-03-22 10:30:00 -07:00
|
|
|
*/
|
|
|
|
#define THREAD_IS_RUNNING_GC(rt, thread) \
|
|
|
|
((rt)->gcRunning && (rt)->gcThread == (thread))
|
|
|
|
|
|
|
|
#define CX_THREAD_IS_RUNNING_GC(cx) \
|
|
|
|
THREAD_IS_RUNNING_GC((cx)->runtime, (cx)->thread)
|
|
|
|
|
2010-03-30 14:42:48 -07:00
|
|
|
#endif /* JS_THREADSAFE */
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2009-08-27 22:53:26 -07:00
|
|
|
inline void
|
2009-08-11 13:05:44 -07:00
|
|
|
OBJ_TO_INNER_OBJECT(JSContext *cx, JSObject *&obj)
|
|
|
|
{
|
2010-06-12 09:29:04 -07:00
|
|
|
if (JSObjectOp op = obj->getClass()->ext.innerObject)
|
|
|
|
obj = op(cx, obj);
|
2009-08-11 13:05:44 -07:00
|
|
|
}
|
|
|
|
|
2009-08-27 22:53:26 -07:00
|
|
|
inline void
|
2009-08-11 13:05:44 -07:00
|
|
|
OBJ_TO_OUTER_OBJECT(JSContext *cx, JSObject *&obj)
|
|
|
|
{
|
2010-06-12 09:29:04 -07:00
|
|
|
if (JSObjectOp op = obj->getClass()->ext.outerObject)
|
|
|
|
obj = op(cx, obj);
|
2009-08-11 13:05:44 -07:00
|
|
|
}
|
2010-06-16 14:13:28 -07:00
|
|
|
|
2010-07-14 23:19:36 -07:00
|
|
|
class JSValueArray {
|
2010-06-16 14:13:28 -07:00
|
|
|
public:
|
|
|
|
jsval *array;
|
|
|
|
size_t length;
|
|
|
|
|
2010-07-14 23:19:36 -07:00
|
|
|
JSValueArray(jsval *v, size_t c) : array(v), length(c) {}
|
2010-06-16 14:13:28 -07:00
|
|
|
};
|
2009-08-11 13:05:44 -07:00
|
|
|
|
2010-07-14 23:19:36 -07:00
|
|
|
class ValueArray {
|
|
|
|
public:
|
|
|
|
js::Value *array;
|
|
|
|
size_t length;
|
|
|
|
|
|
|
|
ValueArray(js::Value *v, size_t c) : array(v), length(c) {}
|
|
|
|
};
|
|
|
|
|
|
|
|
extern js::Class js_ObjectClass;
|
|
|
|
extern js::Class js_WithClass;
|
|
|
|
extern js::Class js_BlockClass;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-07-23 14:41:56 -07:00
|
|
|
inline bool JSObject::isObject() const { return getClass() == &js_ObjectClass; }
|
|
|
|
inline bool JSObject::isWith() const { return getClass() == &js_WithClass; }
|
|
|
|
inline bool JSObject::isBlock() const { return getClass() == &js_BlockClass; }
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
/*
|
|
|
|
* Block scope object macros. The slots reserved by js_BlockClass are:
|
|
|
|
*
|
2010-10-13 11:49:22 -07:00
|
|
|
* private JSStackFrame * active frame pointer or null
|
2007-03-22 10:30:00 -07:00
|
|
|
* JSSLOT_BLOCK_DEPTH int depth of block slots in frame
|
|
|
|
*
|
|
|
|
* After JSSLOT_BLOCK_DEPTH come one or more slots for the block locals.
|
|
|
|
*
|
|
|
|
* A With object is like a Block object, in that both have one reserved slot
|
|
|
|
* telling the stack depth of the relevant slots (the slot whose value is the
|
|
|
|
* object named in the with statement, the slots containing the block's local
|
|
|
|
* variables); and both have a private slot referring to the JSStackFrame in
|
|
|
|
* whose activation they were created (or null if the with or block object
|
|
|
|
* outlives the frame).
|
|
|
|
*/
|
2010-10-13 11:49:22 -07:00
|
|
|
static const uint32 JSSLOT_BLOCK_DEPTH = 0;
|
2010-09-13 22:33:44 -07:00
|
|
|
static const uint32 JSSLOT_BLOCK_FIRST_FREE_SLOT = JSSLOT_BLOCK_DEPTH + 1;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-09-02 14:50:44 -07:00
|
|
|
inline bool
|
|
|
|
JSObject::isStaticBlock() const
|
2009-07-21 14:25:11 -07:00
|
|
|
{
|
2010-09-02 14:50:44 -07:00
|
|
|
return isBlock() && !getProto();
|
2009-07-21 14:25:11 -07:00
|
|
|
}
|
|
|
|
|
2010-09-02 14:50:44 -07:00
|
|
|
inline bool
|
|
|
|
JSObject::isClonedBlock() const
|
|
|
|
{
|
|
|
|
return isBlock() && !!getProto();
|
|
|
|
}
|
2010-06-08 14:09:40 -07:00
|
|
|
|
2010-10-13 11:49:22 -07:00
|
|
|
static const uint32 JSSLOT_WITH_THIS = 1;
|
2009-09-09 13:53:37 -07:00
|
|
|
|
2008-02-07 15:18:45 -08:00
|
|
|
#define OBJ_BLOCK_COUNT(cx,obj) \
|
2010-09-02 14:50:44 -07:00
|
|
|
(obj)->propertyCount()
|
2008-02-07 15:18:45 -08:00
|
|
|
#define OBJ_BLOCK_DEPTH(cx,obj) \
|
2010-09-02 14:50:44 -07:00
|
|
|
(obj)->getSlot(JSSLOT_BLOCK_DEPTH).toInt32()
|
2008-02-07 15:18:45 -08:00
|
|
|
#define OBJ_SET_BLOCK_DEPTH(cx,obj,depth) \
|
2010-09-02 14:50:44 -07:00
|
|
|
(obj)->setSlot(JSSLOT_BLOCK_DEPTH, Value(Int32Value(depth)))
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
/*
|
|
|
|
* To make sure this slot is well-defined, always call js_NewWithObject to
|
|
|
|
* create a With object, don't call js_NewObject directly. When creating a
|
|
|
|
* With object that does not correspond to a stack slot, pass -1 for depth.
|
|
|
|
*
|
|
|
|
* When popping the stack across this object's "with" statement, client code
|
2009-08-04 14:06:55 -07:00
|
|
|
* must call withobj->setPrivate(NULL).
|
2007-03-22 10:30:00 -07:00
|
|
|
*/
|
2008-12-09 08:38:32 -08:00
|
|
|
extern JS_REQUIRES_STACK JSObject *
|
2007-03-22 10:30:00 -07:00
|
|
|
js_NewWithObject(JSContext *cx, JSObject *proto, JSObject *parent, jsint depth);
|
|
|
|
|
2010-05-12 06:11:46 -07:00
|
|
|
inline JSObject *
|
|
|
|
js_UnwrapWithObject(JSContext *cx, JSObject *withobj)
|
|
|
|
{
|
|
|
|
JS_ASSERT(withobj->getClass() == &js_WithClass);
|
|
|
|
return withobj->getProto();
|
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
/*
|
|
|
|
* Create a new block scope object not linked to any proto or parent object.
|
|
|
|
* Blocks are created by the compiler to reify let blocks and comprehensions.
|
|
|
|
* Only when dynamic scope is captured do they need to be cloned and spliced
|
|
|
|
* into an active scope chain.
|
|
|
|
*/
|
|
|
|
extern JSObject *
|
|
|
|
js_NewBlockObject(JSContext *cx);
|
|
|
|
|
|
|
|
extern JSObject *
|
2009-07-21 14:25:11 -07:00
|
|
|
js_CloneBlockObject(JSContext *cx, JSObject *proto, JSStackFrame *fp);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2008-12-09 08:38:32 -08:00
|
|
|
extern JS_REQUIRES_STACK JSBool
|
2008-02-19 04:16:26 -08:00
|
|
|
js_PutBlockObject(JSContext *cx, JSBool normalUnwind);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2009-05-06 16:03:10 -07:00
|
|
|
JSBool
|
|
|
|
js_XDRBlockObject(JSXDRState *xdr, JSObject **objp);
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
struct JSSharpObjectMap {
|
|
|
|
jsrefcount depth;
|
|
|
|
jsatomid sharpgen;
|
|
|
|
JSHashTable *table;
|
|
|
|
};
|
|
|
|
|
|
|
|
#define SHARP_BIT ((jsatomid) 1)
|
|
|
|
#define BUSY_BIT ((jsatomid) 2)
|
|
|
|
#define SHARP_ID_SHIFT 2
|
2010-03-16 08:41:28 -07:00
|
|
|
#define IS_SHARP(he) (uintptr_t((he)->value) & SHARP_BIT)
|
|
|
|
#define MAKE_SHARP(he) ((he)->value = (void *) (uintptr_t((he)->value)|SHARP_BIT))
|
|
|
|
#define IS_BUSY(he) (uintptr_t((he)->value) & BUSY_BIT)
|
|
|
|
#define MAKE_BUSY(he) ((he)->value = (void *) (uintptr_t((he)->value)|BUSY_BIT))
|
|
|
|
#define CLEAR_BUSY(he) ((he)->value = (void *) (uintptr_t((he)->value)&~BUSY_BIT))
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
extern JSHashEntry *
|
|
|
|
js_EnterSharpObject(JSContext *cx, JSObject *obj, JSIdArray **idap,
|
|
|
|
jschar **sp);
|
|
|
|
|
|
|
|
extern void
|
|
|
|
js_LeaveSharpObject(JSContext *cx, JSIdArray **idap);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Mark objects stored in map if GC happens between js_EnterSharpObject
|
|
|
|
* and js_LeaveSharpObject. GC calls this when map->depth > 0.
|
|
|
|
*/
|
|
|
|
extern void
|
2007-04-16 23:53:37 -07:00
|
|
|
js_TraceSharpMap(JSTracer *trc, JSSharpObjectMap *map);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
extern JSBool
|
2010-09-28 02:59:25 -07:00
|
|
|
js_HasOwnPropertyHelper(JSContext *cx, js::LookupPropOp lookup, uintN argc,
|
2010-07-14 23:19:36 -07:00
|
|
|
js::Value *vp);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2008-08-11 17:47:05 -07:00
|
|
|
extern JSBool
|
2010-09-28 02:59:25 -07:00
|
|
|
js_HasOwnProperty(JSContext *cx, js::LookupPropOp lookup, JSObject *obj, jsid id,
|
2009-06-05 12:56:45 -07:00
|
|
|
JSObject **objp, JSProperty **propp);
|
2008-08-11 17:47:05 -07:00
|
|
|
|
2010-05-18 19:21:43 -07:00
|
|
|
extern JSBool
|
2010-07-14 23:19:36 -07:00
|
|
|
js_NewPropertyDescriptorObject(JSContext *cx, jsid id, uintN attrs,
|
|
|
|
const js::Value &getter, const js::Value &setter,
|
|
|
|
const js::Value &value, js::Value *vp);
|
2010-05-18 19:21:43 -07:00
|
|
|
|
2008-08-11 17:47:05 -07:00
|
|
|
extern JSBool
|
2010-07-14 23:19:36 -07:00
|
|
|
js_PropertyIsEnumerable(JSContext *cx, JSObject *obj, jsid id, js::Value *vp);
|
2008-08-11 17:47:05 -07:00
|
|
|
|
2010-05-13 00:45:33 -07:00
|
|
|
#ifdef OLD_GETTER_SETTER_METHODS
|
2010-07-14 23:19:36 -07:00
|
|
|
JS_FRIEND_API(JSBool) js_obj_defineGetter(JSContext *cx, uintN argc, js::Value *vp);
|
|
|
|
JS_FRIEND_API(JSBool) js_obj_defineSetter(JSContext *cx, uintN argc, js::Value *vp);
|
2010-05-13 00:45:33 -07:00
|
|
|
#endif
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
extern JSObject *
|
|
|
|
js_InitObjectClass(JSContext *cx, JSObject *obj);
|
|
|
|
|
2011-01-24 15:32:44 -08:00
|
|
|
namespace js {
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2009-03-04 19:26:16 -08:00
|
|
|
extern JSObject *
|
|
|
|
js_InitClass(JSContext *cx, JSObject *obj, JSObject *parent_proto,
|
2010-07-14 23:19:36 -07:00
|
|
|
js::Class *clasp, js::Native constructor, uintN nargs,
|
2009-03-04 19:26:16 -08:00
|
|
|
JSPropertySpec *ps, JSFunctionSpec *fs,
|
2009-05-05 14:26:06 -07:00
|
|
|
JSPropertySpec *static_ps, JSFunctionSpec *static_fs);
|
2009-03-04 19:26:16 -08:00
|
|
|
|
2009-02-27 22:32:38 -08:00
|
|
|
/*
|
|
|
|
* Select Object.prototype method names shared between jsapi.cpp and jsobj.cpp.
|
|
|
|
*/
|
2007-03-22 10:30:00 -07:00
|
|
|
extern const char js_watch_str[];
|
|
|
|
extern const char js_unwatch_str[];
|
|
|
|
extern const char js_hasOwnProperty_str[];
|
|
|
|
extern const char js_isPrototypeOf_str[];
|
|
|
|
extern const char js_propertyIsEnumerable_str[];
|
2009-10-06 12:35:33 -07:00
|
|
|
|
|
|
|
#ifdef OLD_GETTER_SETTER_METHODS
|
2007-03-22 10:30:00 -07:00
|
|
|
extern const char js_defineGetter_str[];
|
|
|
|
extern const char js_defineSetter_str[];
|
|
|
|
extern const char js_lookupGetter_str[];
|
|
|
|
extern const char js_lookupSetter_str[];
|
2009-10-06 12:35:33 -07:00
|
|
|
#endif
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-05-18 19:21:43 -07:00
|
|
|
extern JSBool
|
|
|
|
js_PopulateObject(JSContext *cx, JSObject *newborn, JSObject *props);
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
/*
|
|
|
|
* Fast access to immutable standard objects (constructors and prototypes).
|
|
|
|
*/
|
|
|
|
extern JSBool
|
|
|
|
js_GetClassObject(JSContext *cx, JSObject *obj, JSProtoKey key,
|
|
|
|
JSObject **objp);
|
|
|
|
|
|
|
|
extern JSBool
|
2010-06-02 20:30:45 -07:00
|
|
|
js_SetClassObject(JSContext *cx, JSObject *obj, JSProtoKey key,
|
|
|
|
JSObject *cobj, JSObject *prototype);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-02-19 09:44:23 -08:00
|
|
|
/*
|
|
|
|
* If protoKey is not JSProto_Null, then clasp is ignored. If protoKey is
|
|
|
|
* JSProto_Null, clasp must non-null.
|
|
|
|
*/
|
2007-03-22 10:30:00 -07:00
|
|
|
extern JSBool
|
2010-07-14 23:19:36 -07:00
|
|
|
js_FindClassObject(JSContext *cx, JSObject *start, JSProtoKey key,
|
|
|
|
js::Value *vp, js::Class *clasp = NULL);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
extern JSObject *
|
2010-07-14 23:19:36 -07:00
|
|
|
js_ConstructObject(JSContext *cx, js::Class *clasp, JSObject *proto,
|
|
|
|
JSObject *parent, uintN argc, js::Value *argv);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-10-04 14:13:33 -07:00
|
|
|
// Specialized call for constructing |this| with a known function callee,
|
|
|
|
// and a known prototype.
|
2010-08-16 12:35:04 -07:00
|
|
|
extern JSObject *
|
2010-10-04 14:13:33 -07:00
|
|
|
js_CreateThisForFunctionWithProto(JSContext *cx, JSObject *callee, JSObject *proto);
|
|
|
|
|
|
|
|
// Specialized call for constructing |this| with a known function callee.
|
|
|
|
extern JSObject *
|
|
|
|
js_CreateThisForFunction(JSContext *cx, JSObject *callee);
|
|
|
|
|
|
|
|
// Generic call for constructing |this|.
|
|
|
|
extern JSObject *
|
|
|
|
js_CreateThis(JSContext *cx, JSObject *callee);
|
2010-08-16 12:35:04 -07:00
|
|
|
|
2008-02-10 17:12:29 -08:00
|
|
|
extern jsid
|
2009-07-11 15:41:32 -07:00
|
|
|
js_CheckForStringIndex(jsid id);
|
2008-02-10 17:12:29 -08:00
|
|
|
|
2009-03-06 16:34:19 -08: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 void
|
|
|
|
js_PurgeScopeChainHelper(JSContext *cx, JSObject *obj, jsid id);
|
|
|
|
|
2010-06-12 09:29:04 -07:00
|
|
|
inline void
|
2009-03-06 16:34:19 -08:00
|
|
|
js_PurgeScopeChain(JSContext *cx, JSObject *obj, jsid id)
|
|
|
|
{
|
2009-08-27 22:53:26 -07:00
|
|
|
if (obj->isDelegate())
|
2009-03-06 16:34:19 -08:00
|
|
|
js_PurgeScopeChainHelper(cx, obj, id);
|
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
/*
|
|
|
|
* Find or create a property named by id in obj's scope, with the given getter
|
|
|
|
* and setter, slot, attributes, and other members.
|
|
|
|
*/
|
2010-08-29 11:57:08 -07:00
|
|
|
extern const js::Shape *
|
2007-03-22 10:30:00 -07:00
|
|
|
js_AddNativeProperty(JSContext *cx, JSObject *obj, jsid id,
|
2011-02-09 11:31:40 -08:00
|
|
|
js::PropertyOp getter, js::StrictPropertyOp setter, uint32 slot,
|
2007-03-22 10:30:00 -07:00
|
|
|
uintN attrs, uintN flags, intN shortid);
|
|
|
|
|
|
|
|
/*
|
2010-08-29 11:57:08 -07:00
|
|
|
* Change shape to have the given attrs, getter, and setter in scope, morphing
|
|
|
|
* it into a potentially new js::Shape. Return a pointer to the changed
|
2007-03-22 10:30:00 -07:00
|
|
|
* or identical property.
|
|
|
|
*/
|
2010-08-29 11:57:08 -07:00
|
|
|
extern const js::Shape *
|
2007-03-22 10:30:00 -07:00
|
|
|
js_ChangeNativePropertyAttrs(JSContext *cx, JSObject *obj,
|
2010-08-29 11:57:08 -07:00
|
|
|
const js::Shape *shape, uintN attrs, uintN mask,
|
2011-02-09 11:31:40 -08:00
|
|
|
js::PropertyOp getter, js::StrictPropertyOp setter);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-03-24 12:36:42 -07:00
|
|
|
extern JSBool
|
2010-07-14 23:19:36 -07:00
|
|
|
js_DefineOwnProperty(JSContext *cx, JSObject *obj, jsid id,
|
|
|
|
const js::Value &descriptor, JSBool *bp);
|
2010-03-24 12:36:42 -07:00
|
|
|
|
2009-05-15 02:43:19 -07:00
|
|
|
/*
|
|
|
|
* Flags for the defineHow parameter of js_DefineNativeProperty.
|
|
|
|
*/
|
|
|
|
const uintN JSDNP_CACHE_RESULT = 1; /* an interpreter call from JSOP_INITPROP */
|
|
|
|
const uintN JSDNP_DONT_PURGE = 2; /* suppress js_PurgeScopeChain */
|
2009-09-03 14:41:19 -07:00
|
|
|
const uintN JSDNP_SET_METHOD = 4; /* js_{DefineNativeProperty,SetPropertyHelper}
|
2010-08-29 11:57:08 -07:00
|
|
|
must pass the js::Shape::METHOD
|
|
|
|
flag on to JSObject::{add,put}Property */
|
2010-04-26 07:06:25 -07:00
|
|
|
const uintN JSDNP_UNQUALIFIED = 8; /* Unqualified property set. Only used in
|
|
|
|
the defineHow argument of
|
|
|
|
js_SetPropertyHelper. */
|
2009-05-15 02:43:19 -07:00
|
|
|
|
2009-08-26 14:28:36 -07:00
|
|
|
/*
|
|
|
|
* On error, return false. On success, if propp is non-null, return true with
|
|
|
|
* obj locked and with a held property in *propp; if propp is null, return true
|
2010-10-22 17:04:22 -07:00
|
|
|
* but release obj's lock first.
|
2009-08-26 14:28:36 -07:00
|
|
|
*/
|
2009-04-30 15:52:13 -07:00
|
|
|
extern JSBool
|
2010-07-14 23:19:36 -07:00
|
|
|
js_DefineNativeProperty(JSContext *cx, JSObject *obj, jsid id, const js::Value &value,
|
2011-02-09 11:31:40 -08:00
|
|
|
js::PropertyOp getter, js::StrictPropertyOp setter, uintN attrs,
|
2009-02-03 23:14:36 -08:00
|
|
|
uintN flags, intN shortid, JSProperty **propp,
|
2009-05-15 02:43:19 -07:00
|
|
|
uintN defineHow = 0);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
/*
|
* Menu of -D flags for enabling instrumentation, as a commented-out CFLAGS += setting for convenient testing. * js_FindProperty and js_LookupPropertyWithFlags return indexes into the scope and prototype chains, respectively, to support internal instrumentation, and to pave the way for the return of the property cache (bug 365851).. * jsutil.[ch] JSBasicStats struct and functions for computing mean/sigma/max and auto-scaling histogram. * JS_SCOPE_DEPTH_METER instrumentation for compile- and run-time scope chain length instrumentation: + At compile time, rt->hostenvScopeDepthStats and rt->lexicalScopeDepthStats meter scope chains passed into the compile and evaluate APIs. + At runtime, rt->protoLookupDepthStats and rt->scopeSearchDepthStats track steps along the prototype and scope chains until the sought-after property is found. * JS_ARENAMETER uses JSBasicStats now. * Added rt->liveScopePropsPreSweep to fix the property tree stats code that rotted when property tree sweeping moved to after the finalization phase. * Un-bitrotted some DEBUG_brendan code, turned some off for myself via XXX. * Mac OS X toolchain requires initialized data shared across dynamic library member files, outlaws common data, so initialize extern metering vars. * Old HASHMETER code in jshash.[ch] is now JS_HASHMETER-controlled and based on JSBasicStats. * DEBUG_scopemeters macro renamed JS_DUMP_SCOPE_METERS; uses JSBasicStats now. * Disentangle DEBUG and DUMP_SCOPE_STATS (now JS_DUMP_PROPTREE_STATS) and fix inconsistent thread safety for liveScopeProps (sometimes atomic-incremented, sometimes runtime-locked). * Compiler-modeled maxScopeDepth will propagate via JSScript to runtime for capability-based, interpreter-inlined cache hit qualifier bits, to bypass scope and prototype chain lookup by optimizing for common monomorphic get, set, and call site referencing a prototype property in a well-named object (no shadowing or mutation in 99.9% of the cases).
2008-01-12 16:31:31 -08:00
|
|
|
* Specialized subroutine that allows caller to preset JSRESOLVE_* flags and
|
|
|
|
* returns the index along the prototype chain in which *propp was found, or
|
|
|
|
* the last index if not found, or -1 on error.
|
2007-03-22 10:30:00 -07:00
|
|
|
*/
|
* Menu of -D flags for enabling instrumentation, as a commented-out CFLAGS += setting for convenient testing. * js_FindProperty and js_LookupPropertyWithFlags return indexes into the scope and prototype chains, respectively, to support internal instrumentation, and to pave the way for the return of the property cache (bug 365851).. * jsutil.[ch] JSBasicStats struct and functions for computing mean/sigma/max and auto-scaling histogram. * JS_SCOPE_DEPTH_METER instrumentation for compile- and run-time scope chain length instrumentation: + At compile time, rt->hostenvScopeDepthStats and rt->lexicalScopeDepthStats meter scope chains passed into the compile and evaluate APIs. + At runtime, rt->protoLookupDepthStats and rt->scopeSearchDepthStats track steps along the prototype and scope chains until the sought-after property is found. * JS_ARENAMETER uses JSBasicStats now. * Added rt->liveScopePropsPreSweep to fix the property tree stats code that rotted when property tree sweeping moved to after the finalization phase. * Un-bitrotted some DEBUG_brendan code, turned some off for myself via XXX. * Mac OS X toolchain requires initialized data shared across dynamic library member files, outlaws common data, so initialize extern metering vars. * Old HASHMETER code in jshash.[ch] is now JS_HASHMETER-controlled and based on JSBasicStats. * DEBUG_scopemeters macro renamed JS_DUMP_SCOPE_METERS; uses JSBasicStats now. * Disentangle DEBUG and DUMP_SCOPE_STATS (now JS_DUMP_PROPTREE_STATS) and fix inconsistent thread safety for liveScopeProps (sometimes atomic-incremented, sometimes runtime-locked). * Compiler-modeled maxScopeDepth will propagate via JSScript to runtime for capability-based, interpreter-inlined cache hit qualifier bits, to bypass scope and prototype chain lookup by optimizing for common monomorphic get, set, and call site referencing a prototype property in a well-named object (no shadowing or mutation in 99.9% of the cases).
2008-01-12 16:31:31 -08:00
|
|
|
extern int
|
2007-03-22 10:30:00 -07:00
|
|
|
js_LookupPropertyWithFlags(JSContext *cx, JSObject *obj, jsid id, uintN flags,
|
|
|
|
JSObject **objp, JSProperty **propp);
|
|
|
|
|
2009-08-06 12:40:51 -07:00
|
|
|
|
2011-02-22 22:25:10 -08:00
|
|
|
extern JS_FRIEND_DATA(js::Class) js_CallClass;
|
|
|
|
extern JS_FRIEND_DATA(js::Class) js_DeclEnvClass;
|
|
|
|
|
|
|
|
namespace js {
|
|
|
|
|
2009-08-06 12:40:51 -07:00
|
|
|
/*
|
|
|
|
* We cache name lookup results only for the global object or for native
|
|
|
|
* non-global objects without prototype or with prototype that never mutates,
|
|
|
|
* see bug 462734 and bug 487039.
|
|
|
|
*/
|
2011-02-22 22:25:10 -08:00
|
|
|
static inline bool
|
|
|
|
IsCacheableNonGlobalScope(JSObject *obj)
|
2009-08-06 12:40:51 -07:00
|
|
|
{
|
2010-03-04 23:52:52 -08:00
|
|
|
JS_ASSERT(obj->getParent());
|
2009-08-06 12:40:51 -07:00
|
|
|
|
2010-07-14 23:19:36 -07:00
|
|
|
js::Class *clasp = obj->getClass();
|
2009-08-06 12:40:51 -07:00
|
|
|
bool cacheable = (clasp == &js_CallClass ||
|
|
|
|
clasp == &js_BlockClass ||
|
|
|
|
clasp == &js_DeclEnvClass);
|
|
|
|
|
2010-06-12 09:29:04 -07:00
|
|
|
JS_ASSERT_IF(cacheable, !obj->getOps()->lookupProperty);
|
2009-08-06 12:40:51 -07:00
|
|
|
return cacheable;
|
|
|
|
}
|
|
|
|
|
2011-02-22 22:25:10 -08:00
|
|
|
}
|
|
|
|
|
2009-04-20 17:00:59 -07:00
|
|
|
/*
|
|
|
|
* If cacheResult is false, return JS_NO_PROP_CACHE_FILL on success.
|
|
|
|
*/
|
2010-03-24 19:20:44 -07:00
|
|
|
extern js::PropertyCacheEntry *
|
2009-04-20 17:00:59 -07:00
|
|
|
js_FindPropertyHelper(JSContext *cx, jsid id, JSBool cacheResult,
|
|
|
|
JSObject **objp, JSObject **pobjp, JSProperty **propp);
|
2008-02-07 15:18:45 -08:00
|
|
|
|
* Menu of -D flags for enabling instrumentation, as a commented-out CFLAGS += setting for convenient testing. * js_FindProperty and js_LookupPropertyWithFlags return indexes into the scope and prototype chains, respectively, to support internal instrumentation, and to pave the way for the return of the property cache (bug 365851).. * jsutil.[ch] JSBasicStats struct and functions for computing mean/sigma/max and auto-scaling histogram. * JS_SCOPE_DEPTH_METER instrumentation for compile- and run-time scope chain length instrumentation: + At compile time, rt->hostenvScopeDepthStats and rt->lexicalScopeDepthStats meter scope chains passed into the compile and evaluate APIs. + At runtime, rt->protoLookupDepthStats and rt->scopeSearchDepthStats track steps along the prototype and scope chains until the sought-after property is found. * JS_ARENAMETER uses JSBasicStats now. * Added rt->liveScopePropsPreSweep to fix the property tree stats code that rotted when property tree sweeping moved to after the finalization phase. * Un-bitrotted some DEBUG_brendan code, turned some off for myself via XXX. * Mac OS X toolchain requires initialized data shared across dynamic library member files, outlaws common data, so initialize extern metering vars. * Old HASHMETER code in jshash.[ch] is now JS_HASHMETER-controlled and based on JSBasicStats. * DEBUG_scopemeters macro renamed JS_DUMP_SCOPE_METERS; uses JSBasicStats now. * Disentangle DEBUG and DUMP_SCOPE_STATS (now JS_DUMP_PROPTREE_STATS) and fix inconsistent thread safety for liveScopeProps (sometimes atomic-incremented, sometimes runtime-locked). * Compiler-modeled maxScopeDepth will propagate via JSScript to runtime for capability-based, interpreter-inlined cache hit qualifier bits, to bypass scope and prototype chain lookup by optimizing for common monomorphic get, set, and call site referencing a prototype property in a well-named object (no shadowing or mutation in 99.9% of the cases).
2008-01-12 16:31:31 -08:00
|
|
|
/*
|
|
|
|
* Return the index along the scope chain in which id was found, or the last
|
|
|
|
* index if not found, or -1 on error.
|
|
|
|
*/
|
2008-02-07 15:18:45 -08:00
|
|
|
extern JS_FRIEND_API(JSBool)
|
2007-03-22 10:30:00 -07:00
|
|
|
js_FindProperty(JSContext *cx, jsid id, JSObject **objp, JSObject **pobjp,
|
|
|
|
JSProperty **propp);
|
|
|
|
|
2008-12-09 08:38:32 -08:00
|
|
|
extern JS_REQUIRES_STACK JSObject *
|
2009-04-20 17:00:59 -07:00
|
|
|
js_FindIdentifierBase(JSContext *cx, JSObject *scopeChain, jsid id);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
extern JSObject *
|
|
|
|
js_FindVariableScope(JSContext *cx, JSFunction **funp);
|
|
|
|
|
2009-09-03 14:41:19 -07:00
|
|
|
/*
|
|
|
|
* JSGET_CACHE_RESULT is the analogue of JSDNP_CACHE_RESULT for js_GetMethod.
|
|
|
|
*
|
|
|
|
* JSGET_METHOD_BARRIER (the default, hence 0 but provided for documentation)
|
|
|
|
* enables a read barrier that preserves standard function object semantics (by
|
|
|
|
* default we assume our caller won't leak a joined callee to script, where it
|
|
|
|
* would create hazardous mutable object sharing as well as observable identity
|
|
|
|
* according to == and ===.
|
|
|
|
*
|
|
|
|
* JSGET_NO_METHOD_BARRIER avoids the performance overhead of the method read
|
|
|
|
* barrier, which is not needed when invoking a lambda that otherwise does not
|
|
|
|
* leak its callee reference (via arguments.callee or its name).
|
|
|
|
*/
|
|
|
|
const uintN JSGET_CACHE_RESULT = 1; // from a caching interpreter opcode
|
|
|
|
const uintN JSGET_METHOD_BARRIER = 0; // get can leak joined function object
|
|
|
|
const uintN JSGET_NO_METHOD_BARRIER = 2; // call to joined function can't leak
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
/*
|
2010-08-29 11:57:08 -07:00
|
|
|
* NB: js_NativeGet and js_NativeSet are called with the scope containing shape
|
2009-04-17 12:41:00 -07:00
|
|
|
* (pobj's scope for Get, obj's for Set) locked, and on successful return, that
|
|
|
|
* scope is again locked. But on failure, both functions return false with the
|
2010-08-29 11:57:08 -07:00
|
|
|
* scope containing shape unlocked.
|
2007-03-22 10:30:00 -07:00
|
|
|
*/
|
|
|
|
extern JSBool
|
2010-08-29 11:57:08 -07:00
|
|
|
js_NativeGet(JSContext *cx, JSObject *obj, JSObject *pobj, const js::Shape *shape, uintN getHow,
|
|
|
|
js::Value *vp);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
extern JSBool
|
2010-08-29 11:57:08 -07:00
|
|
|
js_NativeSet(JSContext *cx, JSObject *obj, const js::Shape *shape, bool added,
|
2011-02-09 11:31:40 -08:00
|
|
|
bool strict, js::Value *vp);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2009-08-26 00:38:13 -07:00
|
|
|
extern JSBool
|
2010-09-16 01:38:19 -07:00
|
|
|
js_GetPropertyHelper(JSContext *cx, JSObject *obj, jsid id, uint32 getHow, js::Value *vp);
|
2010-09-15 21:33:17 -07:00
|
|
|
|
|
|
|
extern bool
|
2010-10-29 10:42:35 -07:00
|
|
|
js_GetPropertyHelperWithShape(JSContext *cx, JSObject *obj, JSObject *receiver, jsid id,
|
|
|
|
uint32 getHow, js::Value *vp,
|
|
|
|
const js::Shape **shapeOut, JSObject **holderOut);
|
2008-02-07 15:18:45 -08:00
|
|
|
|
2010-03-24 12:36:42 -07:00
|
|
|
extern JSBool
|
2010-07-14 23:19:36 -07:00
|
|
|
js_GetOwnPropertyDescriptor(JSContext *cx, JSObject *obj, jsid id, js::Value *vp);
|
2010-03-24 12:36:42 -07:00
|
|
|
|
2009-08-26 00:38:13 -07:00
|
|
|
extern JSBool
|
2010-07-14 23:19:36 -07:00
|
|
|
js_GetMethod(JSContext *cx, JSObject *obj, jsid id, uintN getHow, js::Value *vp);
|
2009-03-14 09:41:47 -07:00
|
|
|
|
2009-04-15 07:09:58 -07:00
|
|
|
/*
|
2010-04-26 07:06:25 -07:00
|
|
|
* Check whether it is OK to assign an undeclared property with name
|
|
|
|
* propname of the global object in the current script on cx. Reports
|
|
|
|
* an error if one needs to be reported (in particular in all cases
|
|
|
|
* when it returns false).
|
2009-04-15 07:09:58 -07:00
|
|
|
*/
|
2009-11-19 12:35:55 -08:00
|
|
|
extern JS_FRIEND_API(bool)
|
2010-07-14 23:19:36 -07:00
|
|
|
js_CheckUndeclaredVarAssignment(JSContext *cx, JSString *propname);
|
2009-04-15 07:09:58 -07:00
|
|
|
|
2009-08-26 00:38:13 -07:00
|
|
|
extern JSBool
|
2009-09-03 14:41:19 -07:00
|
|
|
js_SetPropertyHelper(JSContext *cx, JSObject *obj, jsid id, uintN defineHow,
|
2010-09-15 13:43:55 -07:00
|
|
|
js::Value *vp, JSBool strict);
|
2008-02-07 15:18:45 -08:00
|
|
|
|
2010-06-05 14:24:54 -07:00
|
|
|
/*
|
|
|
|
* Change attributes for the given native property. The caller must ensure
|
|
|
|
* that obj is locked and this function always unlocks obj on return.
|
|
|
|
*/
|
2007-03-22 10:30:00 -07:00
|
|
|
extern JSBool
|
2010-08-29 11:57:08 -07:00
|
|
|
js_SetNativeAttributes(JSContext *cx, JSObject *obj, js::Shape *shape,
|
2010-06-05 14:24:54 -07:00
|
|
|
uintN attrs);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-07-07 00:53:47 -07:00
|
|
|
namespace js {
|
|
|
|
|
2010-11-02 17:36:26 -07:00
|
|
|
/*
|
|
|
|
* If obj has a data property methodid which is a function object for the given
|
|
|
|
* native, return that function object. Otherwise, return NULL.
|
|
|
|
*/
|
|
|
|
extern JSObject *
|
|
|
|
HasNativeMethod(JSObject *obj, jsid methodid, Native native);
|
|
|
|
|
|
|
|
extern bool
|
2010-07-14 23:19:36 -07:00
|
|
|
DefaultValue(JSContext *cx, JSObject *obj, JSType hint, Value *vp);
|
2010-07-07 00:53:47 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
extern JSBool
|
2010-06-17 05:32:26 -07:00
|
|
|
CheckAccess(JSContext *cx, JSObject *obj, jsid id, JSAccessMode mode,
|
2010-07-14 23:19:36 -07:00
|
|
|
js::Value *vp, uintN *attrsp);
|
2010-06-17 05:32:26 -07:00
|
|
|
|
2010-06-12 09:29:04 -07:00
|
|
|
} /* namespace js */
|
2010-02-22 16:30:22 -08:00
|
|
|
|
2010-07-14 23:19:36 -07:00
|
|
|
extern bool
|
|
|
|
js_IsDelegate(JSContext *cx, JSObject *obj, const js::Value &v);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-02-19 09:44:23 -08:00
|
|
|
/*
|
|
|
|
* If protoKey is not JSProto_Null, then clasp is ignored. If protoKey is
|
|
|
|
* JSProto_Null, clasp must non-null.
|
|
|
|
*/
|
2010-03-17 12:55:45 -07:00
|
|
|
extern JS_FRIEND_API(JSBool)
|
2010-02-19 09:44:23 -08:00
|
|
|
js_GetClassPrototype(JSContext *cx, JSObject *scope, JSProtoKey protoKey,
|
2010-07-14 23:19:36 -07:00
|
|
|
JSObject **protop, js::Class *clasp = NULL);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
extern JSBool
|
|
|
|
js_SetClassPrototype(JSContext *cx, JSObject *ctor, JSObject *proto,
|
|
|
|
uintN attrs);
|
|
|
|
|
2007-06-14 00:07:01 -07:00
|
|
|
/*
|
|
|
|
* Wrap boolean, number or string as Boolean, Number or String object.
|
|
|
|
* *vp must not be an object, null or undefined.
|
|
|
|
*/
|
|
|
|
extern JSBool
|
2010-07-14 23:19:36 -07:00
|
|
|
js_PrimitiveToObject(JSContext *cx, js::Value *vp);
|
2007-06-14 00:07:01 -07:00
|
|
|
|
2010-07-14 23:19:36 -07:00
|
|
|
/*
|
|
|
|
* v and vp may alias. On successful return, vp->isObjectOrNull(). If vp is not
|
|
|
|
* rooted, the caller must root vp before the next possible GC.
|
|
|
|
*/
|
2007-03-22 10:30:00 -07:00
|
|
|
extern JSBool
|
2010-07-14 23:19:36 -07:00
|
|
|
js_ValueToObjectOrNull(JSContext *cx, const js::Value &v, JSObject **objp);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2011-01-26 13:37:45 -08:00
|
|
|
namespace js {
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Invokes the ES5 ToObject algorithm on *vp, writing back the object to vp.
|
|
|
|
* If *vp might already be an object, use ToObject.
|
|
|
|
*/
|
|
|
|
extern JSObject *
|
|
|
|
ToObjectSlow(JSContext *cx, js::Value *vp);
|
|
|
|
|
|
|
|
JS_ALWAYS_INLINE JSObject *
|
|
|
|
ToObject(JSContext *cx, js::Value *vp)
|
|
|
|
{
|
|
|
|
if (vp->isObject())
|
|
|
|
return &vp->toObject();
|
|
|
|
return ToObjectSlow(cx, vp);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2010-07-14 23:19:36 -07:00
|
|
|
/*
|
|
|
|
* v and vp may alias. On successful return, vp->isObject(). If vp is not
|
|
|
|
* rooted, the caller must root vp before the next possible GC.
|
|
|
|
*/
|
2007-03-22 10:30:00 -07:00
|
|
|
extern JSObject *
|
2010-07-14 23:19:36 -07:00
|
|
|
js_ValueToNonNullObject(JSContext *cx, const js::Value &v);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
extern JSBool
|
2010-07-14 23:19:36 -07:00
|
|
|
js_TryValueOf(JSContext *cx, JSObject *obj, JSType type, js::Value *rval);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
extern JSBool
|
|
|
|
js_TryMethod(JSContext *cx, JSObject *obj, JSAtom *atom,
|
2010-07-14 23:19:36 -07:00
|
|
|
uintN argc, js::Value *argv, js::Value *rval);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
extern JSBool
|
|
|
|
js_XDRObject(JSXDRState *xdr, JSObject **objp);
|
|
|
|
|
2007-04-16 23:53:37 -07:00
|
|
|
extern void
|
|
|
|
js_TraceObject(JSTracer *trc, JSObject *obj);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2008-02-18 13:01:47 -08:00
|
|
|
extern void
|
|
|
|
js_PrintObjectSlotName(JSTracer *trc, char *buf, size_t bufsize);
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
extern void
|
2010-06-12 09:29:04 -07:00
|
|
|
js_ClearNative(JSContext *cx, JSObject *obj);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2009-08-27 22:53:26 -07:00
|
|
|
extern bool
|
2010-07-14 23:19:36 -07:00
|
|
|
js_GetReservedSlot(JSContext *cx, JSObject *obj, uint32 index, js::Value *vp);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-06-07 18:35:58 -07:00
|
|
|
extern bool
|
2010-07-14 23:19:36 -07:00
|
|
|
js_SetReservedSlot(JSContext *cx, JSObject *obj, uint32 index, const js::Value &v);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
extern JSBool
|
|
|
|
js_CheckPrincipalsAccess(JSContext *cx, JSObject *scopeobj,
|
|
|
|
JSPrincipals *principals, JSAtom *caller);
|
2007-11-19 09:15:45 -08:00
|
|
|
|
2010-03-08 00:24:50 -08:00
|
|
|
/* For CSP -- checks if eval() and friends are allowed to run. */
|
|
|
|
extern JSBool
|
2011-01-22 14:28:37 -08:00
|
|
|
js_CheckContentSecurityPolicy(JSContext *cx, JSObject *scopeObj);
|
2010-03-08 00:24:50 -08:00
|
|
|
|
2008-03-06 14:52:58 -08:00
|
|
|
/* NB: Infallible. */
|
|
|
|
extern const char *
|
|
|
|
js_ComputeFilename(JSContext *cx, JSStackFrame *caller,
|
|
|
|
JSPrincipals *principals, uintN *linenop);
|
2008-08-11 17:47:05 -07:00
|
|
|
|
2009-12-08 17:00:42 -08:00
|
|
|
extern JSBool
|
2009-04-22 03:39:08 -07:00
|
|
|
js_ReportGetterOnlyAssignment(JSContext *cx);
|
|
|
|
|
|
|
|
extern JS_FRIEND_API(JSBool)
|
2011-02-09 11:31:40 -08:00
|
|
|
js_GetterOnlyPropertyStub(JSContext *cx, JSObject *obj, jsid id, JSBool strict, jsval *vp);
|
2009-04-22 03:39:08 -07:00
|
|
|
|
2008-09-25 09:29:12 -07:00
|
|
|
#ifdef DEBUG
|
|
|
|
JS_FRIEND_API(void) js_DumpChars(const jschar *s, size_t n);
|
|
|
|
JS_FRIEND_API(void) js_DumpString(JSString *str);
|
|
|
|
JS_FRIEND_API(void) js_DumpAtom(JSAtom *atom);
|
|
|
|
JS_FRIEND_API(void) js_DumpObject(JSObject *obj);
|
2010-07-14 23:19:36 -07:00
|
|
|
JS_FRIEND_API(void) js_DumpValue(const js::Value &val);
|
|
|
|
JS_FRIEND_API(void) js_DumpId(jsid id);
|
2010-06-04 11:15:23 -07:00
|
|
|
JS_FRIEND_API(void) js_DumpStackFrame(JSContext *cx, JSStackFrame *start = NULL);
|
2008-09-25 09:29:12 -07:00
|
|
|
#endif
|
|
|
|
|
2009-07-05 21:42:13 -07:00
|
|
|
extern uintN
|
|
|
|
js_InferFlags(JSContext *cx, uintN defaultFlags);
|
|
|
|
|
2009-07-29 09:58:19 -07:00
|
|
|
/* Object constructor native. Exposed only so the JIT can know its address. */
|
|
|
|
JSBool
|
2010-08-03 12:20:48 -07:00
|
|
|
js_Object(JSContext *cx, uintN argc, js::Value *vp);
|
2009-07-29 09:58:19 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-06-17 15:23:17 -07:00
|
|
|
namespace js {
|
|
|
|
|
|
|
|
extern bool
|
|
|
|
SetProto(JSContext *cx, JSObject *obj, JSObject *proto, bool checkForCycles);
|
|
|
|
|
2010-06-23 14:35:10 -07:00
|
|
|
extern JSString *
|
|
|
|
obj_toStringHelper(JSContext *cx, JSObject *obj);
|
|
|
|
|
2010-10-21 14:31:29 -07:00
|
|
|
enum EvalType { INDIRECT_EVAL, DIRECT_EVAL };
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Common code implementing direct and indirect eval.
|
|
|
|
*
|
|
|
|
* Evaluate vp[2], if it is a string, in the context of the given calling
|
|
|
|
* frame, with the provided scope chain, with the semantics of either a direct
|
|
|
|
* or indirect eval (see ES5 10.4.2). If this is an indirect eval, scopeobj
|
|
|
|
* must be a global object.
|
|
|
|
*
|
|
|
|
* On success, store the completion value in *vp and return true.
|
|
|
|
*/
|
|
|
|
extern bool
|
|
|
|
EvalKernel(JSContext *cx, uintN argc, js::Value *vp, EvalType evalType, JSStackFrame *caller,
|
|
|
|
JSObject *scopeobj);
|
|
|
|
|
2011-01-26 19:19:33 -08:00
|
|
|
extern JS_FRIEND_API(bool)
|
2010-10-07 13:59:56 -07:00
|
|
|
IsBuiltinEvalFunction(JSFunction *fun);
|
|
|
|
|
2010-06-23 14:35:10 -07:00
|
|
|
}
|
2011-01-18 14:25:46 -08:00
|
|
|
|
|
|
|
#ifdef JS_OBJ_UNDEFD_MOZALLOC_WRAPPERS
|
|
|
|
# include "mozilla/mozalloc_macro_wrappers.h"
|
|
|
|
#endif
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
#endif /* jsobj_h___ */
|