2010-10-29 08:05:55 -07:00
|
|
|
/* -*- Mode: c++; c-basic-offset: 4; tab-width: 40; indent-tabs-mode: nil -*- */
|
|
|
|
/* vim: set ts=40 sw=4 et tw=99: */
|
|
|
|
/* ***** BEGIN LICENSE BLOCK *****
|
|
|
|
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
|
|
|
*
|
|
|
|
* The contents of this file are subject to the Mozilla Public License Version
|
|
|
|
* 1.1 (the "License"); you may not use this file except in compliance with
|
|
|
|
* the License. You may obtain a copy of the License at
|
|
|
|
* http://www.mozilla.org/MPL/
|
|
|
|
*
|
|
|
|
* Software distributed under the License is distributed on an "AS IS" basis,
|
|
|
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
|
|
|
* for the specific language governing rights and limitations under the
|
|
|
|
* License.
|
|
|
|
*
|
|
|
|
* The Original Code is the Mozilla SpiderMonkey bytecode type inference
|
|
|
|
*
|
|
|
|
* The Initial Developer of the Original Code is
|
|
|
|
* Mozilla Foundation
|
|
|
|
* Portions created by the Initial Developer are Copyright (C) 2010
|
|
|
|
* the Initial Developer. All Rights Reserved.
|
|
|
|
*
|
|
|
|
* Contributor(s):
|
|
|
|
* Brian Hackett <bhackett@mozilla.com>
|
|
|
|
*
|
|
|
|
* 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 ***** */
|
|
|
|
|
2010-11-01 20:03:46 -07:00
|
|
|
/* Inline members for javascript type inference. */
|
2010-10-29 08:05:55 -07:00
|
|
|
|
2011-05-16 16:15:37 -07:00
|
|
|
#include "jsarray.h"
|
2010-10-29 08:05:55 -07:00
|
|
|
#include "jsanalyze.h"
|
|
|
|
#include "jscompartment.h"
|
2011-09-01 12:20:30 -07:00
|
|
|
#include "jsgcmark.h"
|
2010-10-29 08:05:55 -07:00
|
|
|
#include "jsinfer.h"
|
2010-10-29 11:44:30 -07:00
|
|
|
#include "jsprf.h"
|
2011-05-12 17:59:28 -07:00
|
|
|
#include "vm/GlobalObject.h"
|
2010-10-29 08:05:55 -07:00
|
|
|
|
2011-06-05 22:39:45 -07:00
|
|
|
#include "vm/Stack-inl.h"
|
|
|
|
|
2010-10-29 08:05:55 -07:00
|
|
|
#ifndef jsinferinlines_h___
|
|
|
|
#define jsinferinlines_h___
|
|
|
|
|
|
|
|
/////////////////////////////////////////////////////////////////////
|
|
|
|
// Types
|
|
|
|
/////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
namespace js {
|
|
|
|
namespace types {
|
|
|
|
|
2011-07-15 10:14:07 -07:00
|
|
|
/* static */ inline Type
|
|
|
|
Type::ObjectType(JSObject *obj)
|
|
|
|
{
|
|
|
|
if (obj->hasSingletonType())
|
|
|
|
return Type((jsuword) obj | 1);
|
|
|
|
return Type((jsuword) obj->type());
|
|
|
|
}
|
|
|
|
|
|
|
|
/* static */ inline Type
|
|
|
|
Type::ObjectType(TypeObject *obj)
|
|
|
|
{
|
|
|
|
if (obj->singleton)
|
2011-10-25 16:07:42 -07:00
|
|
|
return Type((jsuword) obj->singleton.get() | 1);
|
2011-07-15 10:14:07 -07:00
|
|
|
return Type((jsuword) obj);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* static */ inline Type
|
|
|
|
Type::ObjectType(TypeObjectKey *obj)
|
|
|
|
{
|
|
|
|
return Type((jsuword) obj);
|
|
|
|
}
|
|
|
|
|
|
|
|
inline Type
|
2010-10-29 08:05:55 -07:00
|
|
|
GetValueType(JSContext *cx, const Value &val)
|
|
|
|
{
|
2011-03-03 14:07:48 -08:00
|
|
|
JS_ASSERT(cx->typeInferenceEnabled());
|
2010-10-29 08:05:55 -07:00
|
|
|
if (val.isDouble())
|
2011-07-15 10:14:07 -07:00
|
|
|
return Type::DoubleType();
|
|
|
|
if (val.isObject())
|
|
|
|
return Type::ObjectType(&val.toObject());
|
|
|
|
return Type::PrimitiveType(val.extractNonDoubleType());
|
|
|
|
}
|
|
|
|
|
|
|
|
inline TypeFlags
|
|
|
|
PrimitiveTypeFlag(JSValueType type)
|
|
|
|
{
|
|
|
|
switch (type) {
|
2010-10-29 08:05:55 -07:00
|
|
|
case JSVAL_TYPE_UNDEFINED:
|
2011-07-15 10:14:07 -07:00
|
|
|
return TYPE_FLAG_UNDEFINED;
|
|
|
|
case JSVAL_TYPE_NULL:
|
|
|
|
return TYPE_FLAG_NULL;
|
2010-10-29 08:05:55 -07:00
|
|
|
case JSVAL_TYPE_BOOLEAN:
|
2011-07-15 10:14:07 -07:00
|
|
|
return TYPE_FLAG_BOOLEAN;
|
|
|
|
case JSVAL_TYPE_INT32:
|
|
|
|
return TYPE_FLAG_INT32;
|
|
|
|
case JSVAL_TYPE_DOUBLE:
|
|
|
|
return TYPE_FLAG_DOUBLE;
|
2010-10-29 08:05:55 -07:00
|
|
|
case JSVAL_TYPE_STRING:
|
2011-07-15 10:14:07 -07:00
|
|
|
return TYPE_FLAG_STRING;
|
2011-05-26 12:28:19 -07:00
|
|
|
case JSVAL_TYPE_MAGIC:
|
2011-07-15 10:14:07 -07:00
|
|
|
return TYPE_FLAG_LAZYARGS;
|
2010-10-29 08:05:55 -07:00
|
|
|
default:
|
2011-07-15 10:14:07 -07:00
|
|
|
JS_NOT_REACHED("Bad type");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
inline JSValueType
|
|
|
|
TypeFlagPrimitive(TypeFlags flags)
|
|
|
|
{
|
|
|
|
switch (flags) {
|
|
|
|
case TYPE_FLAG_UNDEFINED:
|
|
|
|
return JSVAL_TYPE_UNDEFINED;
|
|
|
|
case TYPE_FLAG_NULL:
|
|
|
|
return JSVAL_TYPE_NULL;
|
|
|
|
case TYPE_FLAG_BOOLEAN:
|
|
|
|
return JSVAL_TYPE_BOOLEAN;
|
|
|
|
case TYPE_FLAG_INT32:
|
|
|
|
return JSVAL_TYPE_INT32;
|
|
|
|
case TYPE_FLAG_DOUBLE:
|
|
|
|
return JSVAL_TYPE_DOUBLE;
|
|
|
|
case TYPE_FLAG_STRING:
|
|
|
|
return JSVAL_TYPE_STRING;
|
|
|
|
case TYPE_FLAG_LAZYARGS:
|
|
|
|
return JSVAL_TYPE_MAGIC;
|
|
|
|
default:
|
|
|
|
JS_NOT_REACHED("Bad type");
|
|
|
|
return (JSValueType) 0;
|
2010-10-29 08:05:55 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Get the canonical representation of an id to use when doing inference. This
|
|
|
|
* maintains the constraint that if two different jsids map to the same property
|
|
|
|
* in JS (e.g. 3 and "3"), they have the same type representation.
|
|
|
|
*/
|
|
|
|
inline jsid
|
2010-12-18 20:44:51 -08:00
|
|
|
MakeTypeId(JSContext *cx, jsid id)
|
2010-10-29 08:05:55 -07:00
|
|
|
{
|
2011-05-20 19:33:06 -07:00
|
|
|
JS_ASSERT(!JSID_IS_EMPTY(id));
|
|
|
|
|
2010-10-29 08:05:55 -07:00
|
|
|
/*
|
|
|
|
* All integers must map to the aggregate property for index types, including
|
|
|
|
* negative integers.
|
|
|
|
*/
|
|
|
|
if (JSID_IS_INT(id))
|
|
|
|
return JSID_VOID;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Check for numeric strings, as in js_StringIsIndex, but allow negative
|
2010-12-18 20:44:51 -08:00
|
|
|
* and overflowing integers.
|
2010-10-29 08:05:55 -07:00
|
|
|
*/
|
|
|
|
if (JSID_IS_STRING(id)) {
|
2010-12-20 09:06:43 -08:00
|
|
|
JSFlatString *str = JSID_TO_FLAT_STRING(id);
|
|
|
|
const jschar *cp = str->getCharsZ(cx);
|
2010-10-29 08:05:55 -07:00
|
|
|
if (JS7_ISDEC(*cp) || *cp == '-') {
|
|
|
|
cp++;
|
|
|
|
while (JS7_ISDEC(*cp))
|
|
|
|
cp++;
|
2011-05-15 21:27:12 -07:00
|
|
|
if (*cp == 0)
|
2010-10-29 08:05:55 -07:00
|
|
|
return JSID_VOID;
|
|
|
|
}
|
2011-03-03 14:07:48 -08:00
|
|
|
return id;
|
2010-10-29 08:05:55 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
return JSID_VOID;
|
|
|
|
}
|
|
|
|
|
2010-12-19 08:09:45 -08:00
|
|
|
const char * TypeIdStringImpl(jsid id);
|
|
|
|
|
2010-11-18 15:18:23 -08:00
|
|
|
/* Convert an id for printing during debug. */
|
|
|
|
static inline const char *
|
2010-11-20 15:45:52 -08:00
|
|
|
TypeIdString(jsid id)
|
2010-11-18 15:18:23 -08:00
|
|
|
{
|
|
|
|
#ifdef DEBUG
|
2010-12-07 17:11:37 -08:00
|
|
|
return TypeIdStringImpl(id);
|
2010-11-18 15:18:23 -08:00
|
|
|
#else
|
2010-11-24 17:41:52 -08:00
|
|
|
return "(missing)";
|
2010-11-18 15:18:23 -08:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2011-03-03 14:07:48 -08:00
|
|
|
/*
|
|
|
|
* Structure for type inference entry point functions. All functions which can
|
|
|
|
* change type information must use this, and functions which depend on
|
|
|
|
* intermediate types (i.e. JITs) can use this to ensure that intermediate
|
|
|
|
* information is not collected and does not change.
|
|
|
|
*
|
|
|
|
* Pins inference results so that intermediate type information, TypeObjects
|
|
|
|
* and JSScripts won't be collected during GC. Does additional sanity checking
|
|
|
|
* that inference is not reentrant and that recompilations occur properly.
|
|
|
|
*/
|
|
|
|
struct AutoEnterTypeInference
|
|
|
|
{
|
|
|
|
JSContext *cx;
|
2011-04-22 07:59:45 -07:00
|
|
|
bool oldActiveAnalysis;
|
|
|
|
bool oldActiveInference;
|
2011-03-03 14:07:48 -08:00
|
|
|
|
|
|
|
AutoEnterTypeInference(JSContext *cx, bool compiling = false)
|
2011-04-22 07:59:45 -07:00
|
|
|
: cx(cx), oldActiveAnalysis(cx->compartment->activeAnalysis),
|
|
|
|
oldActiveInference(cx->compartment->activeInference)
|
2011-03-03 14:07:48 -08:00
|
|
|
{
|
|
|
|
JS_ASSERT_IF(!compiling, cx->compartment->types.inferenceEnabled);
|
2011-04-22 07:59:45 -07:00
|
|
|
cx->compartment->activeAnalysis = true;
|
|
|
|
cx->compartment->activeInference = true;
|
2011-03-03 14:07:48 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
~AutoEnterTypeInference()
|
|
|
|
{
|
2011-04-22 07:59:45 -07:00
|
|
|
cx->compartment->activeAnalysis = oldActiveAnalysis;
|
|
|
|
cx->compartment->activeInference = oldActiveInference;
|
2011-03-03 14:07:48 -08:00
|
|
|
|
|
|
|
/*
|
2011-04-22 07:59:45 -07:00
|
|
|
* If there are no more type inference activations on the stack,
|
|
|
|
* process any triggered recompilations. Note that we should not be
|
|
|
|
* invoking any scripted code while type inference is running.
|
|
|
|
* :TODO: assert this.
|
2011-03-03 14:07:48 -08:00
|
|
|
*/
|
2011-04-22 07:59:45 -07:00
|
|
|
if (!cx->compartment->activeInference) {
|
|
|
|
TypeCompartment *types = &cx->compartment->types;
|
|
|
|
if (types->pendingNukeTypes)
|
|
|
|
types->nukeTypes(cx);
|
|
|
|
else if (types->pendingRecompiles)
|
|
|
|
types->processPendingRecompiles(cx);
|
|
|
|
}
|
2011-03-03 14:07:48 -08:00
|
|
|
}
|
2011-04-22 07:59:45 -07:00
|
|
|
};
|
2011-03-03 14:07:48 -08:00
|
|
|
|
2011-03-30 14:10:16 -07:00
|
|
|
/*
|
|
|
|
* Structure marking the currently compiled script, for constraints which can
|
|
|
|
* trigger recompilation.
|
|
|
|
*/
|
|
|
|
struct AutoEnterCompilation
|
|
|
|
{
|
|
|
|
JSContext *cx;
|
|
|
|
JSScript *script;
|
|
|
|
|
|
|
|
AutoEnterCompilation(JSContext *cx, JSScript *script)
|
|
|
|
: cx(cx), script(script)
|
|
|
|
{
|
|
|
|
JS_ASSERT(!cx->compartment->types.compiledScript);
|
|
|
|
cx->compartment->types.compiledScript = script;
|
|
|
|
}
|
|
|
|
|
|
|
|
~AutoEnterCompilation()
|
|
|
|
{
|
|
|
|
JS_ASSERT(cx->compartment->types.compiledScript == script);
|
|
|
|
cx->compartment->types.compiledScript = NULL;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2010-10-29 08:05:55 -07:00
|
|
|
/////////////////////////////////////////////////////////////////////
|
2011-06-02 10:40:27 -07:00
|
|
|
// Interface functions
|
2010-10-29 08:05:55 -07:00
|
|
|
/////////////////////////////////////////////////////////////////////
|
|
|
|
|
2011-06-02 10:40:27 -07:00
|
|
|
/*
|
|
|
|
* These functions check whether inference is enabled before performing some
|
|
|
|
* action on the type state. To avoid checking cx->typeInferenceEnabled()
|
|
|
|
* everywhere, it is generally preferred to use one of these functions or
|
|
|
|
* a type function on JSScript to perform inference operations.
|
|
|
|
*/
|
2011-03-03 14:07:48 -08:00
|
|
|
|
2011-06-02 10:40:27 -07:00
|
|
|
/*
|
|
|
|
* Get the default 'new' object for a given standard class, per the currently
|
|
|
|
* active global.
|
|
|
|
*/
|
|
|
|
inline TypeObject *
|
|
|
|
GetTypeNewObject(JSContext *cx, JSProtoKey key)
|
2010-11-24 17:41:52 -08:00
|
|
|
{
|
2010-12-18 20:44:51 -08:00
|
|
|
JSObject *proto;
|
2011-06-02 10:40:27 -07:00
|
|
|
if (!js_GetClassPrototype(cx, NULL, key, &proto, NULL))
|
2010-12-18 20:44:51 -08:00
|
|
|
return NULL;
|
2011-06-02 10:40:27 -07:00
|
|
|
return proto->getNewType(cx);
|
2010-11-24 17:41:52 -08:00
|
|
|
}
|
|
|
|
|
2011-06-02 10:40:27 -07:00
|
|
|
/* Get a type object for the immediate allocation site within a native. */
|
|
|
|
inline TypeObject *
|
2011-06-15 11:26:12 -07:00
|
|
|
GetTypeCallerInitObject(JSContext *cx, JSProtoKey key)
|
2010-10-29 08:05:55 -07:00
|
|
|
{
|
2011-06-02 10:40:27 -07:00
|
|
|
if (cx->typeInferenceEnabled()) {
|
2011-06-05 22:39:45 -07:00
|
|
|
jsbytecode *pc;
|
|
|
|
JSScript *script = cx->stack.currentScript(&pc);
|
2011-08-01 22:24:29 -07:00
|
|
|
if (script)
|
2011-07-28 09:16:53 -07:00
|
|
|
return TypeScript::InitObject(cx, script, pc, key);
|
2011-03-03 14:07:48 -08:00
|
|
|
}
|
2011-06-15 11:26:12 -07:00
|
|
|
return GetTypeNewObject(cx, key);
|
2010-10-29 08:05:55 -07:00
|
|
|
}
|
|
|
|
|
2011-06-10 19:03:57 -07:00
|
|
|
/*
|
|
|
|
* When using a custom iterator within the initialization of a 'for in' loop,
|
|
|
|
* mark the iterator values as unknown.
|
|
|
|
*/
|
2011-05-09 07:12:47 -07:00
|
|
|
inline void
|
2011-06-10 19:03:57 -07:00
|
|
|
MarkIteratorUnknown(JSContext *cx)
|
2010-10-29 08:05:55 -07:00
|
|
|
{
|
2011-06-10 19:03:57 -07:00
|
|
|
extern void MarkIteratorUnknownSlow(JSContext *cx);
|
2011-06-02 10:40:27 -07:00
|
|
|
|
|
|
|
if (cx->typeInferenceEnabled())
|
2011-06-10 19:03:57 -07:00
|
|
|
MarkIteratorUnknownSlow(cx);
|
2010-10-29 08:05:55 -07:00
|
|
|
}
|
|
|
|
|
2011-06-02 10:40:27 -07:00
|
|
|
/*
|
2011-10-27 08:11:26 -07:00
|
|
|
* Monitor a javascript call, either on entry to the interpreter or made
|
|
|
|
* from within the interpreter.
|
2011-06-02 10:40:27 -07:00
|
|
|
*/
|
2011-05-09 07:12:47 -07:00
|
|
|
inline void
|
2011-10-27 08:11:26 -07:00
|
|
|
TypeMonitorCall(JSContext *cx, const js::CallArgs &args, bool constructing)
|
2011-06-02 10:40:27 -07:00
|
|
|
{
|
|
|
|
extern void TypeMonitorCallSlow(JSContext *cx, JSObject *callee,
|
2011-10-27 08:11:26 -07:00
|
|
|
const CallArgs &args, bool constructing);
|
2011-06-02 10:40:27 -07:00
|
|
|
|
2011-09-01 12:20:30 -07:00
|
|
|
JSObject *callee = &args.callee();
|
|
|
|
if (callee->isFunction()) {
|
2011-10-11 15:28:54 -07:00
|
|
|
JSFunction *fun = callee->toFunction();
|
2011-09-01 12:20:30 -07:00
|
|
|
if (fun->isInterpreted()) {
|
|
|
|
JSScript *script = fun->script();
|
2011-11-08 13:42:27 -08:00
|
|
|
if (!script->ensureRanAnalysis(cx, fun->environment()))
|
2011-09-01 12:20:30 -07:00
|
|
|
return;
|
|
|
|
if (cx->typeInferenceEnabled())
|
|
|
|
TypeMonitorCallSlow(cx, callee, args, constructing);
|
|
|
|
}
|
2011-03-03 14:07:48 -08:00
|
|
|
}
|
2010-10-29 08:05:55 -07:00
|
|
|
}
|
|
|
|
|
2011-07-15 10:14:07 -07:00
|
|
|
inline bool
|
|
|
|
TrackPropertyTypes(JSContext *cx, JSObject *obj, jsid id)
|
|
|
|
{
|
2011-07-21 07:28:01 -07:00
|
|
|
if (!cx->typeInferenceEnabled() || obj->hasLazyType() || obj->type()->unknownProperties())
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if (obj->hasSingletonType() && !obj->type()->maybeGetProperty(cx, id))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
return true;
|
2011-07-15 10:14:07 -07:00
|
|
|
}
|
|
|
|
|
2011-06-02 10:40:27 -07:00
|
|
|
/* Add a possible type for a property of obj. */
|
2011-05-09 07:12:47 -07:00
|
|
|
inline void
|
2011-07-15 10:14:07 -07:00
|
|
|
AddTypePropertyId(JSContext *cx, JSObject *obj, jsid id, Type type)
|
2010-10-29 08:05:55 -07:00
|
|
|
{
|
2011-07-21 07:28:01 -07:00
|
|
|
if (cx->typeInferenceEnabled())
|
|
|
|
id = MakeTypeId(cx, id);
|
2011-07-15 10:14:07 -07:00
|
|
|
if (TrackPropertyTypes(cx, obj, id))
|
|
|
|
obj->type()->addPropertyType(cx, id, type);
|
2010-10-29 08:05:55 -07:00
|
|
|
}
|
|
|
|
|
2011-05-09 07:12:47 -07:00
|
|
|
inline void
|
2011-07-15 10:14:07 -07:00
|
|
|
AddTypePropertyId(JSContext *cx, JSObject *obj, jsid id, const Value &value)
|
2010-10-29 08:05:55 -07:00
|
|
|
{
|
2011-07-21 07:28:01 -07:00
|
|
|
if (cx->typeInferenceEnabled())
|
|
|
|
id = MakeTypeId(cx, id);
|
2011-07-15 10:14:07 -07:00
|
|
|
if (TrackPropertyTypes(cx, obj, id))
|
|
|
|
obj->type()->addPropertyType(cx, id, value);
|
2010-10-29 08:05:55 -07:00
|
|
|
}
|
|
|
|
|
2011-05-09 07:12:47 -07:00
|
|
|
inline void
|
2011-07-15 10:14:07 -07:00
|
|
|
AddTypeProperty(JSContext *cx, TypeObject *obj, const char *name, Type type)
|
2010-10-29 08:05:55 -07:00
|
|
|
{
|
2011-06-02 10:40:27 -07:00
|
|
|
if (cx->typeInferenceEnabled() && !obj->unknownProperties())
|
|
|
|
obj->addPropertyType(cx, name, type);
|
2010-12-21 18:26:09 -08:00
|
|
|
}
|
|
|
|
|
2011-05-09 07:12:47 -07:00
|
|
|
inline void
|
2011-06-02 10:40:27 -07:00
|
|
|
AddTypeProperty(JSContext *cx, TypeObject *obj, const char *name, const Value &value)
|
2011-03-15 23:50:44 -07:00
|
|
|
{
|
2011-06-02 10:40:27 -07:00
|
|
|
if (cx->typeInferenceEnabled() && !obj->unknownProperties())
|
|
|
|
obj->addPropertyType(cx, name, value);
|
2011-03-15 23:50:44 -07:00
|
|
|
}
|
|
|
|
|
2011-06-02 10:40:27 -07:00
|
|
|
/* Set one or more dynamic flags on a type object. */
|
2011-05-09 07:12:47 -07:00
|
|
|
inline void
|
2011-07-15 10:14:07 -07:00
|
|
|
MarkTypeObjectFlags(JSContext *cx, JSObject *obj, TypeObjectFlags flags)
|
2011-04-11 20:10:46 -07:00
|
|
|
{
|
2011-07-25 07:13:02 -07:00
|
|
|
if (cx->typeInferenceEnabled() && !obj->hasLazyType() && !obj->type()->hasAllFlags(flags))
|
|
|
|
obj->type()->setFlags(cx, flags);
|
2011-04-11 20:10:46 -07:00
|
|
|
}
|
|
|
|
|
2011-07-15 10:14:07 -07:00
|
|
|
/*
|
|
|
|
* Mark all properties of a type object as unknown. If markSetsUnknown is set,
|
|
|
|
* scan the entire compartment and mark all type sets containing it as having
|
|
|
|
* an unknown object. This is needed for correctness in dealing with mutable
|
|
|
|
* __proto__, which can change the type of an object dynamically.
|
|
|
|
*/
|
2011-05-09 07:12:47 -07:00
|
|
|
inline void
|
2011-07-15 10:14:07 -07:00
|
|
|
MarkTypeObjectUnknownProperties(JSContext *cx, TypeObject *obj,
|
|
|
|
bool markSetsUnknown = false)
|
2011-04-11 20:10:46 -07:00
|
|
|
{
|
2011-07-15 10:14:07 -07:00
|
|
|
if (cx->typeInferenceEnabled()) {
|
|
|
|
if (!obj->unknownProperties())
|
|
|
|
obj->markUnknown(cx);
|
2011-07-21 07:28:01 -07:00
|
|
|
if (markSetsUnknown && !(obj->flags & OBJECT_FLAG_SETS_MARKED_UNKNOWN))
|
2011-07-15 10:14:07 -07:00
|
|
|
cx->compartment->types.markSetsUnknown(cx, obj);
|
|
|
|
}
|
2011-04-11 20:10:46 -07:00
|
|
|
}
|
|
|
|
|
2011-06-02 10:40:27 -07:00
|
|
|
/*
|
|
|
|
* Mark any property which has been deleted or configured to be non-writable or
|
|
|
|
* have a getter/setter.
|
|
|
|
*/
|
2011-05-09 07:12:47 -07:00
|
|
|
inline void
|
2011-07-15 10:14:07 -07:00
|
|
|
MarkTypePropertyConfigured(JSContext *cx, JSObject *obj, jsid id)
|
2010-11-09 14:40:10 -08:00
|
|
|
{
|
2011-07-21 07:28:01 -07:00
|
|
|
if (cx->typeInferenceEnabled())
|
|
|
|
id = MakeTypeId(cx, id);
|
|
|
|
if (TrackPropertyTypes(cx, obj, id))
|
2011-07-15 10:14:07 -07:00
|
|
|
obj->type()->markPropertyConfigured(cx, id);
|
2010-10-29 08:05:55 -07:00
|
|
|
}
|
|
|
|
|
2011-08-09 09:52:55 -07:00
|
|
|
/* Mark a state change on a particular object. */
|
2011-05-09 07:12:47 -07:00
|
|
|
inline void
|
2011-08-09 09:52:55 -07:00
|
|
|
MarkObjectStateChange(JSContext *cx, JSObject *obj)
|
2010-11-24 17:41:52 -08:00
|
|
|
{
|
2011-08-09 09:52:55 -07:00
|
|
|
if (cx->typeInferenceEnabled() && !obj->hasLazyType() && !obj->type()->unknownProperties())
|
|
|
|
obj->type()->markStateChange(cx);
|
2010-11-24 17:41:52 -08:00
|
|
|
}
|
|
|
|
|
2011-06-02 10:40:27 -07:00
|
|
|
/*
|
|
|
|
* For an array or object which has not yet escaped and been referenced elsewhere,
|
|
|
|
* pick a new type based on the object's current contents.
|
|
|
|
*/
|
|
|
|
|
2011-05-09 07:12:47 -07:00
|
|
|
inline void
|
2011-06-02 10:40:27 -07:00
|
|
|
FixArrayType(JSContext *cx, JSObject *obj)
|
2011-03-10 16:17:39 -08:00
|
|
|
{
|
2011-06-02 10:40:27 -07:00
|
|
|
if (cx->typeInferenceEnabled())
|
|
|
|
cx->compartment->types.fixArrayType(cx, obj);
|
2011-03-10 16:17:39 -08:00
|
|
|
}
|
|
|
|
|
2011-05-09 07:12:47 -07:00
|
|
|
inline void
|
2011-06-02 10:40:27 -07:00
|
|
|
FixObjectType(JSContext *cx, JSObject *obj)
|
2011-03-10 16:17:39 -08:00
|
|
|
{
|
2011-06-02 10:40:27 -07:00
|
|
|
if (cx->typeInferenceEnabled())
|
|
|
|
cx->compartment->types.fixObjectType(cx, obj);
|
2011-03-10 16:17:39 -08:00
|
|
|
}
|
|
|
|
|
2011-06-02 10:40:27 -07:00
|
|
|
/* Interface helpers for JSScript */
|
2011-10-27 08:11:26 -07:00
|
|
|
extern void TypeMonitorResult(JSContext *cx, JSScript *script, jsbytecode *pc, const js::Value &rval);
|
2011-07-15 10:14:07 -07:00
|
|
|
extern void TypeDynamicResult(JSContext *cx, JSScript *script, jsbytecode *pc, js::types::Type type);
|
2011-06-02 10:40:27 -07:00
|
|
|
|
2011-07-07 21:02:57 -07:00
|
|
|
inline bool
|
|
|
|
UseNewTypeAtEntry(JSContext *cx, StackFrame *fp)
|
|
|
|
{
|
|
|
|
return fp->isConstructing() && cx->typeInferenceEnabled() &&
|
|
|
|
fp->prev() && fp->prev()->isScriptFrame() &&
|
|
|
|
UseNewType(cx, fp->prev()->script(), fp->prev()->pcQuadratic(cx->stack, fp));
|
|
|
|
}
|
|
|
|
|
2010-10-29 08:05:55 -07:00
|
|
|
/////////////////////////////////////////////////////////////////////
|
2011-06-02 10:40:27 -07:00
|
|
|
// Script interface functions
|
2010-10-29 08:05:55 -07:00
|
|
|
/////////////////////////////////////////////////////////////////////
|
|
|
|
|
2011-11-14 13:03:50 -08:00
|
|
|
inline
|
|
|
|
TypeScript::TypeScript()
|
|
|
|
{
|
|
|
|
this->global = (js::GlobalObject *) GLOBAL_MISSING_SCOPE;
|
|
|
|
}
|
|
|
|
|
2011-07-28 09:16:53 -07:00
|
|
|
/* static */ inline unsigned
|
|
|
|
TypeScript::NumTypeSets(JSScript *script)
|
2011-06-06 08:32:41 -07:00
|
|
|
{
|
2011-08-17 06:48:14 -07:00
|
|
|
return script->nTypeSets + analyze::TotalSlots(script);
|
2011-03-01 13:10:05 -08:00
|
|
|
}
|
|
|
|
|
2011-07-28 09:16:53 -07:00
|
|
|
/* static */ inline TypeSet *
|
|
|
|
TypeScript::ReturnTypes(JSScript *script)
|
2011-03-01 13:10:05 -08:00
|
|
|
{
|
2011-07-28 09:16:53 -07:00
|
|
|
return script->types->typeArray() + script->nTypeSets + js::analyze::CalleeSlot();
|
2011-03-01 13:10:05 -08:00
|
|
|
}
|
|
|
|
|
2011-07-28 09:16:53 -07:00
|
|
|
/* static */ inline TypeSet *
|
|
|
|
TypeScript::ThisTypes(JSScript *script)
|
2011-03-01 13:10:05 -08:00
|
|
|
{
|
2011-07-28 09:16:53 -07:00
|
|
|
return script->types->typeArray() + script->nTypeSets + js::analyze::ThisSlot();
|
2011-03-01 13:10:05 -08:00
|
|
|
}
|
|
|
|
|
2011-04-22 07:59:45 -07:00
|
|
|
/*
|
|
|
|
* Note: for non-escaping arguments and locals, argTypes/localTypes reflect
|
|
|
|
* only the initial type of the variable (e.g. passed values for argTypes,
|
|
|
|
* or undefined for localTypes) and not types from subsequent assignments.
|
|
|
|
*/
|
|
|
|
|
2011-07-28 09:16:53 -07:00
|
|
|
/* static */ inline TypeSet *
|
|
|
|
TypeScript::ArgTypes(JSScript *script, unsigned i)
|
2011-03-01 13:10:05 -08:00
|
|
|
{
|
2011-07-28 09:16:53 -07:00
|
|
|
JS_ASSERT(i < script->function()->nargs);
|
|
|
|
return script->types->typeArray() + script->nTypeSets + js::analyze::ArgSlot(i);
|
2011-04-22 07:59:45 -07:00
|
|
|
}
|
|
|
|
|
2011-07-28 09:16:53 -07:00
|
|
|
/* static */ inline TypeSet *
|
|
|
|
TypeScript::LocalTypes(JSScript *script, unsigned i)
|
2011-04-22 07:59:45 -07:00
|
|
|
{
|
2011-07-28 09:16:53 -07:00
|
|
|
JS_ASSERT(i < script->nfixed);
|
|
|
|
return script->types->typeArray() + script->nTypeSets + js::analyze::LocalSlot(script, i);
|
2011-03-01 13:10:05 -08:00
|
|
|
}
|
|
|
|
|
2011-07-28 09:16:53 -07:00
|
|
|
/* static */ inline TypeSet *
|
|
|
|
TypeScript::SlotTypes(JSScript *script, unsigned slot)
|
2010-12-28 11:53:50 -08:00
|
|
|
{
|
2011-07-28 09:16:53 -07:00
|
|
|
JS_ASSERT(slot < js::analyze::TotalSlots(script));
|
|
|
|
return script->types->typeArray() + script->nTypeSets + slot;
|
2010-12-28 11:53:50 -08:00
|
|
|
}
|
|
|
|
|
2011-07-28 09:16:53 -07:00
|
|
|
/* static */ inline TypeObject *
|
|
|
|
TypeScript::StandardType(JSContext *cx, JSScript *script, JSProtoKey key)
|
2010-12-28 11:53:50 -08:00
|
|
|
{
|
|
|
|
JSObject *proto;
|
2011-07-28 09:16:53 -07:00
|
|
|
if (!js_GetClassPrototype(cx, script->global(), key, &proto, NULL))
|
2010-12-28 11:53:50 -08:00
|
|
|
return NULL;
|
|
|
|
return proto->getNewType(cx);
|
|
|
|
}
|
|
|
|
|
2011-07-21 07:28:01 -07:00
|
|
|
struct AllocationSiteKey {
|
|
|
|
JSScript *script;
|
2011-09-01 12:20:30 -07:00
|
|
|
|
Bug 708735 - Use <stdint.h> types in JSAPI and throughout SpiderMonkey. Continue to provide the {u,}int{8,16,32,64} and JS{Uint,Int}{8,16,32,64} integer types through a single header, however, for a simpler backout strategy -- and also to ease the transition for embedders. r=timeless on switching the jsd API to use the <stdint.h> types, r=luke, r=dmandelin
2011-12-08 19:54:10 -08:00
|
|
|
uint32_t offset : 24;
|
2011-07-21 07:28:01 -07:00
|
|
|
JSProtoKey kind : 8;
|
|
|
|
|
Bug 708735 - Use <stdint.h> types in JSAPI and throughout SpiderMonkey. Continue to provide the {u,}int{8,16,32,64} and JS{Uint,Int}{8,16,32,64} integer types through a single header, however, for a simpler backout strategy -- and also to ease the transition for embedders. r=timeless on switching the jsd API to use the <stdint.h> types, r=luke, r=dmandelin
2011-12-08 19:54:10 -08:00
|
|
|
static const uint32_t OFFSET_LIMIT = (1 << 23);
|
2011-07-21 07:28:01 -07:00
|
|
|
|
|
|
|
AllocationSiteKey() { PodZero(this); }
|
|
|
|
|
|
|
|
typedef AllocationSiteKey Lookup;
|
|
|
|
|
Bug 708735 - Use <stdint.h> types in JSAPI and throughout SpiderMonkey. Continue to provide the {u,}int{8,16,32,64} and JS{Uint,Int}{8,16,32,64} integer types through a single header, however, for a simpler backout strategy -- and also to ease the transition for embedders. r=timeless on switching the jsd API to use the <stdint.h> types, r=luke, r=dmandelin
2011-12-08 19:54:10 -08:00
|
|
|
static inline uint32_t hash(AllocationSiteKey key) {
|
|
|
|
return uint32_t(size_t(key.script->code + key.offset)) ^ key.kind;
|
2011-07-21 07:28:01 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline bool match(const AllocationSiteKey &a, const AllocationSiteKey &b) {
|
|
|
|
return a.script == b.script && a.offset == b.offset && a.kind == b.kind;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2011-07-28 09:16:53 -07:00
|
|
|
/* static */ inline TypeObject *
|
|
|
|
TypeScript::InitObject(JSContext *cx, JSScript *script, const jsbytecode *pc, JSProtoKey kind)
|
2010-10-29 08:05:55 -07:00
|
|
|
{
|
2011-07-21 07:28:01 -07:00
|
|
|
/* :XXX: Limit script->length so we don't need to check the offset up front? */
|
Bug 708735 - Use <stdint.h> types in JSAPI and throughout SpiderMonkey. Continue to provide the {u,}int{8,16,32,64} and JS{Uint,Int}{8,16,32,64} integer types through a single header, however, for a simpler backout strategy -- and also to ease the transition for embedders. r=timeless on switching the jsd API to use the <stdint.h> types, r=luke, r=dmandelin
2011-12-08 19:54:10 -08:00
|
|
|
uint32_t offset = pc - script->code;
|
2010-12-28 11:53:50 -08:00
|
|
|
|
2011-07-28 09:16:53 -07:00
|
|
|
if (!cx->typeInferenceEnabled() || !script->hasGlobal() || offset >= AllocationSiteKey::OFFSET_LIMIT)
|
2011-07-21 07:28:01 -07:00
|
|
|
return GetTypeNewObject(cx, kind);
|
|
|
|
|
|
|
|
AllocationSiteKey key;
|
2011-07-28 09:16:53 -07:00
|
|
|
key.script = script;
|
2011-07-21 07:28:01 -07:00
|
|
|
key.offset = offset;
|
|
|
|
key.kind = kind;
|
|
|
|
|
|
|
|
if (!cx->compartment->types.allocationSiteTable)
|
|
|
|
return cx->compartment->types.newAllocationSiteTypeObject(cx, key);
|
|
|
|
|
|
|
|
AllocationSiteTable::Ptr p = cx->compartment->types.allocationSiteTable->lookup(key);
|
|
|
|
|
|
|
|
if (p)
|
|
|
|
return p->value;
|
|
|
|
return cx->compartment->types.newAllocationSiteTypeObject(cx, key);
|
2010-10-29 08:05:55 -07:00
|
|
|
}
|
|
|
|
|
2011-07-28 09:16:53 -07:00
|
|
|
/* static */ inline void
|
2011-10-27 08:11:26 -07:00
|
|
|
TypeScript::Monitor(JSContext *cx, JSScript *script, jsbytecode *pc, const js::Value &rval)
|
2010-10-29 08:05:55 -07:00
|
|
|
{
|
2011-06-02 10:40:27 -07:00
|
|
|
if (cx->typeInferenceEnabled())
|
2011-07-28 09:16:53 -07:00
|
|
|
TypeMonitorResult(cx, script, pc, rval);
|
2011-03-01 13:10:05 -08:00
|
|
|
}
|
|
|
|
|
2011-07-28 09:16:53 -07:00
|
|
|
/* static */ inline void
|
|
|
|
TypeScript::MonitorOverflow(JSContext *cx, JSScript *script, jsbytecode *pc)
|
2010-11-15 18:13:05 -08:00
|
|
|
{
|
2011-05-14 05:45:13 -07:00
|
|
|
if (cx->typeInferenceEnabled())
|
2011-07-28 09:16:53 -07:00
|
|
|
TypeDynamicResult(cx, script, pc, Type::DoubleType());
|
2010-11-15 18:13:05 -08:00
|
|
|
}
|
|
|
|
|
2011-07-28 09:16:53 -07:00
|
|
|
/* static */ inline void
|
|
|
|
TypeScript::MonitorString(JSContext *cx, JSScript *script, jsbytecode *pc)
|
2011-03-17 21:34:36 -07:00
|
|
|
{
|
2011-05-14 05:45:13 -07:00
|
|
|
if (cx->typeInferenceEnabled())
|
2011-07-28 09:16:53 -07:00
|
|
|
TypeDynamicResult(cx, script, pc, Type::StringType());
|
2011-03-17 21:34:36 -07:00
|
|
|
}
|
|
|
|
|
2011-07-28 09:16:53 -07:00
|
|
|
/* static */ inline void
|
|
|
|
TypeScript::MonitorUnknown(JSContext *cx, JSScript *script, jsbytecode *pc)
|
2010-11-15 18:13:05 -08:00
|
|
|
{
|
2011-05-14 05:45:13 -07:00
|
|
|
if (cx->typeInferenceEnabled())
|
2011-07-28 09:16:53 -07:00
|
|
|
TypeDynamicResult(cx, script, pc, Type::UnknownType());
|
2010-11-15 18:13:05 -08:00
|
|
|
}
|
|
|
|
|
2011-07-28 09:16:53 -07:00
|
|
|
/* static */ inline void
|
|
|
|
TypeScript::MonitorAssign(JSContext *cx, JSScript *script, jsbytecode *pc,
|
2011-06-06 08:32:41 -07:00
|
|
|
JSObject *obj, jsid id, const js::Value &rval)
|
2011-05-16 16:15:37 -07:00
|
|
|
{
|
2011-08-01 22:24:29 -07:00
|
|
|
if (cx->typeInferenceEnabled() && !obj->hasSingletonType()) {
|
2011-05-16 16:15:37 -07:00
|
|
|
/*
|
|
|
|
* Mark as unknown any object which has had dynamic assignments to
|
|
|
|
* non-integer properties at SETELEM opcodes. This avoids making large
|
2011-08-01 22:24:29 -07:00
|
|
|
* numbers of type properties for hashmap-style objects. We don't need
|
|
|
|
* to do this for objects with singleton type, because type properties
|
|
|
|
* are only constructed for them when analyzed scripts depend on those
|
|
|
|
* specific properties.
|
2011-05-16 16:15:37 -07:00
|
|
|
*/
|
Bug 708735 - Use <stdint.h> types in JSAPI and throughout SpiderMonkey. Continue to provide the {u,}int{8,16,32,64} and JS{Uint,Int}{8,16,32,64} integer types through a single header, however, for a simpler backout strategy -- and also to ease the transition for embedders. r=timeless on switching the jsd API to use the <stdint.h> types, r=luke, r=dmandelin
2011-12-08 19:54:10 -08:00
|
|
|
uint32_t i;
|
2011-05-16 16:15:37 -07:00
|
|
|
if (js_IdIsIndex(id, &i))
|
|
|
|
return;
|
2011-07-15 10:14:07 -07:00
|
|
|
MarkTypeObjectUnknownProperties(cx, obj->type());
|
2011-05-16 16:15:37 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-07-28 09:16:53 -07:00
|
|
|
/* static */ inline void
|
|
|
|
TypeScript::SetThis(JSContext *cx, JSScript *script, Type type)
|
2010-10-29 08:05:55 -07:00
|
|
|
{
|
2011-09-01 12:20:30 -07:00
|
|
|
if (!cx->typeInferenceEnabled())
|
2011-05-09 07:12:47 -07:00
|
|
|
return;
|
2011-09-01 12:20:30 -07:00
|
|
|
JS_ASSERT(script->types);
|
2011-03-04 11:28:52 -08:00
|
|
|
|
|
|
|
/* Analyze the script regardless if -a was used. */
|
2011-08-18 08:54:36 -07:00
|
|
|
bool analyze = cx->hasRunOption(JSOPTION_METHODJIT_ALWAYS);
|
2011-03-04 11:28:52 -08:00
|
|
|
|
2011-07-28 09:16:53 -07:00
|
|
|
if (!ThisTypes(script)->hasType(type) || analyze) {
|
2011-06-06 08:32:41 -07:00
|
|
|
AutoEnterTypeInference enter(cx);
|
2010-10-29 08:05:55 -07:00
|
|
|
|
2011-06-06 08:32:41 -07:00
|
|
|
InferSpew(ISpewOps, "externalType: setThis #%u: %s",
|
2011-07-28 09:16:53 -07:00
|
|
|
script->id(), TypeString(type));
|
|
|
|
ThisTypes(script)->addType(cx, type);
|
2011-03-03 14:07:48 -08:00
|
|
|
|
2011-09-01 12:20:30 -07:00
|
|
|
if (analyze && script->types->hasScope())
|
2011-07-28 09:16:53 -07:00
|
|
|
script->ensureRanInference(cx);
|
2011-03-03 14:07:48 -08:00
|
|
|
}
|
2010-10-29 08:05:55 -07:00
|
|
|
}
|
|
|
|
|
2011-07-28 09:16:53 -07:00
|
|
|
/* static */ inline void
|
|
|
|
TypeScript::SetThis(JSContext *cx, JSScript *script, const js::Value &value)
|
2011-03-15 18:22:23 -07:00
|
|
|
{
|
|
|
|
if (cx->typeInferenceEnabled())
|
2011-07-28 09:16:53 -07:00
|
|
|
SetThis(cx, script, GetValueType(cx, value));
|
2011-03-15 18:22:23 -07:00
|
|
|
}
|
|
|
|
|
2011-07-28 09:16:53 -07:00
|
|
|
/* static */ inline void
|
|
|
|
TypeScript::SetLocal(JSContext *cx, JSScript *script, unsigned local, Type type)
|
2010-10-29 08:05:55 -07:00
|
|
|
{
|
2011-09-01 12:20:30 -07:00
|
|
|
if (!cx->typeInferenceEnabled())
|
2011-05-09 07:12:47 -07:00
|
|
|
return;
|
2011-09-01 12:20:30 -07:00
|
|
|
JS_ASSERT(script->types);
|
|
|
|
|
2011-07-28 09:16:53 -07:00
|
|
|
if (!LocalTypes(script, local)->hasType(type)) {
|
2011-06-06 08:32:41 -07:00
|
|
|
AutoEnterTypeInference enter(cx);
|
2011-03-03 14:07:48 -08:00
|
|
|
|
2011-06-06 08:32:41 -07:00
|
|
|
InferSpew(ISpewOps, "externalType: setLocal #%u %u: %s",
|
2011-07-28 09:16:53 -07:00
|
|
|
script->id(), local, TypeString(type));
|
|
|
|
LocalTypes(script, local)->addType(cx, type);
|
2011-03-03 14:07:48 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-07-28 09:16:53 -07:00
|
|
|
/* static */ inline void
|
|
|
|
TypeScript::SetLocal(JSContext *cx, JSScript *script, unsigned local, const js::Value &value)
|
2011-03-11 16:29:38 -08:00
|
|
|
{
|
|
|
|
if (cx->typeInferenceEnabled()) {
|
2011-07-15 10:14:07 -07:00
|
|
|
Type type = GetValueType(cx, value);
|
2011-07-28 09:16:53 -07:00
|
|
|
SetLocal(cx, script, local, type);
|
2011-03-11 16:29:38 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-07-28 09:16:53 -07:00
|
|
|
/* static */ inline void
|
|
|
|
TypeScript::SetArgument(JSContext *cx, JSScript *script, unsigned arg, Type type)
|
2011-03-03 14:07:48 -08:00
|
|
|
{
|
2011-09-01 12:20:30 -07:00
|
|
|
if (!cx->typeInferenceEnabled())
|
2011-05-09 07:12:47 -07:00
|
|
|
return;
|
2011-09-01 12:20:30 -07:00
|
|
|
JS_ASSERT(script->types);
|
|
|
|
|
2011-07-28 09:16:53 -07:00
|
|
|
if (!ArgTypes(script, arg)->hasType(type)) {
|
2011-06-06 08:32:41 -07:00
|
|
|
AutoEnterTypeInference enter(cx);
|
2011-03-03 14:07:48 -08:00
|
|
|
|
2011-06-06 08:32:41 -07:00
|
|
|
InferSpew(ISpewOps, "externalType: setArg #%u %u: %s",
|
2011-07-28 09:16:53 -07:00
|
|
|
script->id(), arg, TypeString(type));
|
|
|
|
ArgTypes(script, arg)->addType(cx, type);
|
2011-03-01 13:10:05 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-07-28 09:16:53 -07:00
|
|
|
/* static */ inline void
|
2011-10-27 08:11:26 -07:00
|
|
|
TypeScript::SetArgument(JSContext *cx, JSScript *script, unsigned arg, const js::Value &value)
|
2011-03-03 14:07:48 -08:00
|
|
|
{
|
|
|
|
if (cx->typeInferenceEnabled()) {
|
2011-07-15 10:14:07 -07:00
|
|
|
Type type = GetValueType(cx, value);
|
2011-07-28 09:16:53 -07:00
|
|
|
SetArgument(cx, script, arg, type);
|
2011-03-03 14:07:48 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-09-01 12:20:30 -07:00
|
|
|
void
|
|
|
|
TypeScript::trace(JSTracer *trc)
|
|
|
|
{
|
|
|
|
if (hasScope() && global)
|
2011-10-25 16:07:42 -07:00
|
|
|
gc::MarkObject(trc, global, "script_global");
|
2011-09-01 12:20:30 -07:00
|
|
|
|
|
|
|
/* Note: nesting does not keep anything alive. */
|
|
|
|
}
|
|
|
|
|
2010-10-29 08:05:55 -07:00
|
|
|
/////////////////////////////////////////////////////////////////////
|
|
|
|
// TypeCompartment
|
|
|
|
/////////////////////////////////////////////////////////////////////
|
|
|
|
|
2011-07-21 07:28:01 -07:00
|
|
|
inline JSCompartment *
|
|
|
|
TypeCompartment::compartment()
|
|
|
|
{
|
|
|
|
return (JSCompartment *)((char *)this - offsetof(JSCompartment, types));
|
|
|
|
}
|
|
|
|
|
2010-10-29 08:05:55 -07:00
|
|
|
inline void
|
2011-07-15 10:14:07 -07:00
|
|
|
TypeCompartment::addPending(JSContext *cx, TypeConstraint *constraint, TypeSet *source, Type type)
|
2010-10-29 08:05:55 -07:00
|
|
|
{
|
|
|
|
JS_ASSERT(this == &cx->compartment->types);
|
2011-03-08 10:21:54 -08:00
|
|
|
JS_ASSERT(!cx->runtime->gcRunning);
|
2010-10-29 08:05:55 -07:00
|
|
|
|
2011-06-15 19:22:27 -07:00
|
|
|
InferSpew(ISpewOps, "pending: %sC%p%s %s",
|
|
|
|
InferSpewColor(constraint), constraint, InferSpewColorReset(),
|
|
|
|
TypeString(type));
|
2010-10-29 08:05:55 -07:00
|
|
|
|
2011-10-14 09:49:29 -07:00
|
|
|
if ((pendingCount == pendingCapacity) && !growPendingArray(cx))
|
|
|
|
return;
|
2010-10-29 08:05:55 -07:00
|
|
|
|
|
|
|
PendingWork &pending = pendingArray[pendingCount++];
|
|
|
|
pending.constraint = constraint;
|
|
|
|
pending.source = source;
|
|
|
|
pending.type = type;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline void
|
|
|
|
TypeCompartment::resolvePending(JSContext *cx)
|
|
|
|
{
|
|
|
|
JS_ASSERT(this == &cx->compartment->types);
|
|
|
|
|
|
|
|
if (resolving) {
|
|
|
|
/* There is an active call further up resolving the worklist. */
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
resolving = true;
|
|
|
|
|
|
|
|
/* Handle all pending type registrations. */
|
|
|
|
while (pendingCount) {
|
|
|
|
const PendingWork &pending = pendingArray[--pendingCount];
|
2011-06-15 19:22:27 -07:00
|
|
|
InferSpew(ISpewOps, "resolve: %sC%p%s %s",
|
|
|
|
InferSpewColor(pending.constraint), pending.constraint,
|
|
|
|
InferSpewColorReset(), TypeString(pending.type));
|
2010-10-29 08:05:55 -07:00
|
|
|
pending.constraint->newType(cx, pending.source, pending.type);
|
|
|
|
}
|
|
|
|
|
|
|
|
resolving = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/////////////////////////////////////////////////////////////////////
|
|
|
|
// TypeSet
|
|
|
|
/////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
/*
|
|
|
|
* The sets of objects and scripts in a type set grow monotonically, are usually
|
|
|
|
* empty, almost always small, and sometimes big. For empty or singleton sets,
|
|
|
|
* the pointer refers directly to the value. For sets fitting into SET_ARRAY_SIZE,
|
|
|
|
* an array of this length is used to store the elements. For larger sets, a hash
|
|
|
|
* table filled to 25%-50% of capacity is used, with collisions resolved by linear
|
|
|
|
* probing. TODO: replace these with jshashtables.
|
|
|
|
*/
|
|
|
|
const unsigned SET_ARRAY_SIZE = 8;
|
|
|
|
|
|
|
|
/* Get the capacity of a set with the given element count. */
|
|
|
|
static inline unsigned
|
|
|
|
HashSetCapacity(unsigned count)
|
|
|
|
{
|
|
|
|
JS_ASSERT(count >= 2);
|
|
|
|
|
|
|
|
if (count <= SET_ARRAY_SIZE)
|
|
|
|
return SET_ARRAY_SIZE;
|
|
|
|
|
|
|
|
unsigned log2;
|
|
|
|
JS_FLOOR_LOG2(log2, count);
|
|
|
|
return 1 << (log2 + 2);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Compute the FNV hash for the low 32 bits of v. */
|
2010-11-24 17:41:52 -08:00
|
|
|
template <class T, class KEY>
|
Bug 708735 - Use <stdint.h> types in JSAPI and throughout SpiderMonkey. Continue to provide the {u,}int{8,16,32,64} and JS{Uint,Int}{8,16,32,64} integer types through a single header, however, for a simpler backout strategy -- and also to ease the transition for embedders. r=timeless on switching the jsd API to use the <stdint.h> types, r=luke, r=dmandelin
2011-12-08 19:54:10 -08:00
|
|
|
static inline uint32_t
|
2010-11-24 17:41:52 -08:00
|
|
|
HashKey(T v)
|
2010-10-29 08:05:55 -07:00
|
|
|
{
|
Bug 708735 - Use <stdint.h> types in JSAPI and throughout SpiderMonkey. Continue to provide the {u,}int{8,16,32,64} and JS{Uint,Int}{8,16,32,64} integer types through a single header, however, for a simpler backout strategy -- and also to ease the transition for embedders. r=timeless on switching the jsd API to use the <stdint.h> types, r=luke, r=dmandelin
2011-12-08 19:54:10 -08:00
|
|
|
uint32_t nv = KEY::keyBits(v);
|
2010-10-29 08:05:55 -07:00
|
|
|
|
Bug 708735 - Use <stdint.h> types in JSAPI and throughout SpiderMonkey. Continue to provide the {u,}int{8,16,32,64} and JS{Uint,Int}{8,16,32,64} integer types through a single header, however, for a simpler backout strategy -- and also to ease the transition for embedders. r=timeless on switching the jsd API to use the <stdint.h> types, r=luke, r=dmandelin
2011-12-08 19:54:10 -08:00
|
|
|
uint32_t hash = 84696351 ^ (nv & 0xff);
|
2010-10-29 08:05:55 -07:00
|
|
|
hash = (hash * 16777619) ^ ((nv >> 8) & 0xff);
|
|
|
|
hash = (hash * 16777619) ^ ((nv >> 16) & 0xff);
|
|
|
|
return (hash * 16777619) ^ ((nv >> 24) & 0xff);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2010-11-24 17:41:52 -08:00
|
|
|
* Insert space for an element into the specified set and grow its capacity if needed.
|
|
|
|
* returned value is an existing or new entry (NULL if new).
|
2010-10-29 08:05:55 -07:00
|
|
|
*/
|
2010-11-24 17:41:52 -08:00
|
|
|
template <class T, class U, class KEY>
|
2011-03-03 14:07:48 -08:00
|
|
|
static U **
|
2011-08-17 06:48:14 -07:00
|
|
|
HashSetInsertTry(JSCompartment *compartment, U **&values, unsigned &count, T key)
|
2010-10-29 08:05:55 -07:00
|
|
|
{
|
|
|
|
unsigned capacity = HashSetCapacity(count);
|
2010-11-24 17:41:52 -08:00
|
|
|
unsigned insertpos = HashKey<T,KEY>(key) & (capacity - 1);
|
2010-10-29 08:05:55 -07:00
|
|
|
|
2010-11-24 17:41:52 -08:00
|
|
|
/* Whether we are converting from a fixed array to hashtable. */
|
|
|
|
bool converting = (count == SET_ARRAY_SIZE);
|
2010-10-29 08:05:55 -07:00
|
|
|
|
2010-11-24 17:41:52 -08:00
|
|
|
if (!converting) {
|
|
|
|
while (values[insertpos] != NULL) {
|
|
|
|
if (KEY::getKey(values[insertpos]) == key)
|
2011-03-03 14:07:48 -08:00
|
|
|
return &values[insertpos];
|
2010-11-24 17:41:52 -08:00
|
|
|
insertpos = (insertpos + 1) & (capacity - 1);
|
2010-10-29 08:05:55 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
count++;
|
|
|
|
unsigned newCapacity = HashSetCapacity(count);
|
|
|
|
|
2010-11-24 17:41:52 -08:00
|
|
|
if (newCapacity == capacity) {
|
|
|
|
JS_ASSERT(!converting);
|
2011-03-03 14:07:48 -08:00
|
|
|
return &values[insertpos];
|
2010-11-24 17:41:52 -08:00
|
|
|
}
|
2010-10-29 08:05:55 -07:00
|
|
|
|
2011-09-22 13:22:30 -07:00
|
|
|
U **newValues = compartment->typeLifoAlloc.newArray<U*>(newCapacity);
|
2011-08-17 06:48:14 -07:00
|
|
|
if (!newValues)
|
2011-03-03 14:07:48 -08:00
|
|
|
return NULL;
|
|
|
|
PodZero(newValues, newCapacity);
|
2010-10-29 08:05:55 -07:00
|
|
|
|
2010-11-24 17:41:52 -08:00
|
|
|
for (unsigned i = 0; i < capacity; i++) {
|
|
|
|
if (values[i]) {
|
|
|
|
unsigned pos = HashKey<T,KEY>(KEY::getKey(values[i])) & (newCapacity - 1);
|
|
|
|
while (newValues[pos] != NULL)
|
|
|
|
pos = (pos + 1) & (newCapacity - 1);
|
|
|
|
newValues[pos] = values[i];
|
|
|
|
}
|
2010-10-29 08:05:55 -07:00
|
|
|
}
|
|
|
|
|
2010-11-24 17:41:52 -08:00
|
|
|
values = newValues;
|
2010-10-29 08:05:55 -07:00
|
|
|
|
2010-11-24 17:41:52 -08:00
|
|
|
insertpos = HashKey<T,KEY>(key) & (newCapacity - 1);
|
|
|
|
while (values[insertpos] != NULL)
|
|
|
|
insertpos = (insertpos + 1) & (newCapacity - 1);
|
2011-03-03 14:07:48 -08:00
|
|
|
return &values[insertpos];
|
2010-10-29 08:05:55 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2010-11-24 17:41:52 -08:00
|
|
|
* Insert an element into the specified set if it is not already there, returning
|
|
|
|
* an entry which is NULL if the element was not there.
|
2010-10-29 08:05:55 -07:00
|
|
|
*/
|
2010-11-24 17:41:52 -08:00
|
|
|
template <class T, class U, class KEY>
|
2011-03-03 14:07:48 -08:00
|
|
|
static inline U **
|
2011-08-17 06:48:14 -07:00
|
|
|
HashSetInsert(JSCompartment *compartment, U **&values, unsigned &count, T key)
|
2010-10-29 08:05:55 -07:00
|
|
|
{
|
|
|
|
if (count == 0) {
|
2010-11-24 17:41:52 -08:00
|
|
|
JS_ASSERT(values == NULL);
|
2010-10-29 08:05:55 -07:00
|
|
|
count++;
|
2011-03-03 14:07:48 -08:00
|
|
|
return (U **) &values;
|
2010-10-29 08:05:55 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
if (count == 1) {
|
2010-11-24 17:41:52 -08:00
|
|
|
U *oldData = (U*) values;
|
2011-03-03 14:07:48 -08:00
|
|
|
if (KEY::getKey(oldData) == key)
|
|
|
|
return (U **) &values;
|
|
|
|
|
2011-09-22 13:22:30 -07:00
|
|
|
values = compartment->typeLifoAlloc.newArray<U*>(SET_ARRAY_SIZE);
|
2011-03-03 14:07:48 -08:00
|
|
|
if (!values) {
|
|
|
|
values = (U **) oldData;
|
|
|
|
return NULL;
|
2010-11-24 17:41:52 -08:00
|
|
|
}
|
2011-03-03 14:07:48 -08:00
|
|
|
PodZero(values, SET_ARRAY_SIZE);
|
2010-11-24 17:41:52 -08:00
|
|
|
count++;
|
2010-10-29 08:05:55 -07:00
|
|
|
|
|
|
|
values[0] = oldData;
|
2011-03-03 14:07:48 -08:00
|
|
|
return &values[1];
|
2010-10-29 08:05:55 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
if (count <= SET_ARRAY_SIZE) {
|
|
|
|
for (unsigned i = 0; i < count; i++) {
|
2010-11-24 17:41:52 -08:00
|
|
|
if (KEY::getKey(values[i]) == key)
|
2011-03-03 14:07:48 -08:00
|
|
|
return &values[i];
|
2010-10-29 08:05:55 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
if (count < SET_ARRAY_SIZE) {
|
2010-11-24 17:41:52 -08:00
|
|
|
count++;
|
2011-03-03 14:07:48 -08:00
|
|
|
return &values[count - 1];
|
2010-10-29 08:05:55 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-08-17 06:48:14 -07:00
|
|
|
return HashSetInsertTry<T,U,KEY>(compartment, values, count, key);
|
2010-10-29 08:05:55 -07:00
|
|
|
}
|
|
|
|
|
2010-11-24 17:41:52 -08:00
|
|
|
/* Lookup an entry in a hash set, return NULL if it does not exist. */
|
|
|
|
template <class T, class U, class KEY>
|
|
|
|
static inline U *
|
|
|
|
HashSetLookup(U **values, unsigned count, T key)
|
2010-10-29 08:05:55 -07:00
|
|
|
{
|
|
|
|
if (count == 0)
|
2010-11-24 17:41:52 -08:00
|
|
|
return NULL;
|
2010-10-29 08:05:55 -07:00
|
|
|
|
|
|
|
if (count == 1)
|
2010-11-24 17:41:52 -08:00
|
|
|
return (KEY::getKey((U *) values) == key) ? (U *) values : NULL;
|
2010-10-29 08:05:55 -07:00
|
|
|
|
|
|
|
if (count <= SET_ARRAY_SIZE) {
|
|
|
|
for (unsigned i = 0; i < count; i++) {
|
2010-11-24 17:41:52 -08:00
|
|
|
if (KEY::getKey(values[i]) == key)
|
|
|
|
return values[i];
|
2010-10-29 08:05:55 -07:00
|
|
|
}
|
2010-11-24 17:41:52 -08:00
|
|
|
return NULL;
|
2010-10-29 08:05:55 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
unsigned capacity = HashSetCapacity(count);
|
2010-11-24 17:41:52 -08:00
|
|
|
unsigned pos = HashKey<T,KEY>(key) & (capacity - 1);
|
2010-10-29 08:05:55 -07:00
|
|
|
|
|
|
|
while (values[pos] != NULL) {
|
2010-11-24 17:41:52 -08:00
|
|
|
if (KEY::getKey(values[pos]) == key)
|
|
|
|
return values[pos];
|
2010-10-29 08:05:55 -07:00
|
|
|
pos = (pos + 1) & (capacity - 1);
|
|
|
|
}
|
|
|
|
|
2010-11-24 17:41:52 -08:00
|
|
|
return NULL;
|
2010-10-29 08:05:55 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
inline bool
|
2011-07-15 10:14:07 -07:00
|
|
|
TypeSet::hasType(Type type)
|
2010-10-29 08:05:55 -07:00
|
|
|
{
|
2010-12-21 07:32:21 -08:00
|
|
|
if (unknown())
|
2010-10-29 08:05:55 -07:00
|
|
|
return true;
|
|
|
|
|
2011-07-15 10:14:07 -07:00
|
|
|
if (type.isUnknown()) {
|
2011-03-01 13:10:05 -08:00
|
|
|
return false;
|
2011-07-15 10:14:07 -07:00
|
|
|
} else if (type.isPrimitive()) {
|
2011-07-21 07:28:01 -07:00
|
|
|
return !!(flags & PrimitiveTypeFlag(type.primitive()));
|
2011-07-15 10:14:07 -07:00
|
|
|
} else if (type.isAnyObject()) {
|
2011-07-21 07:28:01 -07:00
|
|
|
return !!(flags & TYPE_FLAG_ANYOBJECT);
|
2010-11-24 17:41:52 -08:00
|
|
|
} else {
|
2011-07-21 07:28:01 -07:00
|
|
|
return !!(flags & TYPE_FLAG_ANYOBJECT) ||
|
2011-07-15 10:14:07 -07:00
|
|
|
HashSetLookup<TypeObjectKey*,TypeObjectKey,TypeObjectKey>
|
2011-07-21 07:28:01 -07:00
|
|
|
(objectSet, baseObjectCount(), type.objectKey()) != NULL;
|
2010-11-24 17:41:52 -08:00
|
|
|
}
|
2010-10-29 08:05:55 -07:00
|
|
|
}
|
|
|
|
|
2011-07-21 07:28:01 -07:00
|
|
|
inline void
|
Bug 708735 - Use <stdint.h> types in JSAPI and throughout SpiderMonkey. Continue to provide the {u,}int{8,16,32,64} and JS{Uint,Int}{8,16,32,64} integer types through a single header, however, for a simpler backout strategy -- and also to ease the transition for embedders. r=timeless on switching the jsd API to use the <stdint.h> types, r=luke, r=dmandelin
2011-12-08 19:54:10 -08:00
|
|
|
TypeSet::setBaseObjectCount(uint32_t count)
|
2011-07-21 07:28:01 -07:00
|
|
|
{
|
|
|
|
JS_ASSERT(count <= TYPE_FLAG_OBJECT_COUNT_LIMIT);
|
|
|
|
flags = (flags & ~TYPE_FLAG_OBJECT_COUNT_MASK)
|
|
|
|
| (count << TYPE_FLAG_OBJECT_COUNT_SHIFT);
|
|
|
|
}
|
|
|
|
|
2011-03-09 11:04:36 -08:00
|
|
|
inline void
|
2011-07-15 10:14:07 -07:00
|
|
|
TypeSet::clearObjects()
|
2011-03-09 11:04:36 -08:00
|
|
|
{
|
2011-07-21 07:28:01 -07:00
|
|
|
setBaseObjectCount(0);
|
2011-03-09 11:04:36 -08:00
|
|
|
objectSet = NULL;
|
|
|
|
}
|
|
|
|
|
2010-10-29 08:05:55 -07:00
|
|
|
inline void
|
2011-07-15 10:14:07 -07:00
|
|
|
TypeSet::addType(JSContext *cx, Type type)
|
2010-10-29 08:05:55 -07:00
|
|
|
{
|
2011-04-22 07:59:45 -07:00
|
|
|
JS_ASSERT(cx->compartment->activeInference);
|
2010-10-29 08:05:55 -07:00
|
|
|
|
2010-12-21 07:32:21 -08:00
|
|
|
if (unknown())
|
2010-10-29 08:05:55 -07:00
|
|
|
return;
|
|
|
|
|
2011-07-15 10:14:07 -07:00
|
|
|
if (type.isUnknown()) {
|
2011-10-18 11:24:28 -07:00
|
|
|
flags |= TYPE_FLAG_BASE_MASK;
|
2011-07-15 10:14:07 -07:00
|
|
|
clearObjects();
|
2011-10-18 11:24:28 -07:00
|
|
|
JS_ASSERT(unknown());
|
2011-07-15 10:14:07 -07:00
|
|
|
} else if (type.isPrimitive()) {
|
|
|
|
TypeFlags flag = PrimitiveTypeFlag(type.primitive());
|
2011-07-21 07:28:01 -07:00
|
|
|
if (flags & flag)
|
2010-10-29 08:05:55 -07:00
|
|
|
return;
|
|
|
|
|
|
|
|
/* If we add float to a type set it is also considered to contain int. */
|
|
|
|
if (flag == TYPE_FLAG_DOUBLE)
|
|
|
|
flag |= TYPE_FLAG_INT32;
|
|
|
|
|
2011-07-21 07:28:01 -07:00
|
|
|
flags |= flag;
|
2010-10-29 08:05:55 -07:00
|
|
|
} else {
|
2011-07-21 07:28:01 -07:00
|
|
|
if (flags & TYPE_FLAG_ANYOBJECT)
|
2011-07-15 10:14:07 -07:00
|
|
|
return;
|
|
|
|
if (type.isAnyObject())
|
|
|
|
goto unknownObject;
|
Bug 708735 - Use <stdint.h> types in JSAPI and throughout SpiderMonkey. Continue to provide the {u,}int{8,16,32,64} and JS{Uint,Int}{8,16,32,64} integer types through a single header, however, for a simpler backout strategy -- and also to ease the transition for embedders. r=timeless on switching the jsd API to use the <stdint.h> types, r=luke, r=dmandelin
2011-12-08 19:54:10 -08:00
|
|
|
uint32_t objectCount = baseObjectCount();
|
2011-07-15 10:14:07 -07:00
|
|
|
TypeObjectKey *object = type.objectKey();
|
|
|
|
TypeObjectKey **pentry = HashSetInsert<TypeObjectKey *,TypeObjectKey,TypeObjectKey>
|
2011-08-17 06:48:14 -07:00
|
|
|
(cx->compartment, objectSet, objectCount, object);
|
|
|
|
if (!pentry) {
|
|
|
|
cx->compartment->types.setPendingNukeTypes(cx);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (*pentry)
|
2010-10-29 08:05:55 -07:00
|
|
|
return;
|
2011-03-03 14:07:48 -08:00
|
|
|
*pentry = object;
|
2011-03-09 11:04:36 -08:00
|
|
|
|
2011-07-21 07:28:01 -07:00
|
|
|
setBaseObjectCount(objectCount);
|
|
|
|
|
2011-07-31 08:40:46 -07:00
|
|
|
if (objectCount == TYPE_FLAG_OBJECT_COUNT_LIMIT)
|
|
|
|
goto unknownObject;
|
|
|
|
|
2011-07-15 10:14:07 -07:00
|
|
|
if (type.isTypeObject()) {
|
|
|
|
TypeObject *nobject = type.typeObject();
|
|
|
|
JS_ASSERT(!nobject->singleton);
|
|
|
|
if (nobject->unknownProperties())
|
|
|
|
goto unknownObject;
|
|
|
|
if (objectCount > 1) {
|
|
|
|
nobject->contribution += (objectCount - 1) * (objectCount - 1);
|
|
|
|
if (nobject->contribution >= TypeObject::CONTRIBUTION_LIMIT) {
|
|
|
|
InferSpew(ISpewOps, "limitUnknown: %sT%p%s",
|
|
|
|
InferSpewColor(this), this, InferSpewColorReset());
|
|
|
|
goto unknownObject;
|
|
|
|
}
|
2011-06-11 09:46:48 -07:00
|
|
|
}
|
2011-03-09 11:04:36 -08:00
|
|
|
}
|
2010-10-29 08:05:55 -07:00
|
|
|
}
|
|
|
|
|
2011-07-15 10:14:07 -07:00
|
|
|
if (false) {
|
|
|
|
unknownObject:
|
|
|
|
type = Type::AnyObjectType();
|
2011-07-21 07:28:01 -07:00
|
|
|
flags |= TYPE_FLAG_ANYOBJECT;
|
2011-07-15 10:14:07 -07:00
|
|
|
clearObjects();
|
|
|
|
}
|
|
|
|
|
2011-06-15 19:22:27 -07:00
|
|
|
InferSpew(ISpewOps, "addType: %sT%p%s %s",
|
|
|
|
InferSpewColor(this), this, InferSpewColorReset(),
|
|
|
|
TypeString(type));
|
2011-03-17 09:42:56 -07:00
|
|
|
|
2010-10-29 08:05:55 -07:00
|
|
|
/* Propagate the type to all constraints. */
|
|
|
|
TypeConstraint *constraint = constraintList;
|
|
|
|
while (constraint) {
|
|
|
|
cx->compartment->types.addPending(cx, constraint, this, type);
|
|
|
|
constraint = constraint->next;
|
|
|
|
}
|
|
|
|
|
|
|
|
cx->compartment->types.resolvePending(cx);
|
|
|
|
}
|
|
|
|
|
2011-04-11 20:10:46 -07:00
|
|
|
inline void
|
|
|
|
TypeSet::setOwnProperty(JSContext *cx, bool configured)
|
|
|
|
{
|
|
|
|
TypeFlags nflags = TYPE_FLAG_OWN_PROPERTY | (configured ? TYPE_FLAG_CONFIGURED_PROPERTY : 0);
|
|
|
|
|
2011-07-21 07:28:01 -07:00
|
|
|
if ((flags & nflags) == nflags)
|
2011-04-11 20:10:46 -07:00
|
|
|
return;
|
|
|
|
|
2011-07-21 07:28:01 -07:00
|
|
|
flags |= nflags;
|
2011-04-11 20:10:46 -07:00
|
|
|
|
|
|
|
/* Propagate the change to all constraints. */
|
|
|
|
TypeConstraint *constraint = constraintList;
|
|
|
|
while (constraint) {
|
|
|
|
constraint->newPropertyState(cx, this);
|
|
|
|
constraint = constraint->next;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-04-05 18:12:03 -07:00
|
|
|
inline unsigned
|
|
|
|
TypeSet::getObjectCount()
|
|
|
|
{
|
2011-07-15 10:14:07 -07:00
|
|
|
JS_ASSERT(!unknownObject());
|
Bug 708735 - Use <stdint.h> types in JSAPI and throughout SpiderMonkey. Continue to provide the {u,}int{8,16,32,64} and JS{Uint,Int}{8,16,32,64} integer types through a single header, however, for a simpler backout strategy -- and also to ease the transition for embedders. r=timeless on switching the jsd API to use the <stdint.h> types, r=luke, r=dmandelin
2011-12-08 19:54:10 -08:00
|
|
|
uint32_t count = baseObjectCount();
|
2011-07-21 07:28:01 -07:00
|
|
|
if (count > SET_ARRAY_SIZE)
|
|
|
|
return HashSetCapacity(count);
|
|
|
|
return count;
|
2011-04-05 18:12:03 -07:00
|
|
|
}
|
|
|
|
|
2011-07-15 10:14:07 -07:00
|
|
|
inline TypeObjectKey *
|
2011-04-05 18:12:03 -07:00
|
|
|
TypeSet::getObject(unsigned i)
|
|
|
|
{
|
2011-07-15 10:14:07 -07:00
|
|
|
JS_ASSERT(i < getObjectCount());
|
2011-07-21 07:28:01 -07:00
|
|
|
if (baseObjectCount() == 1) {
|
2011-04-05 18:12:03 -07:00
|
|
|
JS_ASSERT(i == 0);
|
2011-07-15 10:14:07 -07:00
|
|
|
return (TypeObjectKey *) objectSet;
|
2011-04-05 18:12:03 -07:00
|
|
|
}
|
|
|
|
return objectSet[i];
|
|
|
|
}
|
|
|
|
|
2011-07-15 10:14:07 -07:00
|
|
|
inline JSObject *
|
|
|
|
TypeSet::getSingleObject(unsigned i)
|
|
|
|
{
|
|
|
|
TypeObjectKey *key = getObject(i);
|
|
|
|
return ((jsuword) key & 1) ? (JSObject *)((jsuword) key ^ 1) : NULL;
|
|
|
|
}
|
|
|
|
|
2011-05-12 20:07:23 -07:00
|
|
|
inline TypeObject *
|
2011-07-15 10:14:07 -07:00
|
|
|
TypeSet::getTypeObject(unsigned i)
|
2011-05-12 20:07:23 -07:00
|
|
|
{
|
2011-07-15 10:14:07 -07:00
|
|
|
TypeObjectKey *key = getObject(i);
|
|
|
|
return (key && !((jsuword) key & 1)) ? (TypeObject *) key : NULL;
|
2011-05-12 20:07:23 -07:00
|
|
|
}
|
|
|
|
|
2010-10-29 08:05:55 -07:00
|
|
|
/////////////////////////////////////////////////////////////////////
|
|
|
|
// TypeCallsite
|
|
|
|
/////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
inline
|
2011-05-20 19:33:06 -07:00
|
|
|
TypeCallsite::TypeCallsite(JSContext *cx, JSScript *script, jsbytecode *pc,
|
2010-12-28 11:53:50 -08:00
|
|
|
bool isNew, unsigned argumentCount)
|
|
|
|
: script(script), pc(pc), isNew(isNew), argumentCount(argumentCount),
|
2011-05-20 19:33:06 -07:00
|
|
|
thisTypes(NULL), returnTypes(NULL)
|
2010-10-29 08:05:55 -07:00
|
|
|
{
|
2011-03-03 14:07:48 -08:00
|
|
|
/* Caller must check for failure. */
|
2011-09-22 13:22:30 -07:00
|
|
|
argumentTypes = cx->typeLifoAlloc().newArray<TypeSet*>(argumentCount);
|
2010-10-29 08:05:55 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/////////////////////////////////////////////////////////////////////
|
2010-11-24 17:41:52 -08:00
|
|
|
// TypeObject
|
2010-10-29 08:05:55 -07:00
|
|
|
/////////////////////////////////////////////////////////////////////
|
|
|
|
|
2011-08-26 08:55:00 -07:00
|
|
|
inline TypeObject::TypeObject(JSObject *proto, bool function, bool unknown)
|
2011-06-15 11:26:12 -07:00
|
|
|
{
|
2011-07-15 10:14:07 -07:00
|
|
|
PodZero(this);
|
|
|
|
|
|
|
|
this->proto = proto;
|
2011-09-01 12:20:30 -07:00
|
|
|
|
2011-07-21 07:28:01 -07:00
|
|
|
if (function)
|
|
|
|
flags |= OBJECT_FLAG_FUNCTION;
|
|
|
|
if (unknown)
|
|
|
|
flags |= OBJECT_FLAG_UNKNOWN_MASK;
|
2011-07-15 10:14:07 -07:00
|
|
|
|
2011-08-26 08:55:00 -07:00
|
|
|
InferSpew(ISpewOps, "newObject: %s", TypeObjectString(this));
|
2011-06-15 11:26:12 -07:00
|
|
|
}
|
|
|
|
|
Bug 708735 - Use <stdint.h> types in JSAPI and throughout SpiderMonkey. Continue to provide the {u,}int{8,16,32,64} and JS{Uint,Int}{8,16,32,64} integer types through a single header, however, for a simpler backout strategy -- and also to ease the transition for embedders. r=timeless on switching the jsd API to use the <stdint.h> types, r=luke, r=dmandelin
2011-12-08 19:54:10 -08:00
|
|
|
inline uint32_t
|
2011-07-21 07:28:01 -07:00
|
|
|
TypeObject::basePropertyCount() const
|
|
|
|
{
|
|
|
|
return (flags & OBJECT_FLAG_PROPERTY_COUNT_MASK) >> OBJECT_FLAG_PROPERTY_COUNT_SHIFT;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline void
|
Bug 708735 - Use <stdint.h> types in JSAPI and throughout SpiderMonkey. Continue to provide the {u,}int{8,16,32,64} and JS{Uint,Int}{8,16,32,64} integer types through a single header, however, for a simpler backout strategy -- and also to ease the transition for embedders. r=timeless on switching the jsd API to use the <stdint.h> types, r=luke, r=dmandelin
2011-12-08 19:54:10 -08:00
|
|
|
TypeObject::setBasePropertyCount(uint32_t count)
|
2011-07-21 07:28:01 -07:00
|
|
|
{
|
|
|
|
JS_ASSERT(count <= OBJECT_FLAG_PROPERTY_COUNT_LIMIT);
|
|
|
|
flags = (flags & ~OBJECT_FLAG_PROPERTY_COUNT_MASK)
|
|
|
|
| (count << OBJECT_FLAG_PROPERTY_COUNT_SHIFT);
|
|
|
|
}
|
|
|
|
|
2010-10-29 08:05:55 -07:00
|
|
|
inline TypeSet *
|
2010-11-24 17:41:52 -08:00
|
|
|
TypeObject::getProperty(JSContext *cx, jsid id, bool assign)
|
2010-10-29 08:05:55 -07:00
|
|
|
{
|
2011-04-22 07:59:45 -07:00
|
|
|
JS_ASSERT(cx->compartment->activeInference);
|
2010-12-18 20:44:51 -08:00
|
|
|
JS_ASSERT(JSID_IS_VOID(id) || JSID_IS_EMPTY(id) || JSID_IS_STRING(id));
|
2011-05-20 19:33:06 -07:00
|
|
|
JS_ASSERT_IF(!JSID_IS_EMPTY(id), id == MakeTypeId(cx, id));
|
2011-04-05 18:12:03 -07:00
|
|
|
JS_ASSERT(!unknownProperties());
|
2010-10-29 08:05:55 -07:00
|
|
|
|
Bug 708735 - Use <stdint.h> types in JSAPI and throughout SpiderMonkey. Continue to provide the {u,}int{8,16,32,64} and JS{Uint,Int}{8,16,32,64} integer types through a single header, however, for a simpler backout strategy -- and also to ease the transition for embedders. r=timeless on switching the jsd API to use the <stdint.h> types, r=luke, r=dmandelin
2011-12-08 19:54:10 -08:00
|
|
|
uint32_t propertyCount = basePropertyCount();
|
2011-03-03 14:07:48 -08:00
|
|
|
Property **pprop = HashSetInsert<jsid,Property,Property>
|
2011-08-17 06:48:14 -07:00
|
|
|
(cx->compartment, propertySet, propertyCount, id);
|
|
|
|
if (!pprop) {
|
|
|
|
cx->compartment->types.setPendingNukeTypes(cx);
|
2011-03-03 14:07:48 -08:00
|
|
|
return NULL;
|
2011-08-17 06:48:14 -07:00
|
|
|
}
|
2010-11-20 15:45:52 -08:00
|
|
|
|
2011-07-21 07:28:01 -07:00
|
|
|
if (!*pprop) {
|
2011-07-31 08:40:46 -07:00
|
|
|
setBasePropertyCount(propertyCount);
|
|
|
|
if (!addProperty(cx, id, pprop))
|
|
|
|
return NULL;
|
|
|
|
if (propertyCount == OBJECT_FLAG_PROPERTY_COUNT_LIMIT) {
|
2011-07-21 07:28:01 -07:00
|
|
|
markUnknown(cx);
|
|
|
|
TypeSet *types = TypeSet::make(cx, "propertyOverflow");
|
|
|
|
types->addType(cx, Type::UnknownType());
|
|
|
|
return types;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
TypeSet *types = &(*pprop)->types;
|
|
|
|
|
2011-04-11 20:10:46 -07:00
|
|
|
if (assign)
|
2011-07-21 07:28:01 -07:00
|
|
|
types->setOwnProperty(cx, false);
|
2011-04-11 20:10:46 -07:00
|
|
|
|
2011-07-21 07:28:01 -07:00
|
|
|
return types;
|
2010-10-29 08:05:55 -07:00
|
|
|
}
|
|
|
|
|
2011-07-21 07:28:01 -07:00
|
|
|
inline TypeSet *
|
|
|
|
TypeObject::maybeGetProperty(JSContext *cx, jsid id)
|
2011-07-15 10:14:07 -07:00
|
|
|
{
|
2011-07-21 07:28:01 -07:00
|
|
|
JS_ASSERT(JSID_IS_VOID(id) || JSID_IS_EMPTY(id) || JSID_IS_STRING(id));
|
|
|
|
JS_ASSERT_IF(!JSID_IS_EMPTY(id), id == MakeTypeId(cx, id));
|
2011-07-15 10:14:07 -07:00
|
|
|
JS_ASSERT(!unknownProperties());
|
|
|
|
|
2011-07-21 07:28:01 -07:00
|
|
|
Property *prop = HashSetLookup<jsid,Property,Property>
|
|
|
|
(propertySet, basePropertyCount(), id);
|
|
|
|
|
|
|
|
return prop ? &prop->types : NULL;
|
2011-07-15 10:14:07 -07:00
|
|
|
}
|
|
|
|
|
2011-04-05 18:12:03 -07:00
|
|
|
inline unsigned
|
|
|
|
TypeObject::getPropertyCount()
|
|
|
|
{
|
Bug 708735 - Use <stdint.h> types in JSAPI and throughout SpiderMonkey. Continue to provide the {u,}int{8,16,32,64} and JS{Uint,Int}{8,16,32,64} integer types through a single header, however, for a simpler backout strategy -- and also to ease the transition for embedders. r=timeless on switching the jsd API to use the <stdint.h> types, r=luke, r=dmandelin
2011-12-08 19:54:10 -08:00
|
|
|
uint32_t count = basePropertyCount();
|
2011-07-21 07:28:01 -07:00
|
|
|
if (count > SET_ARRAY_SIZE)
|
|
|
|
return HashSetCapacity(count);
|
|
|
|
return count;
|
2011-04-05 18:12:03 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
inline Property *
|
|
|
|
TypeObject::getProperty(unsigned i)
|
|
|
|
{
|
2011-07-21 07:28:01 -07:00
|
|
|
JS_ASSERT(i < getPropertyCount());
|
|
|
|
if (basePropertyCount() == 1) {
|
2011-04-05 18:12:03 -07:00
|
|
|
JS_ASSERT(i == 0);
|
|
|
|
return (Property *) propertySet;
|
|
|
|
}
|
|
|
|
return propertySet[i];
|
|
|
|
}
|
|
|
|
|
2011-06-15 11:26:12 -07:00
|
|
|
inline void
|
|
|
|
TypeObject::setFlagsFromKey(JSContext *cx, JSProtoKey key)
|
2010-12-18 20:44:51 -08:00
|
|
|
{
|
2011-06-15 11:26:12 -07:00
|
|
|
TypeObjectFlags flags = 0;
|
2010-12-18 20:44:51 -08:00
|
|
|
|
2011-06-15 11:26:12 -07:00
|
|
|
switch (key) {
|
|
|
|
case JSProto_Function:
|
2011-07-21 07:28:01 -07:00
|
|
|
JS_ASSERT(isFunction());
|
2011-06-15 11:26:12 -07:00
|
|
|
/* FALLTHROUGH */
|
2010-12-18 20:44:51 -08:00
|
|
|
|
2011-06-15 11:26:12 -07:00
|
|
|
case JSProto_Object:
|
|
|
|
flags = OBJECT_FLAG_NON_DENSE_ARRAY
|
|
|
|
| OBJECT_FLAG_NON_PACKED_ARRAY
|
|
|
|
| OBJECT_FLAG_NON_TYPED_ARRAY;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case JSProto_Array:
|
|
|
|
flags = OBJECT_FLAG_NON_TYPED_ARRAY;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
/* :XXX: abstract */
|
|
|
|
JS_ASSERT(key == JSProto_Int8Array ||
|
|
|
|
key == JSProto_Uint8Array ||
|
|
|
|
key == JSProto_Int16Array ||
|
|
|
|
key == JSProto_Uint16Array ||
|
|
|
|
key == JSProto_Int32Array ||
|
|
|
|
key == JSProto_Uint32Array ||
|
|
|
|
key == JSProto_Float32Array ||
|
|
|
|
key == JSProto_Float64Array ||
|
|
|
|
key == JSProto_Uint8ClampedArray);
|
|
|
|
flags = OBJECT_FLAG_NON_DENSE_ARRAY
|
|
|
|
| OBJECT_FLAG_NON_PACKED_ARRAY;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!hasAllFlags(flags))
|
|
|
|
setFlags(cx, flags);
|
2010-12-18 20:44:51 -08:00
|
|
|
}
|
|
|
|
|
2011-09-01 12:20:30 -07:00
|
|
|
inline JSObject *
|
|
|
|
TypeObject::getGlobal()
|
|
|
|
{
|
|
|
|
if (singleton)
|
|
|
|
return singleton->getGlobal();
|
|
|
|
if (interpretedFunction && interpretedFunction->script()->compileAndGo)
|
|
|
|
return interpretedFunction->getGlobal();
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2011-10-25 16:07:42 -07:00
|
|
|
inline void
|
|
|
|
TypeObject::writeBarrierPre(TypeObject *type)
|
|
|
|
{
|
|
|
|
#ifdef JSGC_INCREMENTAL
|
2011-11-14 13:03:50 -08:00
|
|
|
if (!type)
|
2011-10-25 16:07:42 -07:00
|
|
|
return;
|
|
|
|
|
|
|
|
JSCompartment *comp = type->compartment();
|
|
|
|
if (comp->needsBarrier())
|
|
|
|
MarkTypeObjectUnbarriered(comp->barrierTracer(), type, "write barrier");
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
inline void
|
|
|
|
TypeObject::writeBarrierPost(TypeObject *type, void *addr)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2011-11-14 13:03:50 -08:00
|
|
|
inline void
|
|
|
|
TypeObject::readBarrier(TypeObject *type)
|
|
|
|
{
|
|
|
|
#ifdef JSGC_INCREMENTAL
|
|
|
|
JSCompartment *comp = type->compartment();
|
2011-12-28 23:56:55 -08:00
|
|
|
if (comp->needsBarrier())
|
|
|
|
MarkTypeObjectUnbarriered(comp->barrierTracer(), type, "read barrier");
|
2011-11-14 13:03:50 -08:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2011-10-25 16:07:42 -07:00
|
|
|
inline void
|
|
|
|
TypeNewScript::writeBarrierPre(TypeNewScript *newScript)
|
|
|
|
{
|
|
|
|
#ifdef JSGC_INCREMENTAL
|
|
|
|
if (!newScript)
|
|
|
|
return;
|
|
|
|
|
|
|
|
JSCompartment *comp = newScript->fun->compartment();
|
|
|
|
if (comp->needsBarrier()) {
|
|
|
|
MarkObjectUnbarriered(comp->barrierTracer(), newScript->fun, "write barrier");
|
|
|
|
MarkShapeUnbarriered(comp->barrierTracer(), newScript->shape, "write barrier");
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
inline void
|
|
|
|
TypeNewScript::writeBarrierPost(TypeNewScript *newScript, void *addr)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
inline
|
|
|
|
Property::Property(jsid id)
|
|
|
|
: id(id)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
inline
|
|
|
|
Property::Property(const Property &o)
|
|
|
|
: id(o.id.get()), types(o.types)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2010-12-18 20:44:51 -08:00
|
|
|
} } /* namespace js::types */
|
|
|
|
|
2011-06-06 08:32:41 -07:00
|
|
|
inline bool
|
2011-10-21 14:31:01 -07:00
|
|
|
JSScript::ensureHasTypes(JSContext *cx)
|
2011-07-28 09:16:53 -07:00
|
|
|
{
|
2011-10-21 14:31:01 -07:00
|
|
|
return types || makeTypes(cx);
|
2011-07-28 09:16:53 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
inline bool
|
2011-10-21 14:31:01 -07:00
|
|
|
JSScript::ensureRanAnalysis(JSContext *cx, JSObject *scope)
|
2011-07-28 09:16:53 -07:00
|
|
|
{
|
2011-12-31 06:13:01 -08:00
|
|
|
if (!ensureHasTypes(cx))
|
2011-09-01 12:20:30 -07:00
|
|
|
return false;
|
2011-12-31 06:13:01 -08:00
|
|
|
if (!types->hasScope() && !js::types::TypeScript::SetScope(cx, this, scope))
|
|
|
|
return false;
|
|
|
|
if (!hasAnalysis() && !makeAnalysis(cx))
|
2011-07-28 09:16:53 -07:00
|
|
|
return false;
|
2011-12-31 06:13:01 -08:00
|
|
|
JS_ASSERT(analysis()->ranBytecode());
|
2011-07-28 09:16:53 -07:00
|
|
|
return true;
|
2011-06-06 08:32:41 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
inline bool
|
|
|
|
JSScript::ensureRanInference(JSContext *cx)
|
|
|
|
{
|
2011-10-21 14:31:01 -07:00
|
|
|
if (!ensureRanAnalysis(cx, NULL))
|
2011-07-28 09:16:53 -07:00
|
|
|
return false;
|
|
|
|
if (!analysis()->ranInference()) {
|
2011-06-06 08:32:41 -07:00
|
|
|
js::types::AutoEnterTypeInference enter(cx);
|
2011-07-28 09:16:53 -07:00
|
|
|
analysis()->analyzeTypes(cx);
|
2011-06-06 08:32:41 -07:00
|
|
|
}
|
2011-10-17 14:18:23 -07:00
|
|
|
return !analysis()->OOM() &&
|
|
|
|
!cx->compartment->types.pendingNukeTypes;
|
2011-07-28 09:16:53 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
inline bool
|
|
|
|
JSScript::hasAnalysis()
|
|
|
|
{
|
|
|
|
return types && types->analysis;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline js::analyze::ScriptAnalysis *
|
|
|
|
JSScript::analysis()
|
|
|
|
{
|
|
|
|
JS_ASSERT(hasAnalysis());
|
|
|
|
return types->analysis;
|
2011-06-06 08:32:41 -07:00
|
|
|
}
|
|
|
|
|
2011-09-01 12:20:30 -07:00
|
|
|
inline void
|
|
|
|
JSScript::clearAnalysis()
|
|
|
|
{
|
|
|
|
if (types)
|
|
|
|
types->analysis = NULL;
|
|
|
|
}
|
|
|
|
|
2011-04-22 07:59:45 -07:00
|
|
|
inline void
|
Bug 708735 - Use <stdint.h> types in JSAPI and throughout SpiderMonkey. Continue to provide the {u,}int{8,16,32,64} and JS{Uint,Int}{8,16,32,64} integer types through a single header, however, for a simpler backout strategy -- and also to ease the transition for embedders. r=timeless on switching the jsd API to use the <stdint.h> types, r=luke, r=dmandelin
2011-12-08 19:54:10 -08:00
|
|
|
js::analyze::ScriptAnalysis::addPushedType(JSContext *cx, uint32_t offset, uint32_t which,
|
2011-07-15 10:14:07 -07:00
|
|
|
js::types::Type type)
|
2011-04-22 07:59:45 -07:00
|
|
|
{
|
|
|
|
js::types::TypeSet *pushed = pushedTypes(offset, which);
|
|
|
|
pushed->addType(cx, type);
|
|
|
|
}
|
|
|
|
|
2011-10-07 20:09:09 -07:00
|
|
|
inline js::types::TypeObject *
|
|
|
|
JSCompartment::getEmptyType(JSContext *cx)
|
|
|
|
{
|
|
|
|
if (!emptyTypeObject)
|
|
|
|
emptyTypeObject = types.newTypeObject(cx, NULL, JSProto_Object, NULL, true);
|
|
|
|
return emptyTypeObject;
|
|
|
|
}
|
|
|
|
|
2010-10-29 08:05:55 -07:00
|
|
|
#endif // jsinferinlines_h___
|