2007-03-22 10:30:00 -07:00
|
|
|
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
2010-05-22 17:09:52 -07:00
|
|
|
* vim: set ts=4 sw=4 et tw=79 ft=cpp:
|
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 jsscript_h___
|
|
|
|
#define jsscript_h___
|
|
|
|
/*
|
|
|
|
* JS script descriptor.
|
|
|
|
*/
|
|
|
|
#include "jsatom.h"
|
|
|
|
#include "jsprvtd.h"
|
2009-02-18 16:31:09 -08:00
|
|
|
#include "jsdbgapi.h"
|
2010-08-05 17:15:49 -07:00
|
|
|
#include "jsclist.h"
|
2010-10-29 08:05:55 -07:00
|
|
|
#include "jsinfer.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
/*
|
2008-06-03 14:48:47 -07:00
|
|
|
* Type of try note associated with each catch or finally block, and also with
|
|
|
|
* for-in loops.
|
2007-05-24 00:51:46 -07:00
|
|
|
*/
|
|
|
|
typedef enum JSTryNoteKind {
|
2008-10-09 10:10:17 -07:00
|
|
|
JSTRY_CATCH,
|
|
|
|
JSTRY_FINALLY,
|
|
|
|
JSTRY_ITER
|
2007-05-24 00:51:46 -07:00
|
|
|
} JSTryNoteKind;
|
|
|
|
|
2010-07-02 13:37:39 -07:00
|
|
|
namespace js {
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Indicates a location in the stack that an upvar value can be retrieved from
|
|
|
|
* as a two tuple of (level, slot).
|
|
|
|
*
|
|
|
|
* Some existing client code uses the level value as a delta, or level "skip"
|
|
|
|
* quantity. We could probably document that through use of more types at some
|
|
|
|
* point in the future.
|
|
|
|
*
|
|
|
|
* Existing XDR code wants this to be backed by a 32b integer for serialization,
|
|
|
|
* so we oblige.
|
|
|
|
*
|
|
|
|
* TODO: consider giving more bits to the slot value and takings ome from the level.
|
|
|
|
*/
|
2010-12-29 23:46:50 -08:00
|
|
|
class UpvarCookie
|
2010-07-02 13:37:39 -07:00
|
|
|
{
|
|
|
|
uint32 value;
|
|
|
|
|
|
|
|
static const uint32 FREE_VALUE = 0xfffffffful;
|
|
|
|
|
2010-07-26 06:35:38 -07:00
|
|
|
void checkInvariants() {
|
|
|
|
JS_STATIC_ASSERT(sizeof(UpvarCookie) == sizeof(uint32));
|
|
|
|
JS_STATIC_ASSERT(UPVAR_LEVEL_LIMIT < FREE_LEVEL);
|
|
|
|
}
|
|
|
|
|
2010-07-02 13:37:39 -07:00
|
|
|
public:
|
|
|
|
/*
|
|
|
|
* All levels above-and-including FREE_LEVEL are reserved so that
|
|
|
|
* FREE_VALUE can be used as a special value.
|
|
|
|
*/
|
|
|
|
static const uint16 FREE_LEVEL = 0x3fff;
|
2010-07-26 06:35:38 -07:00
|
|
|
|
|
|
|
/*
|
|
|
|
* If a function has a higher static level than this limit, we will not
|
|
|
|
* optimize it using UPVAR opcodes.
|
|
|
|
*/
|
|
|
|
static const uint16 UPVAR_LEVEL_LIMIT = 16;
|
2010-07-02 13:37:39 -07:00
|
|
|
static const uint16 CALLEE_SLOT = 0xffff;
|
|
|
|
static bool isLevelReserved(uint16 level) { return level >= FREE_LEVEL; }
|
|
|
|
|
|
|
|
bool isFree() const { return value == FREE_VALUE; }
|
|
|
|
uint32 asInteger() const { return value; }
|
|
|
|
/* isFree check should be performed before using these accessors. */
|
2010-09-02 14:50:44 -07:00
|
|
|
uint16 level() const { JS_ASSERT(!isFree()); return uint16(value >> 16); }
|
2010-07-26 12:04:53 -07:00
|
|
|
uint16 slot() const { JS_ASSERT(!isFree()); return uint16(value); }
|
2010-07-02 13:37:39 -07:00
|
|
|
|
|
|
|
void set(const UpvarCookie &other) { set(other.level(), other.slot()); }
|
|
|
|
void set(uint16 newLevel, uint16 newSlot) { value = (uint32(newLevel) << 16) | newSlot; }
|
|
|
|
void makeFree() { set(0xffff, 0xffff); JS_ASSERT(isFree()); }
|
2010-07-05 20:14:42 -07:00
|
|
|
void fromInteger(uint32 u32) { value = u32; }
|
2010-07-02 13:37:39 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2007-05-24 00:51:46 -07:00
|
|
|
/*
|
|
|
|
* Exception handling record.
|
2007-03-22 10:30:00 -07:00
|
|
|
*/
|
|
|
|
struct JSTryNote {
|
2007-05-24 00:51:46 -07:00
|
|
|
uint8 kind; /* one of JSTryNoteKind */
|
|
|
|
uint8 padding; /* explicit padding on uint16 boundary */
|
|
|
|
uint16 stackDepth; /* stack depth upon exception handler entry */
|
2007-07-02 05:13:23 -07:00
|
|
|
uint32 start; /* start of the try statement or for-in loop
|
|
|
|
relative to script->main */
|
|
|
|
uint32 length; /* length of the try statement or for-in loop */
|
2007-03-22 10:30:00 -07:00
|
|
|
};
|
|
|
|
|
2007-05-24 00:51:46 -07:00
|
|
|
typedef struct JSTryNoteArray {
|
2007-07-08 02:03:34 -07:00
|
|
|
JSTryNote *vector; /* array of indexed try notes */
|
2008-05-28 19:07:32 -07:00
|
|
|
uint32 length; /* count of indexed try notes */
|
2007-05-24 00:51:46 -07:00
|
|
|
} JSTryNoteArray;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2007-07-08 02:03:34 -07:00
|
|
|
typedef struct JSObjectArray {
|
|
|
|
JSObject **vector; /* array of indexed objects */
|
2008-05-28 19:07:32 -07:00
|
|
|
uint32 length; /* count of indexed objects */
|
2007-07-08 02:03:34 -07:00
|
|
|
} JSObjectArray;
|
|
|
|
|
2008-08-21 03:47:33 -07:00
|
|
|
typedef struct JSUpvarArray {
|
2010-07-02 13:37:39 -07:00
|
|
|
js::UpvarCookie *vector; /* array of indexed upvar cookies */
|
2008-08-21 03:47:33 -07:00
|
|
|
uint32 length; /* count of indexed upvar cookies */
|
|
|
|
} JSUpvarArray;
|
|
|
|
|
2010-07-14 23:19:36 -07:00
|
|
|
typedef struct JSConstArray {
|
|
|
|
js::Value *vector; /* array of indexed constant values */
|
|
|
|
uint32 length;
|
|
|
|
} JSConstArray;
|
|
|
|
|
2010-11-16 15:34:24 -08:00
|
|
|
struct JSArenaPool;
|
|
|
|
|
2010-05-22 15:38:04 -07:00
|
|
|
namespace js {
|
|
|
|
|
|
|
|
struct GlobalSlotArray {
|
|
|
|
struct Entry {
|
|
|
|
uint32 atomIndex; /* index into atom table */
|
|
|
|
uint32 slot; /* global obj slot number */
|
|
|
|
};
|
|
|
|
Entry *vector;
|
|
|
|
uint32 length;
|
|
|
|
};
|
|
|
|
|
2011-01-03 13:25:17 -08:00
|
|
|
struct Shape;
|
2010-11-16 15:34:24 -08:00
|
|
|
|
|
|
|
enum BindingKind { NONE, ARGUMENT, VARIABLE, CONSTANT, UPVAR };
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Formal parameters, local variables, and upvars are stored in a shape tree
|
|
|
|
* path encapsulated within this class. This class represents bindings for
|
|
|
|
* both function and top-level scripts (the latter is needed to track names in
|
|
|
|
* strict mode eval code, to give such code its own lexical environment).
|
|
|
|
*/
|
|
|
|
class Bindings {
|
|
|
|
js::Shape *lastBinding;
|
|
|
|
uint16 nargs;
|
|
|
|
uint16 nvars;
|
|
|
|
uint16 nupvars;
|
2011-03-15 12:18:36 -07:00
|
|
|
bool hasExtensibleParents;
|
2010-11-16 15:34:24 -08:00
|
|
|
|
|
|
|
public:
|
2011-03-11 16:29:38 -08:00
|
|
|
inline Bindings(JSContext *cx);
|
2010-11-16 15:34:24 -08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Transfers ownership of bindings data from bindings into this fresh
|
|
|
|
* Bindings instance. Once such a transfer occurs, the old bindings must
|
|
|
|
* not be used again.
|
|
|
|
*/
|
|
|
|
inline void transfer(JSContext *cx, Bindings *bindings);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Clones bindings data from bindings, which must be immutable, into this
|
|
|
|
* fresh Bindings instance. A Bindings instance may be cloned multiple
|
|
|
|
* times.
|
|
|
|
*/
|
|
|
|
inline void clone(JSContext *cx, Bindings *bindings);
|
|
|
|
|
|
|
|
uint16 countArgs() const { return nargs; }
|
|
|
|
uint16 countVars() const { return nvars; }
|
|
|
|
uint16 countUpvars() const { return nupvars; }
|
|
|
|
|
|
|
|
uintN countArgsAndVars() const { return nargs + nvars; }
|
|
|
|
|
|
|
|
uintN countLocalNames() const { return nargs + nvars + nupvars; }
|
|
|
|
|
|
|
|
bool hasUpvars() const { return nupvars > 0; }
|
|
|
|
bool hasLocalNames() const { return countLocalNames() > 0; }
|
|
|
|
|
2011-03-11 16:29:38 -08:00
|
|
|
/* Ensure these bindings have a shape lineage. */
|
|
|
|
inline bool ensureShape(JSContext *cx);
|
|
|
|
|
2010-11-16 15:34:24 -08:00
|
|
|
/* Returns the shape lineage generated for these bindings. */
|
2011-03-15 12:18:36 -07:00
|
|
|
inline js::Shape *lastShape() const;
|
2010-11-16 15:34:24 -08:00
|
|
|
|
2010-12-30 14:40:21 -08:00
|
|
|
enum {
|
2010-12-29 23:46:50 -08:00
|
|
|
/*
|
|
|
|
* A script may have no more than this many arguments, variables, or
|
|
|
|
* upvars.
|
|
|
|
*/
|
|
|
|
BINDING_COUNT_LIMIT = 0xFFFF
|
2010-12-30 14:40:21 -08:00
|
|
|
};
|
|
|
|
|
2010-11-16 15:34:24 -08:00
|
|
|
/*
|
|
|
|
* Add a local binding for the given name, of the given type, for the code
|
|
|
|
* being compiled. If fun is non-null, this binding set is being created
|
|
|
|
* for that function, so adjust corresponding metadata in that function
|
|
|
|
* while adding. Otherwise this set must correspond to a top-level script.
|
|
|
|
*
|
|
|
|
* A binding may be added twice with different kinds; the last one for a
|
|
|
|
* given name prevails. (We preserve both bindings for the decompiler,
|
|
|
|
* which must deal with such cases.) Pass null for name when indicating a
|
|
|
|
* destructuring argument. Return true on success.
|
|
|
|
*
|
|
|
|
* The parser builds shape paths for functions, usable by Call objects at
|
2010-12-29 23:46:50 -08:00
|
|
|
* runtime, by calling an "add" method. All ARGUMENT bindings must be added
|
|
|
|
* before before any VARIABLE or CONSTANT bindings, which themselves must
|
|
|
|
* be added before all UPVAR bindings.
|
2010-11-16 15:34:24 -08:00
|
|
|
*/
|
|
|
|
bool add(JSContext *cx, JSAtom *name, BindingKind kind);
|
|
|
|
|
|
|
|
/* Convenience specializations. */
|
|
|
|
bool addVariable(JSContext *cx, JSAtom *name) {
|
|
|
|
return add(cx, name, VARIABLE);
|
|
|
|
}
|
|
|
|
bool addConstant(JSContext *cx, JSAtom *name) {
|
|
|
|
return add(cx, name, CONSTANT);
|
|
|
|
}
|
|
|
|
bool addUpvar(JSContext *cx, JSAtom *name) {
|
|
|
|
return add(cx, name, UPVAR);
|
|
|
|
}
|
|
|
|
bool addArgument(JSContext *cx, JSAtom *name, uint16 *slotp) {
|
|
|
|
JS_ASSERT(name != NULL); /* not destructuring */
|
|
|
|
*slotp = nargs;
|
|
|
|
return add(cx, name, ARGUMENT);
|
|
|
|
}
|
|
|
|
bool addDestructuring(JSContext *cx, uint16 *slotp) {
|
|
|
|
*slotp = nargs;
|
|
|
|
return add(cx, NULL, ARGUMENT);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Look up an argument or variable name, returning its kind when found or
|
|
|
|
* NONE when no such name exists. When indexp is not null and the name
|
|
|
|
* exists, *indexp will receive the index of the corresponding argument or
|
|
|
|
* variable.
|
|
|
|
*/
|
2011-01-03 17:14:55 -08:00
|
|
|
BindingKind lookup(JSContext *cx, JSAtom *name, uintN *indexp) const;
|
2010-11-16 15:34:24 -08:00
|
|
|
|
|
|
|
/* Convenience method to check for any binding for a name. */
|
2011-01-03 17:14:55 -08:00
|
|
|
bool hasBinding(JSContext *cx, JSAtom *name) const {
|
|
|
|
return lookup(cx, name, NULL) != NONE;
|
2010-11-16 15:34:24 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2011-06-24 18:03:04 -07:00
|
|
|
* This method returns the local variable, argument, etc. names used by a
|
|
|
|
* script. This function must be called only when hasLocalNames().
|
2010-11-16 15:34:24 -08:00
|
|
|
*
|
2011-06-24 18:03:04 -07:00
|
|
|
* The elements of the vector with index less than nargs correspond to the
|
|
|
|
* the names of arguments. An index >= nargs addresses a var binding.
|
|
|
|
* The name at an element will be null when the element is for an argument
|
2010-11-16 15:34:24 -08:00
|
|
|
* corresponding to a destructuring pattern.
|
|
|
|
*/
|
2011-06-24 18:03:04 -07:00
|
|
|
bool getLocalNameArray(JSContext *cx, Vector<JSAtom *> *namesp);
|
2010-11-16 15:34:24 -08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Returns the slot where the sharp array is stored, or a value < 0 if no
|
|
|
|
* sharps are present or in case of failure.
|
|
|
|
*/
|
|
|
|
int sharpSlotBase(JSContext *cx);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Protect stored bindings from mutation. Subsequent attempts to add
|
|
|
|
* bindings will copy the existing bindings before adding to them, allowing
|
|
|
|
* the original bindings to be safely shared.
|
|
|
|
*/
|
|
|
|
void makeImmutable();
|
|
|
|
|
2011-03-15 12:18:36 -07:00
|
|
|
/*
|
|
|
|
* Sometimes call objects and run-time block objects need unique shapes, but
|
|
|
|
* sometimes they don't.
|
|
|
|
*
|
|
|
|
* Property cache entries only record the shapes of the first and last
|
|
|
|
* objects along the search path, so if the search traverses more than those
|
|
|
|
* two objects, then those first and last shapes must determine the shapes
|
|
|
|
* of everything else along the path. The js_PurgeScopeChain stuff takes
|
|
|
|
* care of making this work, but that suffices only because we require that
|
|
|
|
* start points with the same shape have the same successor object in the
|
|
|
|
* search path --- a cache hit means the starting shapes were equal, which
|
|
|
|
* means the seach path tail (everything but the first object in the path)
|
|
|
|
* was shared, which in turn means the effects of a purge will be seen by
|
|
|
|
* all affected starting search points.
|
|
|
|
*
|
|
|
|
* For call and run-time block objects, the "successor object" is the scope
|
|
|
|
* chain parent. Unlike prototype objects (of which there are usually few),
|
|
|
|
* scope chain parents are created frequently (possibly on every call), so
|
|
|
|
* following the shape-implies-parent rule blindly would lead one to give
|
|
|
|
* every call and block its own shape.
|
|
|
|
*
|
|
|
|
* In many cases, however, it's not actually necessary to give call and
|
|
|
|
* block objects their own shapes, and we can do better. If the code will
|
|
|
|
* always be used with the same global object, and none of the enclosing
|
|
|
|
* call objects could have bindings added to them at runtime (by direct eval
|
|
|
|
* calls or function statements), then we can use a fixed set of shapes for
|
|
|
|
* those objects. You could think of the shapes in the functions' bindings
|
|
|
|
* and compile-time blocks as uniquely identifying the global object(s) at
|
|
|
|
* the end of the scope chain.
|
|
|
|
*
|
|
|
|
* (In fact, some JSScripts we do use against multiple global objects (see
|
|
|
|
* bug 618497), and using the fixed shapes isn't sound there.)
|
2011-06-16 02:42:35 -07:00
|
|
|
*
|
2011-03-15 12:18:36 -07:00
|
|
|
* In deciding whether a call or block has any extensible parents, we
|
|
|
|
* actually only need to consider enclosing calls; blocks are never
|
|
|
|
* extensible, and the other sorts of objects that appear in the scope
|
|
|
|
* chains ('with' blocks, say) are not CacheableNonGlobalScopes.
|
|
|
|
*
|
|
|
|
* If the hasExtensibleParents flag is set, then Call objects created for
|
|
|
|
* the function this Bindings describes need unique shapes. If the flag is
|
|
|
|
* clear, then we can use lastBinding's shape.
|
|
|
|
*
|
|
|
|
* For blocks, we set the the OWN_SHAPE flag on the compiler-generated
|
|
|
|
* blocksto indicate that their clones need unique shapes.
|
|
|
|
*/
|
|
|
|
void setExtensibleParents() { hasExtensibleParents = true; }
|
|
|
|
bool extensibleParents() const { return hasExtensibleParents; }
|
|
|
|
|
2010-11-16 15:34:24 -08:00
|
|
|
/*
|
|
|
|
* These methods provide direct access to the shape path normally
|
|
|
|
* encapsulated by js::Bindings. These methods may be used to make a
|
|
|
|
* Shape::Range for iterating over the relevant shapes from youngest to
|
|
|
|
* oldest (i.e., last or right-most to first or left-most in source order).
|
|
|
|
*
|
|
|
|
* Sometimes iteration order must be from oldest to youngest, however. For
|
2011-06-24 18:03:04 -07:00
|
|
|
* such cases, use js::Bindings::getLocalNameArray.
|
2010-11-16 15:34:24 -08:00
|
|
|
*/
|
|
|
|
const js::Shape *lastArgument() const;
|
|
|
|
const js::Shape *lastVariable() const;
|
|
|
|
const js::Shape *lastUpvar() const;
|
|
|
|
|
|
|
|
void trace(JSTracer *trc);
|
|
|
|
};
|
|
|
|
|
2010-05-22 15:38:04 -07:00
|
|
|
} /* namespace js */
|
|
|
|
|
2007-07-08 02:03:34 -07:00
|
|
|
#define JS_OBJECT_ARRAY_SIZE(length) \
|
|
|
|
(offsetof(JSObjectArray, vector) + sizeof(JSObject *) * (length))
|
|
|
|
|
2008-02-07 15:18:45 -08:00
|
|
|
#if defined DEBUG && defined JS_THREADSAFE
|
|
|
|
# define CHECK_SCRIPT_OWNER 1
|
|
|
|
#endif
|
|
|
|
|
2010-05-22 17:09:52 -07:00
|
|
|
#ifdef JS_METHODJIT
|
|
|
|
namespace JSC {
|
|
|
|
class ExecutablePool;
|
|
|
|
}
|
2010-10-04 14:13:33 -07:00
|
|
|
|
|
|
|
#define JS_UNJITTABLE_SCRIPT (reinterpret_cast<void*>(1))
|
|
|
|
|
|
|
|
enum JITScriptStatus {
|
|
|
|
JITScript_None,
|
|
|
|
JITScript_Invalid,
|
|
|
|
JITScript_Valid
|
|
|
|
};
|
|
|
|
|
2011-07-05 16:52:39 -07:00
|
|
|
namespace js { namespace mjit { struct JITScript; } }
|
2010-05-22 17:09:52 -07:00
|
|
|
#endif
|
|
|
|
|
2011-07-05 16:52:39 -07:00
|
|
|
namespace js { namespace analyze { class ScriptAnalysis; } }
|
|
|
|
|
2011-05-10 11:26:39 -07:00
|
|
|
class JSPCCounters {
|
|
|
|
size_t numBytecodes;
|
2011-08-05 05:51:14 -07:00
|
|
|
double *counts;
|
2011-05-10 11:26:39 -07:00
|
|
|
|
|
|
|
public:
|
2011-08-05 05:51:14 -07:00
|
|
|
|
|
|
|
enum {
|
|
|
|
INTERP = 0,
|
|
|
|
TRACEJIT = 1,
|
|
|
|
METHODJIT = 2,
|
|
|
|
METHODJIT_STUBS = 3,
|
|
|
|
METHODJIT_CODE = 4,
|
|
|
|
METHODJIT_PICS = 5,
|
|
|
|
COUNT = 6,
|
|
|
|
};
|
|
|
|
|
2011-05-10 11:26:39 -07:00
|
|
|
JSPCCounters() : numBytecodes(0), counts(NULL) {
|
|
|
|
}
|
|
|
|
|
|
|
|
~JSPCCounters() {
|
2011-06-06 16:48:20 -07:00
|
|
|
JS_ASSERT(!counts);
|
2011-05-10 11:26:39 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
bool init(JSContext *cx, size_t numBytecodes);
|
2011-06-06 16:48:20 -07:00
|
|
|
void destroy(JSContext *cx);
|
2011-05-10 11:26:39 -07:00
|
|
|
|
|
|
|
// Boolean conversion, for 'if (counters) ...'
|
|
|
|
operator void*() const {
|
|
|
|
return counts;
|
|
|
|
}
|
|
|
|
|
2011-08-05 05:51:14 -07:00
|
|
|
double *get(int runmode) {
|
|
|
|
JS_ASSERT(runmode >= 0 && runmode < COUNT);
|
2011-05-10 11:26:39 -07:00
|
|
|
return counts ? &counts[numBytecodes * runmode] : NULL;
|
|
|
|
}
|
|
|
|
|
2011-08-05 05:51:14 -07:00
|
|
|
double& get(int runmode, size_t offset) {
|
2011-05-10 11:26:39 -07:00
|
|
|
JS_ASSERT(offset < numBytecodes);
|
|
|
|
JS_ASSERT(counts);
|
|
|
|
return get(runmode)[offset];
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2011-07-19 14:21:58 -07:00
|
|
|
static const uint32 JS_SCRIPT_COOKIE = 0xc00cee;
|
|
|
|
|
2011-07-25 18:05:05 -07:00
|
|
|
static JSObject * const JS_NEW_SCRIPT = (JSObject *)0x12345678;
|
|
|
|
static JSObject * const JS_CACHED_SCRIPT = (JSObject *)0x12341234;
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
struct JSScript {
|
2010-09-13 22:33:44 -07:00
|
|
|
/*
|
|
|
|
* Two successively less primitive ways to make a new JSScript. The first
|
|
|
|
* does *not* call a non-null cx->runtime->newScriptHook -- only the second,
|
|
|
|
* NewScriptFromCG, calls this optional debugger hook.
|
|
|
|
*
|
|
|
|
* The NewScript function can't know whether the script it creates belongs
|
|
|
|
* to a function, or is top-level or eval code, but the debugger wants access
|
|
|
|
* to the newly made script's function, if any -- so callers of NewScript
|
|
|
|
* are responsible for notifying the debugger after successfully creating any
|
|
|
|
* kind (function or other) of new JSScript.
|
|
|
|
*/
|
|
|
|
static JSScript *NewScript(JSContext *cx, uint32 length, uint32 nsrcnotes, uint32 natoms,
|
|
|
|
uint32 nobjects, uint32 nupvars, uint32 nregexps,
|
|
|
|
uint32 ntrynotes, uint32 nconsts, uint32 nglobals,
|
2011-05-14 05:45:13 -07:00
|
|
|
uint16 nClosedArgs, uint16 nClosedVars, uint32 nTypeSets,
|
|
|
|
JSVersion version);
|
2010-09-13 22:33:44 -07:00
|
|
|
|
|
|
|
static JSScript *NewScriptFromCG(JSContext *cx, JSCodeGenerator *cg);
|
|
|
|
|
2010-08-05 17:15:49 -07:00
|
|
|
/* FIXME: bug 586181 */
|
|
|
|
JSCList links; /* Links for compartment script list */
|
2007-07-08 02:03:34 -07:00
|
|
|
jsbytecode *code; /* bytecodes and their immediate operands */
|
|
|
|
uint32 length; /* length of code vector */
|
2011-01-27 02:54:58 -08:00
|
|
|
|
2011-07-19 14:21:58 -07:00
|
|
|
uint32 cookie1;
|
|
|
|
|
2011-01-27 02:54:58 -08:00
|
|
|
private:
|
2011-05-09 15:11:32 -07:00
|
|
|
size_t useCount_; /* Number of times the script has been called
|
|
|
|
* or has had backedges taken. Reset if the
|
|
|
|
* script's JIT code is forcibly discarded. */
|
2011-01-27 02:54:58 -08:00
|
|
|
|
2011-05-09 15:11:32 -07:00
|
|
|
uint16 version; /* JS version under which script was compiled */
|
2011-02-11 16:31:32 -08:00
|
|
|
|
2011-01-27 02:54:58 -08:00
|
|
|
public:
|
2008-07-20 13:13:17 -07:00
|
|
|
uint16 nfixed; /* number of slots besides stack operands in
|
|
|
|
slot array */
|
2011-05-14 05:45:13 -07:00
|
|
|
uint16 nTypeSets; /* number of type sets used in this script for
|
|
|
|
dynamic type monitoring */
|
2010-12-02 14:23:51 -08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Offsets to various array structures from the end of this script, or
|
|
|
|
* JSScript::INVALID_OFFSET if the array has length 0.
|
|
|
|
*/
|
2011-06-15 20:01:04 -07:00
|
|
|
public:
|
2007-07-08 02:03:34 -07:00
|
|
|
uint8 objectsOffset; /* offset to the array of nested function,
|
|
|
|
block, scope, xml and one-time regexps
|
2010-12-02 14:23:51 -08:00
|
|
|
objects */
|
2008-08-21 03:47:33 -07:00
|
|
|
uint8 upvarsOffset; /* offset of the array of display ("up")
|
2010-12-02 14:23:51 -08:00
|
|
|
closure vars */
|
2007-07-08 02:03:34 -07:00
|
|
|
uint8 regexpsOffset; /* offset to the array of to-be-cloned
|
2010-12-02 14:23:51 -08:00
|
|
|
regexps */
|
|
|
|
uint8 trynotesOffset; /* offset to the array of try notes */
|
|
|
|
uint8 globalsOffset; /* offset to the array of global slots */
|
|
|
|
uint8 constOffset; /* offset to the array of constants */
|
|
|
|
|
2009-10-08 10:29:03 -07:00
|
|
|
bool noScriptRval:1; /* no need for result value of last
|
|
|
|
expression statement */
|
|
|
|
bool savedCallerFun:1; /* object 0 is caller function */
|
|
|
|
bool hasSharps:1; /* script uses sharp variables */
|
2010-04-22 17:45:49 -07:00
|
|
|
bool strictModeCode:1; /* code is in strict mode */
|
2010-06-12 19:00:27 -07:00
|
|
|
bool compileAndGo:1; /* script was compiled with TCF_COMPILE_N_GO */
|
2010-06-18 11:07:15 -07:00
|
|
|
bool usesEval:1; /* script uses eval() */
|
2010-09-13 22:33:44 -07:00
|
|
|
bool usesArguments:1; /* script uses arguments */
|
2010-07-23 09:27:07 -07:00
|
|
|
bool warnedAboutTwoArgumentEval:1; /* have warned about use of
|
|
|
|
obsolete eval(s, o) in
|
|
|
|
this script */
|
2011-06-06 17:12:49 -07:00
|
|
|
bool warnedAboutUndefinedProp:1; /* have warned about uses of
|
|
|
|
undefined properties in this
|
|
|
|
script */
|
2010-12-30 05:07:43 -08:00
|
|
|
bool hasSingletons:1; /* script has singleton objects */
|
2011-07-28 09:16:53 -07:00
|
|
|
bool hasFunction:1; /* function is active in 'where' union */
|
2011-04-20 07:06:59 -07:00
|
|
|
bool isActiveEval:1; /* script came from eval(), and is still active */
|
|
|
|
bool isCachedEval:1; /* script came from eval(), and is in eval cache */
|
2011-03-01 13:10:05 -08:00
|
|
|
bool isUncachedEval:1; /* script came from EvaluateScript */
|
2011-05-26 12:28:19 -07:00
|
|
|
bool usedLazyArgs:1; /* script has used lazy arguments at some point */
|
2011-07-21 07:28:01 -07:00
|
|
|
bool createdArgs:1; /* script has had arguments objects created */
|
|
|
|
bool uninlineable:1; /* script is considered uninlineable by analysis */
|
2010-08-05 17:15:49 -07:00
|
|
|
#ifdef JS_METHODJIT
|
|
|
|
bool debugMode:1; /* script was compiled in debug mode */
|
2010-11-16 15:18:35 -08:00
|
|
|
bool singleStepMode:1; /* compile script in single-step mode */
|
2011-04-05 18:12:03 -07:00
|
|
|
bool failedBoundsCheck:1; /* script has had hoisted bounds checks fail */
|
2010-08-05 17:15:49 -07:00
|
|
|
#endif
|
2009-10-08 10:29:03 -07:00
|
|
|
|
2007-07-08 02:03:34 -07:00
|
|
|
jsbytecode *main; /* main entry point, after predef'ing prolog */
|
|
|
|
JSAtomMap atomMap; /* maps immediate index to literal struct */
|
2010-09-29 23:17:29 -07:00
|
|
|
JSCompartment *compartment; /* compartment the script was compiled for */
|
2007-07-08 02:03:34 -07:00
|
|
|
const char *filename; /* source filename or null */
|
2008-08-21 03:47:33 -07:00
|
|
|
uint32 lineno; /* base line number of script */
|
|
|
|
uint16 nslots; /* vars plus maximum stack depth */
|
2009-04-05 21:17:22 -07:00
|
|
|
uint16 staticLevel;/* static level for display maintenance */
|
2010-09-13 22:33:44 -07:00
|
|
|
uint16 nClosedArgs; /* number of args which are closed over. */
|
|
|
|
uint16 nClosedVars; /* number of vars which are closed over. */
|
2010-11-16 15:34:24 -08:00
|
|
|
js::Bindings bindings; /* names of top-level variables in this script
|
|
|
|
(and arguments if this is a function script) */
|
2007-07-08 02:03:34 -07:00
|
|
|
JSPrincipals *principals;/* principals for this script */
|
2011-07-29 08:44:45 -07:00
|
|
|
jschar *sourceMap; /* source map file or null */
|
2011-07-25 18:05:05 -07:00
|
|
|
|
|
|
|
JSObject *ownerObject;
|
|
|
|
|
|
|
|
void setOwnerObject(JSObject *owner);
|
|
|
|
|
2008-08-20 22:18:42 -07:00
|
|
|
union {
|
2010-08-20 13:11:05 -07:00
|
|
|
/*
|
|
|
|
* A script object of class js_ScriptClass, to ensure the script is GC'd.
|
|
|
|
* - All scripts returned by JSAPI functions (JS_CompileScript,
|
|
|
|
* JS_CompileFile, etc.) have these objects.
|
|
|
|
* - Function scripts never have script objects; such scripts are owned
|
|
|
|
* by their function objects.
|
2010-12-29 23:46:50 -08:00
|
|
|
* - Temporary scripts created by obj_eval, JS_EvaluateScript, and
|
2010-08-20 13:11:05 -07:00
|
|
|
* similar functions never have these objects; such scripts are
|
|
|
|
* explicitly destroyed by the code that created them.
|
|
|
|
* Debugging API functions (JSDebugHooks::newScriptHook;
|
|
|
|
* JS_GetFunctionScript) may reveal sans-script-object Function and
|
|
|
|
* temporary scripts to clients, but clients must never call
|
|
|
|
* JS_NewScriptObject on such scripts: doing so would double-free them,
|
|
|
|
* once from the explicit call to js_DestroyScript, and once when the
|
|
|
|
* script object is garbage collected.
|
|
|
|
*/
|
|
|
|
JSObject *object;
|
2008-08-20 22:18:42 -07:00
|
|
|
JSScript *nextToGC; /* next to GC in rt->scriptsToGC list */
|
|
|
|
} u;
|
2010-09-29 23:17:29 -07:00
|
|
|
|
2008-02-07 15:18:45 -08:00
|
|
|
#ifdef CHECK_SCRIPT_OWNER
|
|
|
|
JSThread *owner; /* for thread-safe life-cycle assertions */
|
|
|
|
#endif
|
2010-09-13 22:33:44 -07:00
|
|
|
|
|
|
|
uint32 *closedSlots; /* vector of closed slots; args first, then vars. */
|
|
|
|
|
2011-05-10 11:26:39 -07:00
|
|
|
/* array of execution counters for every JSOp in the script, by runmode */
|
|
|
|
JSPCCounters pcCounters;
|
|
|
|
|
2011-07-19 14:21:58 -07:00
|
|
|
uint32 cookie2;
|
|
|
|
|
2010-09-13 22:33:44 -07:00
|
|
|
public:
|
2010-10-29 08:05:55 -07:00
|
|
|
|
2011-07-28 09:16:53 -07:00
|
|
|
union {
|
|
|
|
/* Function this script is the body for, if there is one. */
|
|
|
|
JSFunction *fun;
|
|
|
|
|
|
|
|
/* Global object for this script, if compileAndGo. */
|
|
|
|
js::GlobalObject *global;
|
|
|
|
} where;
|
|
|
|
|
|
|
|
inline JSFunction *function() const {
|
|
|
|
JS_ASSERT(hasFunction);
|
|
|
|
return where.fun;
|
|
|
|
}
|
2010-12-28 11:53:50 -08:00
|
|
|
|
2011-06-06 08:32:41 -07:00
|
|
|
/*
|
|
|
|
* Associates this script with a specific function, constructing a new type
|
|
|
|
* object for the function.
|
|
|
|
*/
|
2011-07-15 10:14:07 -07:00
|
|
|
bool typeSetFunction(JSContext *cx, JSFunction *fun, bool singleton = false);
|
2010-10-29 08:05:55 -07:00
|
|
|
|
2011-06-06 08:32:41 -07:00
|
|
|
inline bool hasGlobal() const;
|
|
|
|
inline js::GlobalObject *global() const;
|
2010-10-29 08:05:55 -07:00
|
|
|
|
2011-06-06 08:32:41 -07:00
|
|
|
inline bool hasClearedGlobal() const;
|
2011-03-01 13:10:05 -08:00
|
|
|
|
2011-06-06 08:32:41 -07:00
|
|
|
#ifdef DEBUG
|
|
|
|
/*
|
|
|
|
* Unique identifier within the compartment for this script, used for
|
|
|
|
* printing analysis information.
|
|
|
|
*/
|
|
|
|
unsigned id_;
|
|
|
|
unsigned id() { return id_; }
|
|
|
|
#else
|
|
|
|
unsigned id() { return 0; }
|
|
|
|
#endif
|
2011-03-01 13:10:05 -08:00
|
|
|
|
2011-07-28 09:16:53 -07:00
|
|
|
/* Persistent type information retained across GCs. */
|
|
|
|
js::types::TypeScript *types;
|
2010-10-29 08:05:55 -07:00
|
|
|
|
2011-07-28 09:16:53 -07:00
|
|
|
/* Ensure the script has types, bytecode and/or type inference results. */
|
|
|
|
inline bool ensureHasTypes(JSContext *cx);
|
|
|
|
inline bool ensureRanBytecode(JSContext *cx);
|
2011-06-06 08:32:41 -07:00
|
|
|
inline bool ensureRanInference(JSContext *cx);
|
2010-10-29 08:05:55 -07:00
|
|
|
|
2011-07-28 09:16:53 -07:00
|
|
|
/* Filled in by one of the above. */
|
|
|
|
inline bool hasAnalysis();
|
|
|
|
inline js::analyze::ScriptAnalysis *analysis();
|
2010-12-28 11:53:50 -08:00
|
|
|
|
2011-06-06 08:32:41 -07:00
|
|
|
inline bool isAboutToBeFinalized(JSContext *cx);
|
2010-12-22 14:46:42 -08:00
|
|
|
|
2011-07-28 09:16:53 -07:00
|
|
|
private:
|
|
|
|
bool makeTypes(JSContext *cx);
|
|
|
|
bool makeAnalysis(JSContext *cx);
|
|
|
|
public:
|
|
|
|
|
2010-05-22 17:09:52 -07:00
|
|
|
#ifdef JS_METHODJIT
|
2010-10-04 14:13:33 -07:00
|
|
|
// Fast-cached pointers to make calls faster. These are also used to
|
|
|
|
// quickly test whether there is JIT code; a NULL value means no
|
|
|
|
// compilation has been attempted. A JS_UNJITTABLE_SCRIPT value means
|
|
|
|
// compilation failed. Any value is the arity-check entry point.
|
|
|
|
void *jitArityCheckNormal;
|
|
|
|
void *jitArityCheckCtor;
|
|
|
|
|
|
|
|
js::mjit::JITScript *jitNormal; /* Extra JIT info for normal scripts */
|
|
|
|
js::mjit::JITScript *jitCtor; /* Extra JIT info for constructors */
|
|
|
|
|
|
|
|
bool hasJITCode() {
|
|
|
|
return jitNormal || jitCtor;
|
|
|
|
}
|
|
|
|
|
2010-10-10 15:47:09 -07:00
|
|
|
// These methods are implemented in MethodJIT.h.
|
|
|
|
inline void **nativeMap(bool constructing);
|
|
|
|
inline void *maybeNativeCodeForPC(bool constructing, jsbytecode *pc);
|
|
|
|
inline void *nativeCodeForPC(bool constructing, jsbytecode *pc);
|
2010-10-04 14:13:33 -07:00
|
|
|
|
|
|
|
js::mjit::JITScript *getJIT(bool constructing) {
|
|
|
|
return constructing ? jitCtor : jitNormal;
|
|
|
|
}
|
|
|
|
|
2011-05-09 15:11:32 -07:00
|
|
|
size_t useCount() const { return useCount_; }
|
|
|
|
size_t incUseCount() { return ++useCount_; }
|
|
|
|
size_t *addressOfUseCount() { return &useCount_; }
|
|
|
|
void resetUseCount() { useCount_ = 0; }
|
2011-02-11 16:31:32 -08:00
|
|
|
|
2010-10-04 14:13:33 -07:00
|
|
|
JITScriptStatus getJITStatus(bool constructing) {
|
|
|
|
void *addr = constructing ? jitArityCheckCtor : jitArityCheckNormal;
|
|
|
|
if (addr == NULL)
|
|
|
|
return JITScript_None;
|
|
|
|
if (addr == JS_UNJITTABLE_SCRIPT)
|
|
|
|
return JITScript_Invalid;
|
|
|
|
return JITScript_Valid;
|
|
|
|
}
|
2011-06-29 22:44:17 -07:00
|
|
|
|
|
|
|
// This method is implemented in MethodJIT.h.
|
|
|
|
JS_FRIEND_API(size_t) jitDataSize();/* Size of the JITScript and all sections */
|
2008-02-07 15:18:45 -08:00
|
|
|
#endif
|
2009-09-09 16:52:55 -07:00
|
|
|
|
2011-06-15 20:01:04 -07:00
|
|
|
JS_FRIEND_API(size_t) totalSize(); /* Size of the JSScript and all sections */
|
|
|
|
uint32 numNotes(); /* Number of srcnote slots in the srcnotes section */
|
|
|
|
|
2009-09-09 16:52:55 -07:00
|
|
|
/* Script notes are allocated right after the code. */
|
|
|
|
jssrcnote *notes() { return (jssrcnote *)(code + length); }
|
|
|
|
|
2010-12-02 14:23:51 -08:00
|
|
|
static const uint8 INVALID_OFFSET = 0xFF;
|
|
|
|
static bool isValidOffset(uint8 offset) { return offset != INVALID_OFFSET; }
|
|
|
|
|
2009-09-09 16:52:55 -07:00
|
|
|
JSObjectArray *objects() {
|
2010-12-02 14:23:51 -08:00
|
|
|
JS_ASSERT(isValidOffset(objectsOffset));
|
2011-06-17 12:59:47 -07:00
|
|
|
return reinterpret_cast<JSObjectArray *>(uintptr_t(this + 1) + objectsOffset);
|
2009-09-09 16:52:55 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
JSUpvarArray *upvars() {
|
2010-12-02 14:23:51 -08:00
|
|
|
JS_ASSERT(isValidOffset(upvarsOffset));
|
2011-06-17 12:59:47 -07:00
|
|
|
return reinterpret_cast<JSUpvarArray *>(uintptr_t(this + 1) + upvarsOffset);
|
2009-09-09 16:52:55 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
JSObjectArray *regexps() {
|
2010-12-02 14:23:51 -08:00
|
|
|
JS_ASSERT(isValidOffset(regexpsOffset));
|
2011-06-17 12:59:47 -07:00
|
|
|
return reinterpret_cast<JSObjectArray *>(uintptr_t(this + 1) + regexpsOffset);
|
2009-09-09 16:52:55 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
JSTryNoteArray *trynotes() {
|
2010-12-02 14:23:51 -08:00
|
|
|
JS_ASSERT(isValidOffset(trynotesOffset));
|
2011-06-17 12:59:47 -07:00
|
|
|
return reinterpret_cast<JSTryNoteArray *>(uintptr_t(this + 1) + trynotesOffset);
|
2009-09-09 16:52:55 -07:00
|
|
|
}
|
|
|
|
|
2010-05-22 15:38:04 -07:00
|
|
|
js::GlobalSlotArray *globals() {
|
2010-12-02 14:23:51 -08:00
|
|
|
JS_ASSERT(isValidOffset(globalsOffset));
|
2011-06-17 12:59:47 -07:00
|
|
|
return reinterpret_cast<js::GlobalSlotArray *>(uintptr_t(this + 1) + globalsOffset);
|
2010-05-22 15:38:04 -07:00
|
|
|
}
|
|
|
|
|
2010-07-14 23:19:36 -07:00
|
|
|
JSConstArray *consts() {
|
2010-12-02 14:23:51 -08:00
|
|
|
JS_ASSERT(isValidOffset(constOffset));
|
2011-06-17 12:59:47 -07:00
|
|
|
return reinterpret_cast<JSConstArray *>(uintptr_t(this + 1) + constOffset);
|
2010-07-14 23:19:36 -07:00
|
|
|
}
|
|
|
|
|
2009-09-09 16:52:55 -07:00
|
|
|
JSAtom *getAtom(size_t index) {
|
|
|
|
JS_ASSERT(index < atomMap.length);
|
|
|
|
return atomMap.vector[index];
|
|
|
|
}
|
|
|
|
|
|
|
|
JSObject *getObject(size_t index) {
|
|
|
|
JSObjectArray *arr = objects();
|
|
|
|
JS_ASSERT(index < arr->length);
|
|
|
|
return arr->vector[index];
|
|
|
|
}
|
|
|
|
|
2010-05-22 15:38:04 -07:00
|
|
|
uint32 getGlobalSlot(size_t index) {
|
|
|
|
js::GlobalSlotArray *arr = globals();
|
|
|
|
JS_ASSERT(index < arr->length);
|
|
|
|
return arr->vector[index].slot;
|
|
|
|
}
|
|
|
|
|
|
|
|
JSAtom *getGlobalAtom(size_t index) {
|
|
|
|
js::GlobalSlotArray *arr = globals();
|
|
|
|
JS_ASSERT(index < arr->length);
|
|
|
|
return getAtom(arr->vector[index].atomIndex);
|
|
|
|
}
|
|
|
|
|
2010-09-13 09:38:22 -07:00
|
|
|
JSVersion getVersion() const {
|
|
|
|
return JSVersion(version);
|
|
|
|
}
|
|
|
|
|
2009-09-10 07:22:20 -07:00
|
|
|
inline JSFunction *getFunction(size_t index);
|
2009-09-09 16:52:55 -07:00
|
|
|
|
|
|
|
inline JSObject *getRegExp(size_t index);
|
2009-10-18 17:41:24 -07:00
|
|
|
|
2010-07-14 23:19:36 -07:00
|
|
|
const js::Value &getConst(size_t index) {
|
|
|
|
JSConstArray *arr = consts();
|
|
|
|
JS_ASSERT(index < arr->length);
|
|
|
|
return arr->vector[index];
|
|
|
|
}
|
|
|
|
|
2009-10-18 17:41:24 -07:00
|
|
|
/*
|
|
|
|
* The isEmpty method tells whether this script has code that computes any
|
|
|
|
* result (not return value, result AKA normal completion value) other than
|
2010-11-16 15:30:56 -08:00
|
|
|
* JSVAL_VOID, or any other effects.
|
2009-10-18 17:41:24 -07:00
|
|
|
*/
|
|
|
|
inline bool isEmpty() const;
|
|
|
|
|
2010-09-13 22:33:44 -07:00
|
|
|
uint32 getClosedArg(uint32 index) {
|
|
|
|
JS_ASSERT(index < nClosedArgs);
|
|
|
|
return closedSlots[index];
|
|
|
|
}
|
|
|
|
|
|
|
|
uint32 getClosedVar(uint32 index) {
|
|
|
|
JS_ASSERT(index < nClosedVars);
|
|
|
|
return closedSlots[nClosedArgs + index];
|
|
|
|
}
|
|
|
|
|
|
|
|
void copyClosedSlotsTo(JSScript *other);
|
2007-03-22 10:30:00 -07:00
|
|
|
};
|
|
|
|
|
2009-09-14 07:29:56 -07:00
|
|
|
#define SHARP_NSLOTS 2 /* [#array, #depth] slots if the script
|
|
|
|
uses sharp variables */
|
|
|
|
|
2008-07-29 10:53:03 -07:00
|
|
|
static JS_INLINE uintN
|
2008-07-20 13:13:17 -07:00
|
|
|
StackDepth(JSScript *script)
|
|
|
|
{
|
2008-07-23 15:55:41 -07:00
|
|
|
return script->nslots - script->nfixed;
|
2008-07-20 13:13:17 -07:00
|
|
|
}
|
|
|
|
|
2009-09-04 16:27:17 -07:00
|
|
|
/*
|
|
|
|
* If pc_ does not point within script_'s bytecode, then it must point into an
|
|
|
|
* imacro body, so we use cx->runtime common atoms instead of script_'s atoms.
|
|
|
|
* This macro uses cx from its callers' environments in the pc-in-imacro case.
|
|
|
|
*/
|
|
|
|
#define JS_GET_SCRIPT_ATOM(script_, pc_, index, atom) \
|
2007-07-08 02:03:34 -07:00
|
|
|
JS_BEGIN_MACRO \
|
2009-09-04 16:27:17 -07:00
|
|
|
if ((pc_) < (script_)->code || \
|
|
|
|
(script_)->code + (script_)->length <= (pc_)) { \
|
2008-11-13 00:30:20 -08:00
|
|
|
JS_ASSERT((size_t)(index) < js_common_atom_count); \
|
2011-05-17 12:15:12 -07:00
|
|
|
(atom) = cx->runtime->atomState.commonAtomsStart()[index]; \
|
2008-11-13 00:30:20 -08:00
|
|
|
} else { \
|
2009-09-09 16:52:55 -07:00
|
|
|
(atom) = script_->getAtom(index); \
|
2008-11-13 00:30:20 -08:00
|
|
|
} \
|
2007-07-08 02:03:34 -07:00
|
|
|
JS_END_MACRO
|
|
|
|
|
2010-07-14 23:19:36 -07:00
|
|
|
extern JS_FRIEND_DATA(js::Class) js_ScriptClass;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
extern JSObject *
|
|
|
|
js_InitScriptClass(JSContext *cx, JSObject *obj);
|
|
|
|
|
|
|
|
extern void
|
|
|
|
js_MarkScriptFilename(const char *filename);
|
|
|
|
|
|
|
|
extern void
|
2011-07-14 16:02:12 -07:00
|
|
|
js_SweepScriptFilenames(JSCompartment *comp);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
/*
|
|
|
|
* New-script-hook calling is factored from js_NewScriptFromCG so that it
|
|
|
|
* and callers of js_XDRScript can share this code. In the case of callers
|
|
|
|
* of js_XDRScript, the hook should be invoked only after successful decode
|
|
|
|
* of any owning function (the fun parameter) or script object (null fun).
|
|
|
|
*/
|
2008-03-29 03:34:29 -07:00
|
|
|
extern JS_FRIEND_API(void)
|
|
|
|
js_CallNewScriptHook(JSContext *cx, JSScript *script, JSFunction *fun);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2011-02-11 13:23:18 -08:00
|
|
|
extern void
|
2007-03-22 10:30:00 -07:00
|
|
|
js_CallDestroyScriptHook(JSContext *cx, JSScript *script);
|
|
|
|
|
2010-10-06 08:21:23 -07:00
|
|
|
/*
|
|
|
|
* The function must be used only outside the GC for a script that was run
|
|
|
|
* only on the current thread.
|
|
|
|
*/
|
2007-03-22 10:30:00 -07:00
|
|
|
extern void
|
|
|
|
js_DestroyScript(JSContext *cx, JSScript *script);
|
|
|
|
|
2011-02-11 13:23:18 -08:00
|
|
|
extern void
|
2011-07-25 18:05:05 -07:00
|
|
|
js_DestroyScriptFromGC(JSContext *cx, JSScript *script, JSObject *owner);
|
2011-02-11 13:23:18 -08:00
|
|
|
|
2010-10-06 08:21:23 -07:00
|
|
|
/*
|
2011-02-11 13:23:18 -08:00
|
|
|
* Script objects may be cached and reused, in which case their JSD-visible
|
|
|
|
* lifetimes may be shorter than their actual lifetimes. Destroy one such
|
|
|
|
* script for real as part of a GC pass. From JSD's point of view, the script
|
|
|
|
* is already dead.
|
2010-10-06 08:21:23 -07:00
|
|
|
*/
|
|
|
|
extern void
|
2011-02-11 13:23:18 -08:00
|
|
|
js_DestroyCachedScript(JSContext *cx, JSScript *script);
|
2010-10-06 08:21:23 -07:00
|
|
|
|
2011-07-19 14:21:58 -07:00
|
|
|
namespace js {
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This diagnostic function checks that a compartment's list of scripts
|
|
|
|
* contains only valid scripts. It also searches for the target script
|
|
|
|
* in the list. If expected is true, it asserts that the target script
|
|
|
|
* is found. If expected is false, it asserts that it's not found.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
CheckCompartmentScripts(JSCompartment *comp);
|
|
|
|
|
|
|
|
} /* namespace js */
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
extern void
|
2011-07-25 18:05:05 -07:00
|
|
|
js_TraceScript(JSTracer *trc, JSScript *script, JSObject *owner);
|
2010-08-20 13:11:05 -07:00
|
|
|
|
2011-02-03 05:06:21 -08:00
|
|
|
extern JSObject *
|
2010-08-20 13:11:05 -07:00
|
|
|
js_NewScriptObject(JSContext *cx, JSScript *script);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
/*
|
|
|
|
* To perturb as little code as possible, we introduce a js_GetSrcNote lookup
|
|
|
|
* cache without adding an explicit cx parameter. Thus js_GetSrcNote becomes
|
|
|
|
* a macro that uses cx from its calls' lexical environments.
|
|
|
|
*/
|
|
|
|
#define js_GetSrcNote(script,pc) js_GetSrcNoteCached(cx, script, pc)
|
|
|
|
|
|
|
|
extern jssrcnote *
|
|
|
|
js_GetSrcNoteCached(JSContext *cx, JSScript *script, jsbytecode *pc);
|
|
|
|
|
2008-11-13 00:30:20 -08:00
|
|
|
/*
|
|
|
|
* NOTE: use js_FramePCToLineNumber(cx, fp) when you have an active fp, in
|
|
|
|
* preference to js_PCToLineNumber (cx, fp->script fp->regs->pc), because
|
|
|
|
* fp->imacpc may be non-null, indicating an active imacro.
|
|
|
|
*/
|
|
|
|
extern uintN
|
2011-05-27 18:15:39 -07:00
|
|
|
js_FramePCToLineNumber(JSContext *cx, js::StackFrame *fp, jsbytecode *pc);
|
2008-11-13 00:30:20 -08:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
extern uintN
|
|
|
|
js_PCToLineNumber(JSContext *cx, JSScript *script, jsbytecode *pc);
|
|
|
|
|
|
|
|
extern jsbytecode *
|
|
|
|
js_LineNumberToPC(JSScript *script, uintN lineno);
|
|
|
|
|
|
|
|
extern JS_FRIEND_API(uintN)
|
|
|
|
js_GetScriptLineExtent(JSScript *script);
|
|
|
|
|
2011-04-08 10:52:51 -07:00
|
|
|
namespace js {
|
|
|
|
|
2011-05-27 18:15:39 -07:00
|
|
|
extern uintN
|
|
|
|
CurrentLine(JSContext *cx);
|
|
|
|
|
2011-04-08 10:52:51 -07:00
|
|
|
/*
|
|
|
|
* This function returns the file and line number of the script currently
|
|
|
|
* executing on cx. If there is no current script executing on cx (e.g., a
|
|
|
|
* native called directly through JSAPI (e.g., by setTimeout)), NULL and 0 are
|
|
|
|
* returned as the file and line. Additionally, this function avoids the full
|
|
|
|
* linear scan to compute line number when the caller guarnatees that the
|
|
|
|
* script compilation occurs at a JSOP_EVAL.
|
|
|
|
*/
|
|
|
|
|
|
|
|
enum LineOption {
|
|
|
|
CALLED_FROM_JSOP_EVAL,
|
|
|
|
NOT_CALLED_FROM_JSOP_EVAL
|
|
|
|
};
|
|
|
|
|
|
|
|
inline const char *
|
|
|
|
CurrentScriptFileAndLine(JSContext *cx, uintN *linenop, LineOption = NOT_CALLED_FROM_JSOP_EVAL);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2009-02-18 16:31:09 -08:00
|
|
|
static JS_INLINE JSOp
|
|
|
|
js_GetOpcode(JSContext *cx, JSScript *script, jsbytecode *pc)
|
|
|
|
{
|
|
|
|
JSOp op = (JSOp) *pc;
|
|
|
|
if (op == JSOP_TRAP)
|
|
|
|
op = JS_GetTrapOpcode(cx, script, pc);
|
|
|
|
return op;
|
|
|
|
}
|
|
|
|
|
2010-09-29 23:17:29 -07:00
|
|
|
extern JSScript *
|
|
|
|
js_CloneScript(JSContext *cx, JSScript *script);
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
/*
|
2010-11-16 15:30:56 -08:00
|
|
|
* NB: after a successful JSXDR_DECODE, js_XDRScript callers must do any
|
|
|
|
* required subsequent set-up of owning function or script object and then call
|
|
|
|
* js_CallNewScriptHook.
|
2007-03-22 10:30:00 -07:00
|
|
|
*/
|
|
|
|
extern JSBool
|
2011-03-15 18:00:58 -07:00
|
|
|
js_XDRScript(JSXDRState *xdr, JSScript **scriptp);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2011-02-03 05:06:21 -08:00
|
|
|
inline bool
|
|
|
|
JSObject::isScript() const
|
|
|
|
{
|
|
|
|
return getClass() == &js_ScriptClass;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline JSScript *
|
|
|
|
JSObject::getScript() const
|
|
|
|
{
|
|
|
|
JS_ASSERT(isScript());
|
|
|
|
return static_cast<JSScript *>(getPrivate());
|
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
#endif /* jsscript_h___ */
|