2012-08-28 02:41:49 +08:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
2013-08-07 09:43:25 +08:00
|
|
|
* vim: set ts=8 sts=4 et sw=4 tw=99:
|
2012-10-19 11:48:42 +08:00
|
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2012-08-28 02:41:49 +08:00
|
|
|
|
2013-10-30 21:55:19 +08:00
|
|
|
#ifndef jsfriendapi_h
|
|
|
|
#define jsfriendapi_h
|
2012-08-28 02:41:49 +08:00
|
|
|
|
2013-10-30 21:55:19 +08:00
|
|
|
#include "mozilla/MemoryReporting.h"
|
2013-04-10 11:19:43 +08:00
|
|
|
|
2014-02-07 15:12:54 +08:00
|
|
|
#include "jsbytecode.h"
|
2013-10-30 21:55:19 +08:00
|
|
|
#include "jspubtd.h"
|
|
|
|
|
|
|
|
#include "js/CallArgs.h"
|
2014-02-07 15:12:54 +08:00
|
|
|
#include "js/CallNonGenericMethod.h"
|
|
|
|
#include "js/Class.h"
|
2012-08-28 02:41:49 +08:00
|
|
|
|
2013-02-27 16:57:36 +08:00
|
|
|
/*
|
|
|
|
* This macro checks if the stack pointer has exceeded a given limit. If
|
|
|
|
* |tolerance| is non-zero, it returns true only if the stack pointer has
|
|
|
|
* exceeded the limit by more than |tolerance| bytes.
|
|
|
|
*/
|
|
|
|
#if JS_STACK_GROWTH_DIRECTION > 0
|
|
|
|
# define JS_CHECK_STACK_SIZE_WITH_TOLERANCE(limit, sp, tolerance) \
|
|
|
|
((uintptr_t)(sp) < (limit)+(tolerance))
|
|
|
|
#else
|
|
|
|
# define JS_CHECK_STACK_SIZE_WITH_TOLERANCE(limit, sp, tolerance) \
|
|
|
|
((uintptr_t)(sp) > (limit)-(tolerance))
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#define JS_CHECK_STACK_SIZE(limit, lval) JS_CHECK_STACK_SIZE_WITH_TOLERANCE(limit, lval, 0)
|
2012-08-28 02:41:49 +08:00
|
|
|
|
2014-02-07 15:12:54 +08:00
|
|
|
class JSAtom;
|
|
|
|
struct JSErrorFormatString;
|
|
|
|
class JSLinearString;
|
|
|
|
struct JSJitInfo;
|
|
|
|
class JSErrorReport;
|
|
|
|
|
2013-10-30 21:55:19 +08:00
|
|
|
namespace JS {
|
|
|
|
template <class T>
|
|
|
|
class Heap;
|
|
|
|
} /* namespace JS */
|
|
|
|
|
2012-08-28 02:41:49 +08:00
|
|
|
extern JS_FRIEND_API(void)
|
|
|
|
JS_SetGrayGCRootsTracer(JSRuntime *rt, JSTraceDataOp traceOp, void *data);
|
|
|
|
|
|
|
|
extern JS_FRIEND_API(JSString *)
|
|
|
|
JS_GetAnonymousString(JSRuntime *rt);
|
|
|
|
|
|
|
|
extern JS_FRIEND_API(JSObject *)
|
2013-08-07 09:43:25 +08:00
|
|
|
JS_FindCompilationScope(JSContext *cx, JSObject *obj);
|
2012-08-28 02:41:49 +08:00
|
|
|
|
|
|
|
extern JS_FRIEND_API(JSFunction *)
|
2013-08-07 09:43:25 +08:00
|
|
|
JS_GetObjectFunction(JSObject *obj);
|
2012-08-28 02:41:49 +08:00
|
|
|
|
2014-02-07 15:12:54 +08:00
|
|
|
extern JS_FRIEND_API(bool)
|
2012-08-28 02:41:49 +08:00
|
|
|
JS_SplicePrototype(JSContext *cx, JSObject *obj, JSObject *proto);
|
|
|
|
|
|
|
|
extern JS_FRIEND_API(JSObject *)
|
2014-02-07 15:12:54 +08:00
|
|
|
JS_NewObjectWithUniqueType(JSContext *cx, const JSClass *clasp, JSObject *proto, JSObject *parent);
|
2012-08-28 02:41:49 +08:00
|
|
|
|
|
|
|
extern JS_FRIEND_API(uint32_t)
|
2013-10-30 21:55:19 +08:00
|
|
|
JS_ObjectCountDynamicSlots(JS::HandleObject obj);
|
2012-08-28 02:41:49 +08:00
|
|
|
|
|
|
|
extern JS_FRIEND_API(size_t)
|
|
|
|
JS_SetProtoCalled(JSContext *cx);
|
|
|
|
|
|
|
|
extern JS_FRIEND_API(size_t)
|
|
|
|
JS_GetCustomIteratorCount(JSContext *cx);
|
|
|
|
|
2014-02-07 15:12:54 +08:00
|
|
|
extern JS_FRIEND_API(bool)
|
2012-08-28 02:41:49 +08:00
|
|
|
JS_NondeterministicGetWeakMapKeys(JSContext *cx, JSObject *obj, JSObject **ret);
|
|
|
|
|
2012-10-19 11:48:42 +08:00
|
|
|
/*
|
|
|
|
* Determine whether the given object is backed by a DeadObjectProxy.
|
|
|
|
*
|
|
|
|
* Such objects hold no other objects (they have no outgoing reference edges)
|
|
|
|
* and will throw if you touch them (e.g. by reading/writing a property).
|
|
|
|
*/
|
2014-02-07 15:12:54 +08:00
|
|
|
extern JS_FRIEND_API(bool)
|
2012-10-19 11:48:42 +08:00
|
|
|
JS_IsDeadWrapper(JSObject *obj);
|
|
|
|
|
2012-08-28 02:41:49 +08:00
|
|
|
/*
|
|
|
|
* Used by the cycle collector to trace through the shape and all
|
|
|
|
* shapes it reaches, marking all non-shape children found in the
|
|
|
|
* process. Uses bounded stack space.
|
|
|
|
*/
|
|
|
|
extern JS_FRIEND_API(void)
|
|
|
|
JS_TraceShapeCycleCollectorChildren(JSTracer *trc, void *shape);
|
|
|
|
|
|
|
|
enum {
|
|
|
|
JS_TELEMETRY_GC_REASON,
|
|
|
|
JS_TELEMETRY_GC_IS_COMPARTMENTAL,
|
|
|
|
JS_TELEMETRY_GC_MS,
|
2012-10-31 10:33:43 +08:00
|
|
|
JS_TELEMETRY_GC_MAX_PAUSE_MS,
|
2012-08-28 02:41:49 +08:00
|
|
|
JS_TELEMETRY_GC_MARK_MS,
|
|
|
|
JS_TELEMETRY_GC_SWEEP_MS,
|
2012-10-31 10:33:43 +08:00
|
|
|
JS_TELEMETRY_GC_MARK_ROOTS_MS,
|
|
|
|
JS_TELEMETRY_GC_MARK_GRAY_MS,
|
2012-08-28 02:41:49 +08:00
|
|
|
JS_TELEMETRY_GC_SLICE_MS,
|
|
|
|
JS_TELEMETRY_GC_MMU_50,
|
|
|
|
JS_TELEMETRY_GC_RESET,
|
|
|
|
JS_TELEMETRY_GC_INCREMENTAL_DISABLED,
|
2012-10-31 10:33:43 +08:00
|
|
|
JS_TELEMETRY_GC_NON_INCREMENTAL,
|
|
|
|
JS_TELEMETRY_GC_SCC_SWEEP_TOTAL_MS,
|
|
|
|
JS_TELEMETRY_GC_SCC_SWEEP_MAX_PAUSE_MS
|
2012-08-28 02:41:49 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
typedef void
|
|
|
|
(* JSAccumulateTelemetryDataCallback)(int id, uint32_t sample);
|
|
|
|
|
|
|
|
extern JS_FRIEND_API(void)
|
|
|
|
JS_SetAccumulateTelemetryCallback(JSRuntime *rt, JSAccumulateTelemetryDataCallback callback);
|
|
|
|
|
|
|
|
extern JS_FRIEND_API(JSPrincipals *)
|
|
|
|
JS_GetCompartmentPrincipals(JSCompartment *compartment);
|
|
|
|
|
2012-10-19 11:48:42 +08:00
|
|
|
extern JS_FRIEND_API(void)
|
|
|
|
JS_SetCompartmentPrincipals(JSCompartment *compartment, JSPrincipals *principals);
|
|
|
|
|
2014-02-07 15:12:54 +08:00
|
|
|
/* Safe to call with input obj == nullptr. Returns non-nullptr iff obj != nullptr. */
|
2012-08-28 02:41:49 +08:00
|
|
|
extern JS_FRIEND_API(JSObject *)
|
|
|
|
JS_ObjectToInnerObject(JSContext *cx, JSObject *obj);
|
|
|
|
|
2014-02-07 15:12:54 +08:00
|
|
|
/* Requires obj != nullptr. */
|
2012-08-28 02:41:49 +08:00
|
|
|
extern JS_FRIEND_API(JSObject *)
|
|
|
|
JS_ObjectToOuterObject(JSContext *cx, JSObject *obj);
|
|
|
|
|
|
|
|
extern JS_FRIEND_API(JSObject *)
|
|
|
|
JS_CloneObject(JSContext *cx, JSObject *obj, JSObject *proto, JSObject *parent);
|
|
|
|
|
2013-08-07 09:43:25 +08:00
|
|
|
extern JS_FRIEND_API(JSString *)
|
2013-10-30 21:55:19 +08:00
|
|
|
JS_BasicObjectToString(JSContext *cx, JS::HandleObject obj);
|
2013-08-07 09:43:25 +08:00
|
|
|
|
2014-02-07 15:12:54 +08:00
|
|
|
extern JS_FRIEND_API(bool)
|
|
|
|
js_GetterOnlyPropertyStub(JSContext *cx, JS::HandleObject obj, JS::HandleId id, bool strict,
|
2013-10-30 21:55:19 +08:00
|
|
|
JS::MutableHandleValue vp);
|
2012-08-28 02:41:49 +08:00
|
|
|
|
|
|
|
JS_FRIEND_API(void)
|
|
|
|
js_ReportOverRecursed(JSContext *maybecx);
|
|
|
|
|
2013-10-30 21:55:19 +08:00
|
|
|
JS_FRIEND_API(bool)
|
|
|
|
js_ObjectClassIs(JSContext *cx, JS::HandleObject obj, js::ESClassValue classValue);
|
|
|
|
|
|
|
|
JS_FRIEND_API(const char *)
|
|
|
|
js_ObjectClassName(JSContext *cx, JS::HandleObject obj);
|
|
|
|
|
|
|
|
JS_FRIEND_API(bool)
|
|
|
|
js_AddObjectRoot(JSRuntime *rt, JSObject **objp);
|
|
|
|
|
|
|
|
JS_FRIEND_API(void)
|
|
|
|
js_RemoveObjectRoot(JSRuntime *rt, JSObject **objp);
|
|
|
|
|
2012-08-28 02:41:49 +08:00
|
|
|
#ifdef DEBUG
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Routines to print out values during debugging. These are FRIEND_API to help
|
|
|
|
* the debugger find them and to support temporarily hacking js_Dump* calls
|
|
|
|
* into other code.
|
|
|
|
*/
|
|
|
|
|
|
|
|
extern JS_FRIEND_API(void)
|
|
|
|
js_DumpString(JSString *str);
|
|
|
|
|
|
|
|
extern JS_FRIEND_API(void)
|
|
|
|
js_DumpAtom(JSAtom *atom);
|
|
|
|
|
|
|
|
extern JS_FRIEND_API(void)
|
|
|
|
js_DumpObject(JSObject *obj);
|
|
|
|
|
|
|
|
extern JS_FRIEND_API(void)
|
|
|
|
js_DumpChars(const jschar *s, size_t n);
|
|
|
|
#endif
|
|
|
|
|
2014-02-07 15:12:54 +08:00
|
|
|
/*
|
|
|
|
* Copies all own properties from |obj| to |target|. |obj| must be a "native"
|
|
|
|
* object (that is to say, normal-ish - not an Array or a Proxy).
|
|
|
|
*
|
|
|
|
* On entry, |cx| must be in the compartment of |target|.
|
|
|
|
*/
|
2012-08-28 02:41:49 +08:00
|
|
|
extern JS_FRIEND_API(bool)
|
|
|
|
JS_CopyPropertiesFrom(JSContext *cx, JSObject *target, JSObject *obj);
|
|
|
|
|
2014-02-07 15:12:54 +08:00
|
|
|
/*
|
|
|
|
* Single-property version of the above. This function asserts that an |own|
|
|
|
|
* property of the given name exists on |obj|.
|
|
|
|
*/
|
|
|
|
extern JS_FRIEND_API(bool)
|
|
|
|
JS_CopyPropertyFrom(JSContext *cx, JS::HandleId id, JS::HandleObject target,
|
|
|
|
JS::HandleObject obj);
|
|
|
|
|
|
|
|
extern JS_FRIEND_API(bool)
|
|
|
|
JS_WrapPropertyDescriptor(JSContext *cx, JS::MutableHandle<JSPropertyDescriptor> desc);
|
2012-08-28 02:41:49 +08:00
|
|
|
|
2014-02-07 15:12:54 +08:00
|
|
|
extern JS_FRIEND_API(bool)
|
2012-10-19 11:48:42 +08:00
|
|
|
JS_WrapAutoIdVector(JSContext *cx, JS::AutoIdVector &props);
|
|
|
|
|
2014-02-07 15:12:54 +08:00
|
|
|
extern JS_FRIEND_API(bool)
|
2013-10-30 21:55:19 +08:00
|
|
|
JS_EnumerateState(JSContext *cx, JS::HandleObject obj, JSIterateOp enum_op,
|
2014-02-07 15:12:54 +08:00
|
|
|
JS::MutableHandleValue statep, JS::MutableHandleId idp);
|
2012-08-28 02:41:49 +08:00
|
|
|
|
|
|
|
struct JSFunctionSpecWithHelp {
|
|
|
|
const char *name;
|
|
|
|
JSNative call;
|
|
|
|
uint16_t nargs;
|
|
|
|
uint16_t flags;
|
|
|
|
const char *usage;
|
|
|
|
const char *help;
|
|
|
|
};
|
|
|
|
|
|
|
|
#define JS_FN_HELP(name,call,nargs,flags,usage,help) \
|
|
|
|
{name, call, nargs, (flags) | JSPROP_ENUMERATE | JSFUN_STUB_GSOPS, usage, help}
|
2012-10-31 10:33:43 +08:00
|
|
|
#define JS_FS_HELP_END \
|
2014-02-07 15:12:54 +08:00
|
|
|
{nullptr, nullptr, 0, 0, nullptr, nullptr}
|
2012-08-28 02:41:49 +08:00
|
|
|
|
|
|
|
extern JS_FRIEND_API(bool)
|
|
|
|
JS_DefineFunctionsWithHelp(JSContext *cx, JSObject *obj, const JSFunctionSpecWithHelp *fs);
|
|
|
|
|
2014-02-07 15:12:54 +08:00
|
|
|
namespace js {
|
|
|
|
|
|
|
|
/*
|
|
|
|
* A class of objects that return source code on demand.
|
|
|
|
*
|
|
|
|
* When code is compiled with CompileOptions::LAZY_SOURCE, SpiderMonkey
|
|
|
|
* doesn't retain the source code (and doesn't do lazy bytecode
|
|
|
|
* generation). If we ever need the source code, say, in response to a call
|
|
|
|
* to Function.prototype.toSource or Debugger.Source.prototype.text, then
|
|
|
|
* we call the 'load' member function of the instance of this class that
|
|
|
|
* has hopefully been registered with the runtime, passing the code's URL,
|
|
|
|
* and hope that it will be able to find the source.
|
|
|
|
*/
|
|
|
|
class SourceHook {
|
|
|
|
public:
|
|
|
|
virtual ~SourceHook() { }
|
2012-10-31 10:33:43 +08:00
|
|
|
|
2014-02-07 15:12:54 +08:00
|
|
|
/*
|
|
|
|
* Set |*src| and |*length| to refer to the source code for |filename|.
|
|
|
|
* On success, the caller owns the buffer to which |*src| points, and
|
|
|
|
* should use JS_free to free it.
|
|
|
|
*/
|
|
|
|
virtual bool load(JSContext *cx, const char *filename, jschar **src, size_t *length) = 0;
|
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Have |rt| use |hook| to retrieve LAZY_SOURCE source code. See the
|
|
|
|
* comments for SourceHook. The runtime takes ownership of the hook, and
|
|
|
|
* will delete it when the runtime itself is deleted, or when a new hook is
|
|
|
|
* set.
|
|
|
|
*/
|
2012-10-31 10:33:43 +08:00
|
|
|
extern JS_FRIEND_API(void)
|
2014-02-07 15:12:54 +08:00
|
|
|
SetSourceHook(JSRuntime *rt, SourceHook *hook);
|
2012-10-31 10:33:43 +08:00
|
|
|
|
2014-02-07 15:12:54 +08:00
|
|
|
/* Remove |rt|'s source hook, and return it. The caller now owns the hook. */
|
|
|
|
extern JS_FRIEND_API(SourceHook *)
|
|
|
|
ForgetSourceHook(JSRuntime *rt);
|
2012-08-28 02:41:49 +08:00
|
|
|
|
|
|
|
inline JSRuntime *
|
|
|
|
GetRuntime(const JSContext *cx)
|
|
|
|
{
|
2013-10-30 21:55:19 +08:00
|
|
|
return ContextFriendFields::get(cx)->runtime_;
|
2012-08-28 02:41:49 +08:00
|
|
|
}
|
|
|
|
|
2013-04-10 11:19:43 +08:00
|
|
|
inline JSCompartment *
|
|
|
|
GetContextCompartment(const JSContext *cx)
|
|
|
|
{
|
2013-10-30 21:55:19 +08:00
|
|
|
return ContextFriendFields::get(cx)->compartment_;
|
2013-04-10 11:19:43 +08:00
|
|
|
}
|
|
|
|
|
2013-06-27 16:06:05 +08:00
|
|
|
inline JS::Zone *
|
|
|
|
GetContextZone(const JSContext *cx)
|
|
|
|
{
|
|
|
|
return ContextFriendFields::get(cx)->zone_;
|
|
|
|
}
|
|
|
|
|
|
|
|
extern JS_FRIEND_API(JS::Zone *)
|
|
|
|
GetCompartmentZone(JSCompartment *comp);
|
|
|
|
|
2012-08-28 02:41:49 +08:00
|
|
|
typedef bool
|
|
|
|
(* PreserveWrapperCallback)(JSContext *cx, JSObject *obj);
|
|
|
|
|
2014-02-07 15:12:54 +08:00
|
|
|
typedef enum {
|
|
|
|
CollectNurseryBeforeDump,
|
|
|
|
IgnoreNurseryObjects
|
|
|
|
} DumpHeapNurseryBehaviour;
|
|
|
|
|
2012-08-28 02:41:49 +08:00
|
|
|
/*
|
2012-10-19 11:48:42 +08:00
|
|
|
* Dump the complete object graph of heap-allocated things.
|
2012-08-28 02:41:49 +08:00
|
|
|
* fp is the file for the dump output.
|
|
|
|
*/
|
|
|
|
extern JS_FRIEND_API(void)
|
2014-02-07 15:12:54 +08:00
|
|
|
DumpHeapComplete(JSRuntime *rt, FILE *fp, DumpHeapNurseryBehaviour nurseryBehaviour);
|
2012-08-28 02:41:49 +08:00
|
|
|
|
2014-02-07 15:12:54 +08:00
|
|
|
#ifdef JS_OLD_GETTER_SETTER_METHODS
|
|
|
|
JS_FRIEND_API(bool) obj_defineGetter(JSContext *cx, unsigned argc, JS::Value *vp);
|
|
|
|
JS_FRIEND_API(bool) obj_defineSetter(JSContext *cx, unsigned argc, JS::Value *vp);
|
2012-08-28 02:41:49 +08:00
|
|
|
#endif
|
|
|
|
|
|
|
|
extern JS_FRIEND_API(bool)
|
2013-06-27 16:06:05 +08:00
|
|
|
IsSystemCompartment(JSCompartment *comp);
|
|
|
|
|
|
|
|
extern JS_FRIEND_API(bool)
|
|
|
|
IsSystemZone(JS::Zone *zone);
|
2012-08-28 02:41:49 +08:00
|
|
|
|
|
|
|
extern JS_FRIEND_API(bool)
|
2013-06-27 16:06:05 +08:00
|
|
|
IsAtomsCompartment(JSCompartment *comp);
|
2012-08-28 02:41:49 +08:00
|
|
|
|
|
|
|
/*
|
2013-04-10 11:19:43 +08:00
|
|
|
* Check whether it is OK to assign an undeclared variable with the name
|
|
|
|
* |propname| at the current location in script. It is not an error if there is
|
|
|
|
* no current script location, or if that location is not an assignment to an
|
|
|
|
* undeclared variable. Reports an error if one needs to be reported (and,
|
|
|
|
* particularly, always reports when it returns false).
|
2012-08-28 02:41:49 +08:00
|
|
|
*/
|
|
|
|
extern JS_FRIEND_API(bool)
|
2014-02-07 15:12:54 +08:00
|
|
|
ReportIfUndeclaredVarAssignment(JSContext *cx, JS::HandleString propname);
|
2012-08-28 02:41:49 +08:00
|
|
|
|
2013-10-30 21:55:19 +08:00
|
|
|
/*
|
|
|
|
* Returns whether we're in a non-strict property set (in that we're in a
|
|
|
|
* non-strict script and the bytecode we're on is a property set). The return
|
|
|
|
* value does NOT indicate any sort of exception was thrown: it's just a
|
|
|
|
* boolean.
|
|
|
|
*/
|
|
|
|
extern JS_FRIEND_API(bool)
|
|
|
|
IsInNonStrictPropertySet(JSContext *cx);
|
|
|
|
|
2012-08-28 02:41:49 +08:00
|
|
|
struct WeakMapTracer;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Weak map tracer callback, called once for every binding of every
|
|
|
|
* weak map that was live at the time of the last garbage collection.
|
|
|
|
*
|
2014-02-07 15:12:54 +08:00
|
|
|
* m will be nullptr if the weak map is not contained in a JS Object.
|
2012-08-28 02:41:49 +08:00
|
|
|
*/
|
|
|
|
typedef void
|
|
|
|
(* WeakMapTraceCallback)(WeakMapTracer *trc, JSObject *m,
|
|
|
|
void *k, JSGCTraceKind kkind,
|
|
|
|
void *v, JSGCTraceKind vkind);
|
|
|
|
|
|
|
|
struct WeakMapTracer {
|
|
|
|
JSRuntime *runtime;
|
|
|
|
WeakMapTraceCallback callback;
|
|
|
|
|
|
|
|
WeakMapTracer(JSRuntime *rt, WeakMapTraceCallback cb)
|
|
|
|
: runtime(rt), callback(cb) {}
|
|
|
|
};
|
|
|
|
|
|
|
|
extern JS_FRIEND_API(void)
|
|
|
|
TraceWeakMaps(WeakMapTracer *trc);
|
|
|
|
|
2013-02-27 16:57:36 +08:00
|
|
|
extern JS_FRIEND_API(bool)
|
|
|
|
AreGCGrayBitsValid(JSRuntime *rt);
|
|
|
|
|
2012-10-19 11:48:42 +08:00
|
|
|
typedef void
|
2013-02-27 16:57:36 +08:00
|
|
|
(*GCThingCallback)(void *closure, void *gcthing);
|
2012-10-19 11:48:42 +08:00
|
|
|
|
|
|
|
extern JS_FRIEND_API(void)
|
2013-06-27 16:06:05 +08:00
|
|
|
VisitGrayWrapperTargets(JS::Zone *zone, GCThingCallback callback, void *closure);
|
2012-10-19 11:48:42 +08:00
|
|
|
|
2012-10-31 10:33:43 +08:00
|
|
|
extern JS_FRIEND_API(JSObject *)
|
|
|
|
GetWeakmapKeyDelegate(JSObject *key);
|
|
|
|
|
2013-02-27 16:57:36 +08:00
|
|
|
JS_FRIEND_API(JSGCTraceKind)
|
|
|
|
GCThingTraceKind(void *thing);
|
|
|
|
|
|
|
|
/*
|
2013-06-27 16:06:05 +08:00
|
|
|
* Invoke cellCallback on every gray JS_OBJECT in the given zone.
|
2013-02-27 16:57:36 +08:00
|
|
|
*/
|
|
|
|
extern JS_FRIEND_API(void)
|
2013-06-27 16:06:05 +08:00
|
|
|
IterateGrayObjects(JS::Zone *zone, GCThingCallback cellCallback, void *data);
|
2013-02-27 16:57:36 +08:00
|
|
|
|
2013-04-10 11:19:43 +08:00
|
|
|
#ifdef JS_HAS_CTYPES
|
|
|
|
extern JS_FRIEND_API(size_t)
|
2013-10-30 21:55:19 +08:00
|
|
|
SizeOfDataIfCDataObject(mozilla::MallocSizeOf mallocSizeOf, JSObject *obj);
|
2013-04-10 11:19:43 +08:00
|
|
|
#endif
|
|
|
|
|
2013-06-27 16:06:05 +08:00
|
|
|
extern JS_FRIEND_API(JSCompartment *)
|
|
|
|
GetAnyCompartmentInZone(JS::Zone *zone);
|
|
|
|
|
2012-08-28 02:41:49 +08:00
|
|
|
/*
|
|
|
|
* Shadow declarations of JS internal structures, for access by inline access
|
|
|
|
* functions below. Do not use these structures in any other way. When adding
|
|
|
|
* new fields for access by inline methods, make sure to add static asserts to
|
|
|
|
* the original header file to ensure that offsets are consistent.
|
|
|
|
*/
|
|
|
|
namespace shadow {
|
|
|
|
|
|
|
|
struct TypeObject {
|
2014-02-07 15:12:54 +08:00
|
|
|
const Class *clasp;
|
2012-08-28 02:41:49 +08:00
|
|
|
JSObject *proto;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct BaseShape {
|
2014-02-07 15:12:54 +08:00
|
|
|
const js::Class *clasp;
|
2013-10-30 21:55:19 +08:00
|
|
|
JSObject *parent;
|
|
|
|
JSObject *_1;
|
2013-06-27 16:06:05 +08:00
|
|
|
JSCompartment *compartment;
|
2012-08-28 02:41:49 +08:00
|
|
|
};
|
|
|
|
|
2013-04-10 11:19:43 +08:00
|
|
|
class Shape {
|
|
|
|
public:
|
|
|
|
shadow::BaseShape *base;
|
|
|
|
jsid _1;
|
|
|
|
uint32_t slotInfo;
|
2012-08-28 02:41:49 +08:00
|
|
|
|
|
|
|
static const uint32_t FIXED_SLOTS_SHIFT = 27;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct Object {
|
2013-04-10 11:19:43 +08:00
|
|
|
shadow::Shape *shape;
|
|
|
|
shadow::TypeObject *type;
|
2014-02-07 15:12:54 +08:00
|
|
|
JS::Value *slots;
|
|
|
|
JS::Value *_1;
|
2012-08-28 02:41:49 +08:00
|
|
|
|
|
|
|
size_t numFixedSlots() const { return shape->slotInfo >> Shape::FIXED_SLOTS_SHIFT; }
|
2014-02-07 15:12:54 +08:00
|
|
|
JS::Value *fixedSlots() const {
|
|
|
|
return (JS::Value *)(uintptr_t(this) + sizeof(shadow::Object));
|
2012-08-28 02:41:49 +08:00
|
|
|
}
|
|
|
|
|
2014-02-07 15:12:54 +08:00
|
|
|
JS::Value &slotRef(size_t slot) const {
|
2012-08-28 02:41:49 +08:00
|
|
|
size_t nfixed = numFixedSlots();
|
|
|
|
if (slot < nfixed)
|
|
|
|
return fixedSlots()[slot];
|
|
|
|
return slots[slot - nfixed];
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2012-10-31 10:33:43 +08:00
|
|
|
struct Function {
|
|
|
|
Object base;
|
|
|
|
uint16_t nargs;
|
|
|
|
uint16_t flags;
|
|
|
|
/* Used only for natives */
|
2014-02-07 15:12:54 +08:00
|
|
|
JSNative native;
|
2012-10-31 10:33:43 +08:00
|
|
|
const JSJitInfo *jitinfo;
|
|
|
|
void *_1;
|
|
|
|
};
|
|
|
|
|
2012-08-28 02:41:49 +08:00
|
|
|
struct Atom {
|
2013-10-30 21:55:19 +08:00
|
|
|
static const size_t LENGTH_SHIFT = 4;
|
|
|
|
size_t lengthAndFlags;
|
2012-08-28 02:41:49 +08:00
|
|
|
const jschar *chars;
|
|
|
|
};
|
|
|
|
|
|
|
|
} /* namespace shadow */
|
|
|
|
|
2013-10-30 21:55:19 +08:00
|
|
|
// This is equal to |&JSObject::class_|. Use it in places where you don't want
|
|
|
|
// to #include jsobj.h.
|
2014-02-07 15:12:54 +08:00
|
|
|
extern JS_FRIEND_DATA(const js::Class* const) ObjectClassPtr;
|
2012-08-28 02:41:49 +08:00
|
|
|
|
2014-02-07 15:12:54 +08:00
|
|
|
inline const js::Class *
|
2013-08-07 09:43:25 +08:00
|
|
|
GetObjectClass(JSObject *obj)
|
2012-08-28 02:41:49 +08:00
|
|
|
{
|
2013-05-22 17:31:07 +08:00
|
|
|
return reinterpret_cast<const shadow::Object*>(obj)->type->clasp;
|
2012-08-28 02:41:49 +08:00
|
|
|
}
|
|
|
|
|
2014-02-07 15:12:54 +08:00
|
|
|
inline const JSClass *
|
2013-08-07 09:43:25 +08:00
|
|
|
GetObjectJSClass(JSObject *obj)
|
2012-08-28 02:41:49 +08:00
|
|
|
{
|
|
|
|
return js::Jsvalify(GetObjectClass(obj));
|
|
|
|
}
|
|
|
|
|
2013-05-22 17:31:07 +08:00
|
|
|
inline bool
|
|
|
|
IsInnerObject(JSObject *obj) {
|
|
|
|
return !!GetObjectClass(obj)->ext.outerObject;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline bool
|
|
|
|
IsOuterObject(JSObject *obj) {
|
|
|
|
return !!GetObjectClass(obj)->ext.innerObject;
|
|
|
|
}
|
|
|
|
|
2013-10-30 21:55:19 +08:00
|
|
|
JS_FRIEND_API(bool)
|
|
|
|
IsFunctionObject(JSObject *obj);
|
|
|
|
|
2012-08-28 02:41:49 +08:00
|
|
|
JS_FRIEND_API(bool)
|
2013-08-07 09:43:25 +08:00
|
|
|
IsScopeObject(JSObject *obj);
|
2012-08-28 02:41:49 +08:00
|
|
|
|
2013-10-30 21:55:19 +08:00
|
|
|
JS_FRIEND_API(bool)
|
|
|
|
IsCallObject(JSObject *obj);
|
|
|
|
|
2012-08-28 02:41:49 +08:00
|
|
|
inline JSObject *
|
2013-08-07 09:43:25 +08:00
|
|
|
GetObjectParent(JSObject *obj)
|
2012-08-28 02:41:49 +08:00
|
|
|
{
|
|
|
|
JS_ASSERT(!IsScopeObject(obj));
|
|
|
|
return reinterpret_cast<shadow::Object*>(obj)->shape->base->parent;
|
|
|
|
}
|
|
|
|
|
2013-06-27 16:06:05 +08:00
|
|
|
static JS_ALWAYS_INLINE JSCompartment *
|
|
|
|
GetObjectCompartment(JSObject *obj)
|
|
|
|
{
|
|
|
|
return reinterpret_cast<shadow::Object*>(obj)->shape->base->compartment;
|
|
|
|
}
|
|
|
|
|
2012-08-28 02:41:49 +08:00
|
|
|
JS_FRIEND_API(JSObject *)
|
2013-08-07 09:43:25 +08:00
|
|
|
GetObjectParentMaybeScope(JSObject *obj);
|
2012-08-28 02:41:49 +08:00
|
|
|
|
|
|
|
JS_FRIEND_API(JSObject *)
|
2013-08-07 09:43:25 +08:00
|
|
|
GetGlobalForObjectCrossCompartment(JSObject *obj);
|
2012-08-28 02:41:49 +08:00
|
|
|
|
2014-02-07 15:12:54 +08:00
|
|
|
JS_FRIEND_API(void)
|
|
|
|
AssertSameCompartment(JSContext *cx, JSObject *obj);
|
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
JS_FRIEND_API(void)
|
|
|
|
AssertSameCompartment(JSObject *objA, JSObject *objB);
|
|
|
|
#else
|
|
|
|
inline void AssertSameCompartment(JSObject *objA, JSObject *objB) {}
|
|
|
|
#endif
|
|
|
|
|
2013-10-30 21:55:19 +08:00
|
|
|
// For legacy consumers only. This whole concept is going away soon.
|
|
|
|
JS_FRIEND_API(JSObject *)
|
|
|
|
DefaultObjectForContextOrNull(JSContext *cx);
|
|
|
|
|
|
|
|
JS_FRIEND_API(void)
|
|
|
|
SetDefaultObjectForContext(JSContext *cx, JSObject *obj);
|
|
|
|
|
2012-10-19 11:48:42 +08:00
|
|
|
JS_FRIEND_API(void)
|
2013-08-07 09:43:25 +08:00
|
|
|
NotifyAnimationActivity(JSObject *obj);
|
2012-10-19 11:48:42 +08:00
|
|
|
|
2012-08-28 02:41:49 +08:00
|
|
|
JS_FRIEND_API(bool)
|
|
|
|
IsOriginalScriptFunction(JSFunction *fun);
|
|
|
|
|
2013-01-09 13:42:21 +08:00
|
|
|
/*
|
|
|
|
* Return the outermost enclosing function (script) of the scripted caller.
|
2014-02-07 15:12:54 +08:00
|
|
|
* This function returns nullptr in several cases:
|
2013-01-09 13:42:21 +08:00
|
|
|
* - no script is running on the context
|
|
|
|
* - the caller is in global or eval code
|
|
|
|
* In particular, this function will "stop" its outermost search at eval() and
|
|
|
|
* thus it will really return the outermost enclosing function *since the
|
|
|
|
* innermost eval*.
|
|
|
|
*/
|
|
|
|
JS_FRIEND_API(JSScript *)
|
|
|
|
GetOutermostEnclosingFunctionOfScriptedCaller(JSContext *cx);
|
|
|
|
|
2012-08-28 02:41:49 +08:00
|
|
|
JS_FRIEND_API(JSFunction *)
|
|
|
|
DefineFunctionWithReserved(JSContext *cx, JSObject *obj, const char *name, JSNative call,
|
|
|
|
unsigned nargs, unsigned attrs);
|
|
|
|
|
|
|
|
JS_FRIEND_API(JSFunction *)
|
|
|
|
NewFunctionWithReserved(JSContext *cx, JSNative call, unsigned nargs, unsigned flags,
|
|
|
|
JSObject *parent, const char *name);
|
|
|
|
|
|
|
|
JS_FRIEND_API(JSFunction *)
|
|
|
|
NewFunctionByIdWithReserved(JSContext *cx, JSNative native, unsigned nargs, unsigned flags,
|
|
|
|
JSObject *parent, jsid id);
|
|
|
|
|
|
|
|
JS_FRIEND_API(JSObject *)
|
|
|
|
InitClassWithReserved(JSContext *cx, JSObject *obj, JSObject *parent_proto,
|
2014-02-07 15:12:54 +08:00
|
|
|
const JSClass *clasp, JSNative constructor, unsigned nargs,
|
2013-08-07 09:43:25 +08:00
|
|
|
const JSPropertySpec *ps, const JSFunctionSpec *fs,
|
|
|
|
const JSPropertySpec *static_ps, const JSFunctionSpec *static_fs);
|
2012-08-28 02:41:49 +08:00
|
|
|
|
2014-02-07 15:12:54 +08:00
|
|
|
JS_FRIEND_API(const JS::Value &)
|
2013-08-07 09:43:25 +08:00
|
|
|
GetFunctionNativeReserved(JSObject *fun, size_t which);
|
2012-08-28 02:41:49 +08:00
|
|
|
|
|
|
|
JS_FRIEND_API(void)
|
2014-02-07 15:12:54 +08:00
|
|
|
SetFunctionNativeReserved(JSObject *fun, size_t which, const JS::Value &val);
|
2013-01-09 13:42:21 +08:00
|
|
|
|
2014-02-07 15:12:54 +08:00
|
|
|
JS_FRIEND_API(bool)
|
|
|
|
GetObjectProto(JSContext *cx, JS::Handle<JSObject*> obj, JS::MutableHandle<JSObject*> proto);
|
2012-08-28 02:41:49 +08:00
|
|
|
|
|
|
|
inline void *
|
2013-08-07 09:43:25 +08:00
|
|
|
GetObjectPrivate(JSObject *obj)
|
2012-08-28 02:41:49 +08:00
|
|
|
{
|
|
|
|
const shadow::Object *nobj = reinterpret_cast<const shadow::Object*>(obj);
|
|
|
|
void **addr = reinterpret_cast<void**>(&nobj->fixedSlots()[nobj->numFixedSlots()]);
|
|
|
|
return *addr;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Get a slot that is both reserved for object's clasp *and* is fixed (fits
|
|
|
|
* within the maximum capacity for the object's fixed slots).
|
|
|
|
*/
|
2014-02-07 15:12:54 +08:00
|
|
|
inline const JS::Value &
|
2013-08-07 09:43:25 +08:00
|
|
|
GetReservedSlot(JSObject *obj, size_t slot)
|
2012-08-28 02:41:49 +08:00
|
|
|
{
|
|
|
|
JS_ASSERT(slot < JSCLASS_RESERVED_SLOTS(GetObjectClass(obj)));
|
|
|
|
return reinterpret_cast<const shadow::Object *>(obj)->slotRef(slot);
|
|
|
|
}
|
|
|
|
|
|
|
|
JS_FRIEND_API(void)
|
2014-02-07 15:12:54 +08:00
|
|
|
SetReservedSlotWithBarrier(JSObject *obj, size_t slot, const JS::Value &value);
|
2012-08-28 02:41:49 +08:00
|
|
|
|
|
|
|
inline void
|
2014-02-07 15:12:54 +08:00
|
|
|
SetReservedSlot(JSObject *obj, size_t slot, const JS::Value &value)
|
2012-08-28 02:41:49 +08:00
|
|
|
{
|
|
|
|
JS_ASSERT(slot < JSCLASS_RESERVED_SLOTS(GetObjectClass(obj)));
|
|
|
|
shadow::Object *sobj = reinterpret_cast<shadow::Object *>(obj);
|
2013-05-22 17:31:07 +08:00
|
|
|
if (sobj->slotRef(slot).isMarkable()
|
|
|
|
#ifdef JSGC_GENERATIONAL
|
|
|
|
|| value.isMarkable()
|
|
|
|
#endif
|
|
|
|
)
|
|
|
|
{
|
2012-08-28 02:41:49 +08:00
|
|
|
SetReservedSlotWithBarrier(obj, slot, value);
|
2013-05-22 17:31:07 +08:00
|
|
|
} else {
|
2012-08-28 02:41:49 +08:00
|
|
|
sobj->slotRef(slot) = value;
|
2013-05-22 17:31:07 +08:00
|
|
|
}
|
2012-08-28 02:41:49 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
JS_FRIEND_API(uint32_t)
|
2013-08-07 09:43:25 +08:00
|
|
|
GetObjectSlotSpan(JSObject *obj);
|
2012-08-28 02:41:49 +08:00
|
|
|
|
2014-02-07 15:12:54 +08:00
|
|
|
inline const JS::Value &
|
2013-08-07 09:43:25 +08:00
|
|
|
GetObjectSlot(JSObject *obj, size_t slot)
|
2012-08-28 02:41:49 +08:00
|
|
|
{
|
|
|
|
JS_ASSERT(slot < GetObjectSlotSpan(obj));
|
|
|
|
return reinterpret_cast<const shadow::Object *>(obj)->slotRef(slot);
|
|
|
|
}
|
|
|
|
|
|
|
|
inline const jschar *
|
|
|
|
GetAtomChars(JSAtom *atom)
|
|
|
|
{
|
|
|
|
return reinterpret_cast<shadow::Atom *>(atom)->chars;
|
|
|
|
}
|
|
|
|
|
2013-10-30 21:55:19 +08:00
|
|
|
inline size_t
|
|
|
|
GetAtomLength(JSAtom *atom)
|
|
|
|
{
|
|
|
|
using shadow::Atom;
|
|
|
|
return reinterpret_cast<Atom*>(atom)->lengthAndFlags >> Atom::LENGTH_SHIFT;
|
|
|
|
}
|
|
|
|
|
2012-08-28 02:41:49 +08:00
|
|
|
inline JSLinearString *
|
|
|
|
AtomToLinearString(JSAtom *atom)
|
|
|
|
{
|
|
|
|
return reinterpret_cast<JSLinearString *>(atom);
|
|
|
|
}
|
|
|
|
|
|
|
|
JS_FRIEND_API(bool)
|
2014-02-07 15:12:54 +08:00
|
|
|
GetPropertyNames(JSContext *cx, JSObject *obj, unsigned flags, JS::AutoIdVector *props);
|
2012-08-28 02:41:49 +08:00
|
|
|
|
2013-05-22 17:31:07 +08:00
|
|
|
JS_FRIEND_API(bool)
|
2014-02-07 15:12:54 +08:00
|
|
|
AppendUnique(JSContext *cx, JS::AutoIdVector &base, JS::AutoIdVector &others);
|
2013-05-22 17:31:07 +08:00
|
|
|
|
2012-10-19 11:48:42 +08:00
|
|
|
JS_FRIEND_API(bool)
|
2014-02-07 15:12:54 +08:00
|
|
|
GetGeneric(JSContext *cx, JSObject *obj, JSObject *receiver, jsid id, JS::Value *vp);
|
2012-10-19 11:48:42 +08:00
|
|
|
|
2012-08-28 02:41:49 +08:00
|
|
|
JS_FRIEND_API(bool)
|
|
|
|
StringIsArrayIndex(JSLinearString *str, uint32_t *indexp);
|
|
|
|
|
|
|
|
JS_FRIEND_API(void)
|
|
|
|
SetPreserveWrapperCallback(JSRuntime *rt, PreserveWrapperCallback callback);
|
|
|
|
|
|
|
|
JS_FRIEND_API(bool)
|
2013-08-07 09:43:25 +08:00
|
|
|
IsObjectInContextCompartment(JSObject *obj, const JSContext *cx);
|
2012-08-28 02:41:49 +08:00
|
|
|
|
2014-02-07 15:12:54 +08:00
|
|
|
/*
|
|
|
|
* ErrorFromException takes a raw Value so that it's possible to call it during
|
|
|
|
* GC/CC/whatever, when it may not be possible to get a JSContext to create a
|
|
|
|
* Rooted. It promises to never ever GC.
|
|
|
|
*/
|
|
|
|
JS_FRIEND_API(JSErrorReport*)
|
|
|
|
ErrorFromException(JS::Value val);
|
|
|
|
|
2012-08-28 02:41:49 +08:00
|
|
|
/*
|
|
|
|
* NB: these flag bits are encoded into the bytecode stream in the immediate
|
|
|
|
* operand of JSOP_ITER, so don't change them without advancing vm/Xdr.h's
|
|
|
|
* XDR_BYTECODE_VERSION.
|
|
|
|
*/
|
|
|
|
#define JSITER_ENUMERATE 0x1 /* for-in compatible hidden default iterator */
|
|
|
|
#define JSITER_FOREACH 0x2 /* return [key, value] pair rather than key */
|
|
|
|
#define JSITER_KEYVALUE 0x4 /* destructuring for-in wants [key, value] */
|
|
|
|
#define JSITER_OWNONLY 0x8 /* iterate over obj's own properties only */
|
|
|
|
#define JSITER_HIDDEN 0x10 /* also enumerate non-enumerable properties */
|
|
|
|
|
2014-02-07 15:12:54 +08:00
|
|
|
JS_FRIEND_API(bool)
|
|
|
|
RunningWithTrustedPrincipals(JSContext *cx);
|
2012-08-28 02:41:49 +08:00
|
|
|
|
2013-10-30 21:55:19 +08:00
|
|
|
inline uintptr_t
|
|
|
|
GetNativeStackLimit(JSContext *cx)
|
|
|
|
{
|
2014-02-07 15:12:54 +08:00
|
|
|
StackKind kind = RunningWithTrustedPrincipals(cx) ? StackForTrustedScript
|
|
|
|
: StackForUntrustedScript;
|
|
|
|
PerThreadDataFriendFields *mainThread =
|
|
|
|
PerThreadDataFriendFields::getMainThread(GetRuntime(cx));
|
|
|
|
return mainThread->nativeStackLimit[kind];
|
2013-10-30 21:55:19 +08:00
|
|
|
}
|
|
|
|
|
2013-02-27 16:57:36 +08:00
|
|
|
/*
|
|
|
|
* These macros report a stack overflow and run |onerror| if we are close to
|
|
|
|
* using up the C stack. The JS_CHECK_CHROME_RECURSION variant gives us a little
|
|
|
|
* extra space so that we can ensure that crucial code is able to run.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#define JS_CHECK_RECURSION(cx, onerror) \
|
2012-08-28 02:41:49 +08:00
|
|
|
JS_BEGIN_MACRO \
|
|
|
|
int stackDummy_; \
|
2013-10-30 21:55:19 +08:00
|
|
|
if (!JS_CHECK_STACK_SIZE(js::GetNativeStackLimit(cx), &stackDummy_)) { \
|
2012-08-28 02:41:49 +08:00
|
|
|
js_ReportOverRecursed(cx); \
|
|
|
|
onerror; \
|
|
|
|
} \
|
|
|
|
JS_END_MACRO
|
|
|
|
|
2013-10-30 21:55:19 +08:00
|
|
|
#define JS_CHECK_RECURSION_WITH_SP_DONT_REPORT(cx, sp, onerror) \
|
2013-08-07 09:43:25 +08:00
|
|
|
JS_BEGIN_MACRO \
|
2013-10-30 21:55:19 +08:00
|
|
|
if (!JS_CHECK_STACK_SIZE(js::GetNativeStackLimit(cx), sp)) { \
|
2013-08-07 09:43:25 +08:00
|
|
|
onerror; \
|
|
|
|
} \
|
|
|
|
JS_END_MACRO
|
|
|
|
|
2014-02-07 15:12:54 +08:00
|
|
|
#define JS_CHECK_RECURSION_WITH_SP(cx, sp, onerror) \
|
|
|
|
JS_BEGIN_MACRO \
|
|
|
|
if (!JS_CHECK_STACK_SIZE(js::GetNativeStackLimit(cx), sp)) { \
|
|
|
|
js_ReportOverRecursed(cx); \
|
|
|
|
onerror; \
|
|
|
|
} \
|
|
|
|
JS_END_MACRO
|
|
|
|
|
2013-02-27 16:57:36 +08:00
|
|
|
#define JS_CHECK_CHROME_RECURSION(cx, onerror) \
|
|
|
|
JS_BEGIN_MACRO \
|
|
|
|
int stackDummy_; \
|
2013-10-30 21:55:19 +08:00
|
|
|
if (!JS_CHECK_STACK_SIZE_WITH_TOLERANCE(js::GetNativeStackLimit(cx), \
|
2013-02-27 16:57:36 +08:00
|
|
|
&stackDummy_, \
|
|
|
|
1024 * sizeof(size_t))) \
|
|
|
|
{ \
|
|
|
|
js_ReportOverRecursed(cx); \
|
|
|
|
onerror; \
|
|
|
|
} \
|
|
|
|
JS_END_MACRO
|
|
|
|
|
2012-08-28 02:41:49 +08:00
|
|
|
JS_FRIEND_API(void)
|
|
|
|
StartPCCountProfiling(JSContext *cx);
|
|
|
|
|
|
|
|
JS_FRIEND_API(void)
|
|
|
|
StopPCCountProfiling(JSContext *cx);
|
|
|
|
|
|
|
|
JS_FRIEND_API(void)
|
|
|
|
PurgePCCounts(JSContext *cx);
|
|
|
|
|
|
|
|
JS_FRIEND_API(size_t)
|
|
|
|
GetPCCountScriptCount(JSContext *cx);
|
|
|
|
|
|
|
|
JS_FRIEND_API(JSString *)
|
|
|
|
GetPCCountScriptSummary(JSContext *cx, size_t script);
|
|
|
|
|
|
|
|
JS_FRIEND_API(JSString *)
|
|
|
|
GetPCCountScriptContents(JSContext *cx, size_t script);
|
|
|
|
|
|
|
|
#ifdef JS_THREADSAFE
|
2013-01-09 13:42:21 +08:00
|
|
|
JS_FRIEND_API(bool)
|
|
|
|
ContextHasOutstandingRequests(const JSContext *cx);
|
2012-08-28 02:41:49 +08:00
|
|
|
#endif
|
|
|
|
|
|
|
|
typedef void
|
2014-02-07 15:12:54 +08:00
|
|
|
(* ActivityCallback)(void *arg, bool active);
|
2012-08-28 02:41:49 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Sets a callback that is run whenever the runtime goes idle - the
|
|
|
|
* last active request ceases - and begins activity - when it was
|
|
|
|
* idle and a request begins.
|
|
|
|
*/
|
|
|
|
JS_FRIEND_API(void)
|
|
|
|
SetActivityCallback(JSRuntime *rt, ActivityCallback cb, void *arg);
|
|
|
|
|
|
|
|
extern JS_FRIEND_API(const JSStructuredCloneCallbacks *)
|
|
|
|
GetContextStructuredCloneCallbacks(JSContext *cx);
|
|
|
|
|
|
|
|
extern JS_FRIEND_API(bool)
|
|
|
|
IsContextRunningJS(JSContext *cx);
|
|
|
|
|
2014-02-07 15:12:54 +08:00
|
|
|
typedef bool
|
2013-10-30 21:55:19 +08:00
|
|
|
(* DOMInstanceClassMatchesProto)(JS::HandleObject protoObject, uint32_t protoID,
|
2012-10-31 10:33:43 +08:00
|
|
|
uint32_t depth);
|
|
|
|
struct JSDOMCallbacks {
|
|
|
|
DOMInstanceClassMatchesProto instanceClassMatchesProto;
|
|
|
|
};
|
|
|
|
typedef struct JSDOMCallbacks DOMCallbacks;
|
|
|
|
|
|
|
|
extern JS_FRIEND_API(void)
|
|
|
|
SetDOMCallbacks(JSRuntime *rt, const DOMCallbacks *callbacks);
|
|
|
|
|
|
|
|
extern JS_FRIEND_API(const DOMCallbacks *)
|
|
|
|
GetDOMCallbacks(JSRuntime *rt);
|
|
|
|
|
2012-08-28 02:41:49 +08:00
|
|
|
extern JS_FRIEND_API(JSObject *)
|
|
|
|
GetTestingFunctions(JSContext *cx);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Helper to convert FreeOp to JSFreeOp when the definition of FreeOp is not
|
|
|
|
* available and the compiler does not know that FreeOp inherits from
|
|
|
|
* JSFreeOp.
|
|
|
|
*/
|
|
|
|
inline JSFreeOp *
|
|
|
|
CastToJSFreeOp(FreeOp *fop)
|
|
|
|
{
|
|
|
|
return reinterpret_cast<JSFreeOp *>(fop);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Implemented in jsexn.cpp. */
|
|
|
|
|
|
|
|
/*
|
2012-10-31 10:33:43 +08:00
|
|
|
* Get an error type name from a JSExnType constant.
|
2014-02-07 15:12:54 +08:00
|
|
|
* Returns nullptr for invalid arguments and JSEXN_INTERNALERR
|
2012-08-28 02:41:49 +08:00
|
|
|
*/
|
|
|
|
extern JS_FRIEND_API(const jschar*)
|
2014-02-07 15:12:54 +08:00
|
|
|
GetErrorTypeName(JSRuntime* rt, int16_t exnType);
|
2012-08-28 02:41:49 +08:00
|
|
|
|
2013-05-22 17:31:07 +08:00
|
|
|
#ifdef DEBUG
|
|
|
|
extern JS_FRIEND_API(unsigned)
|
|
|
|
GetEnterCompartmentDepth(JSContext* cx);
|
|
|
|
#endif
|
|
|
|
|
2012-10-19 11:48:42 +08:00
|
|
|
/* Implemented in jswrapper.cpp. */
|
2012-10-31 10:33:43 +08:00
|
|
|
typedef enum NukeReferencesToWindow {
|
|
|
|
NukeWindowReferences,
|
|
|
|
DontNukeWindowReferences
|
|
|
|
} NukeReferencesToWindow;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* These filters are designed to be ephemeral stack classes, and thus don't
|
|
|
|
* do any rooting or holding of their members.
|
|
|
|
*/
|
|
|
|
struct CompartmentFilter {
|
|
|
|
virtual bool match(JSCompartment *c) const = 0;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct AllCompartments : public CompartmentFilter {
|
|
|
|
virtual bool match(JSCompartment *c) const { return true; }
|
|
|
|
};
|
|
|
|
|
|
|
|
struct ContentCompartmentsOnly : public CompartmentFilter {
|
|
|
|
virtual bool match(JSCompartment *c) const {
|
|
|
|
return !IsSystemCompartment(c);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
struct ChromeCompartmentsOnly : public CompartmentFilter {
|
|
|
|
virtual bool match(JSCompartment *c) const {
|
|
|
|
return IsSystemCompartment(c);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
struct SingleCompartment : public CompartmentFilter {
|
|
|
|
JSCompartment *ours;
|
|
|
|
SingleCompartment(JSCompartment *c) : ours(c) {}
|
|
|
|
virtual bool match(JSCompartment *c) const { return c == ours; }
|
|
|
|
};
|
|
|
|
|
|
|
|
struct CompartmentsWithPrincipals : public CompartmentFilter {
|
|
|
|
JSPrincipals *principals;
|
|
|
|
CompartmentsWithPrincipals(JSPrincipals *p) : principals(p) {}
|
|
|
|
virtual bool match(JSCompartment *c) const {
|
|
|
|
return JS_GetCompartmentPrincipals(c) == principals;
|
|
|
|
}
|
|
|
|
};
|
2012-10-19 11:48:42 +08:00
|
|
|
|
2014-02-07 15:12:54 +08:00
|
|
|
extern JS_FRIEND_API(bool)
|
2012-10-31 10:33:43 +08:00
|
|
|
NukeCrossCompartmentWrappers(JSContext* cx,
|
|
|
|
const CompartmentFilter& sourceFilter,
|
|
|
|
const CompartmentFilter& targetFilter,
|
|
|
|
NukeReferencesToWindow nukeReferencesToWindow);
|
|
|
|
|
2013-10-30 21:55:19 +08:00
|
|
|
/* Specify information about DOMProxy proxies in the DOM, for use by ICs. */
|
2013-08-07 09:43:25 +08:00
|
|
|
|
|
|
|
/*
|
2013-10-30 21:55:19 +08:00
|
|
|
* The DOMProxyShadowsCheck function will be called to check if the property for
|
2013-08-07 09:43:25 +08:00
|
|
|
* id should be gotten from the prototype, or if there is an own property that
|
|
|
|
* shadows it.
|
|
|
|
* If DoesntShadow is returned then the slot at listBaseExpandoSlot should
|
|
|
|
* either be undefined or point to an expando object that would contain the own
|
|
|
|
* property.
|
|
|
|
* If DoesntShadowUnique is returned then the slot at listBaseExpandoSlot should
|
|
|
|
* contain a private pointer to a ExpandoAndGeneration, which contains a
|
|
|
|
* JS::Value that should either be undefined or point to an expando object, and
|
|
|
|
* a uint32 value. If that value changes then the IC for getting a property will
|
|
|
|
* be invalidated.
|
|
|
|
*/
|
|
|
|
|
|
|
|
struct ExpandoAndGeneration {
|
|
|
|
ExpandoAndGeneration()
|
2014-02-07 15:12:54 +08:00
|
|
|
: expando(JS::UndefinedValue()),
|
2013-08-07 09:43:25 +08:00
|
|
|
generation(0)
|
|
|
|
{}
|
|
|
|
|
2013-10-30 21:55:19 +08:00
|
|
|
void Unlink()
|
|
|
|
{
|
|
|
|
++generation;
|
|
|
|
expando.setUndefined();
|
|
|
|
}
|
|
|
|
|
|
|
|
JS::Heap<JS::Value> expando;
|
2013-08-07 09:43:25 +08:00
|
|
|
uint32_t generation;
|
|
|
|
};
|
|
|
|
|
2013-10-30 21:55:19 +08:00
|
|
|
typedef enum DOMProxyShadowsResult {
|
2013-08-07 09:43:25 +08:00
|
|
|
ShadowCheckFailed,
|
|
|
|
Shadows,
|
|
|
|
DoesntShadow,
|
|
|
|
DoesntShadowUnique
|
2013-10-30 21:55:19 +08:00
|
|
|
} DOMProxyShadowsResult;
|
|
|
|
typedef DOMProxyShadowsResult
|
|
|
|
(* DOMProxyShadowsCheck)(JSContext* cx, JS::HandleObject object, JS::HandleId id);
|
2012-10-31 10:33:43 +08:00
|
|
|
JS_FRIEND_API(void)
|
2014-02-07 15:12:54 +08:00
|
|
|
SetDOMProxyInformation(const void *domProxyHandlerFamily, uint32_t domProxyExpandoSlot,
|
2013-10-30 21:55:19 +08:00
|
|
|
DOMProxyShadowsCheck domProxyShadowsCheck);
|
2012-10-31 10:33:43 +08:00
|
|
|
|
2014-02-07 15:12:54 +08:00
|
|
|
const void *GetDOMProxyHandlerFamily();
|
2013-10-30 21:55:19 +08:00
|
|
|
uint32_t GetDOMProxyExpandoSlot();
|
|
|
|
DOMProxyShadowsCheck GetDOMProxyShadowsCheck();
|
2012-10-19 11:48:42 +08:00
|
|
|
|
2012-08-28 02:41:49 +08:00
|
|
|
} /* namespace js */
|
|
|
|
|
|
|
|
/* Implemented in jsdate.cpp. */
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Detect whether the internal date value is NaN. (Because failure is
|
|
|
|
* out-of-band for js_DateGet*)
|
|
|
|
*/
|
2014-02-07 15:12:54 +08:00
|
|
|
extern JS_FRIEND_API(bool)
|
2013-01-09 13:42:21 +08:00
|
|
|
js_DateIsValid(JSObject* obj);
|
2012-08-28 02:41:49 +08:00
|
|
|
|
|
|
|
extern JS_FRIEND_API(double)
|
2013-08-07 09:43:25 +08:00
|
|
|
js_DateGetMsecSinceEpoch(JSObject *obj);
|
2012-08-28 02:41:49 +08:00
|
|
|
|
|
|
|
/* Implemented in jscntxt.cpp. */
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Report an exception, which is currently realized as a printf-style format
|
|
|
|
* string and its arguments.
|
|
|
|
*/
|
|
|
|
typedef enum JSErrNum {
|
|
|
|
#define MSG_DEF(name, number, count, exception, format) \
|
|
|
|
name = number,
|
|
|
|
#include "js.msg"
|
|
|
|
#undef MSG_DEF
|
|
|
|
JSErr_Limit
|
|
|
|
} JSErrNum;
|
|
|
|
|
|
|
|
extern JS_FRIEND_API(const JSErrorFormatString *)
|
|
|
|
js_GetErrorMessage(void *userRef, const char *locale, const unsigned errorNumber);
|
|
|
|
|
|
|
|
/* Implemented in jsclone.cpp. */
|
|
|
|
|
|
|
|
extern JS_FRIEND_API(uint64_t)
|
|
|
|
js_GetSCOffset(JSStructuredCloneWriter* writer);
|
|
|
|
|
|
|
|
/* Typed Array functions, implemented in jstypedarray.cpp */
|
|
|
|
|
|
|
|
namespace js {
|
|
|
|
namespace ArrayBufferView {
|
|
|
|
|
|
|
|
enum ViewType {
|
|
|
|
TYPE_INT8 = 0,
|
|
|
|
TYPE_UINT8,
|
|
|
|
TYPE_INT16,
|
|
|
|
TYPE_UINT16,
|
|
|
|
TYPE_INT32,
|
|
|
|
TYPE_UINT32,
|
|
|
|
TYPE_FLOAT32,
|
|
|
|
TYPE_FLOAT64,
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Special type that is a uint8_t, but assignments are clamped to [0, 256).
|
|
|
|
* Treat the raw data type as a uint8_t.
|
|
|
|
*/
|
|
|
|
TYPE_UINT8_CLAMPED,
|
|
|
|
|
2013-02-27 16:57:36 +08:00
|
|
|
/*
|
|
|
|
* Type returned for a DataView. Note that there is no single element type
|
|
|
|
* in this case.
|
|
|
|
*/
|
|
|
|
TYPE_DATAVIEW,
|
|
|
|
|
2012-08-28 02:41:49 +08:00
|
|
|
TYPE_MAX
|
|
|
|
};
|
|
|
|
|
|
|
|
} /* namespace ArrayBufferView */
|
2013-10-30 21:55:19 +08:00
|
|
|
|
2012-08-28 02:41:49 +08:00
|
|
|
} /* namespace js */
|
|
|
|
|
|
|
|
typedef js::ArrayBufferView::ViewType JSArrayBufferViewType;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Create a new typed array with nelements elements.
|
2013-01-09 13:42:21 +08:00
|
|
|
*
|
|
|
|
* These functions (except the WithBuffer variants) fill in the array with zeros.
|
2012-08-28 02:41:49 +08:00
|
|
|
*/
|
|
|
|
|
|
|
|
extern JS_FRIEND_API(JSObject *)
|
|
|
|
JS_NewInt8Array(JSContext *cx, uint32_t nelements);
|
|
|
|
extern JS_FRIEND_API(JSObject *)
|
|
|
|
JS_NewUint8Array(JSContext *cx, uint32_t nelements);
|
|
|
|
extern JS_FRIEND_API(JSObject *)
|
|
|
|
JS_NewUint8ClampedArray(JSContext *cx, uint32_t nelements);
|
|
|
|
|
|
|
|
extern JS_FRIEND_API(JSObject *)
|
|
|
|
JS_NewInt16Array(JSContext *cx, uint32_t nelements);
|
|
|
|
extern JS_FRIEND_API(JSObject *)
|
|
|
|
JS_NewUint16Array(JSContext *cx, uint32_t nelements);
|
|
|
|
extern JS_FRIEND_API(JSObject *)
|
|
|
|
JS_NewInt32Array(JSContext *cx, uint32_t nelements);
|
|
|
|
extern JS_FRIEND_API(JSObject *)
|
|
|
|
JS_NewUint32Array(JSContext *cx, uint32_t nelements);
|
|
|
|
extern JS_FRIEND_API(JSObject *)
|
|
|
|
JS_NewFloat32Array(JSContext *cx, uint32_t nelements);
|
|
|
|
extern JS_FRIEND_API(JSObject *)
|
|
|
|
JS_NewFloat64Array(JSContext *cx, uint32_t nelements);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Create a new typed array and copy in values from the given object. The
|
|
|
|
* object is used as if it were an array; that is, the new array (if
|
|
|
|
* successfully created) will have length given by array.length, and its
|
|
|
|
* elements will be those specified by array[0], array[1], and so on, after
|
|
|
|
* conversion to the typed array element type.
|
|
|
|
*/
|
|
|
|
|
|
|
|
extern JS_FRIEND_API(JSObject *)
|
|
|
|
JS_NewInt8ArrayFromArray(JSContext *cx, JSObject *array);
|
|
|
|
extern JS_FRIEND_API(JSObject *)
|
|
|
|
JS_NewUint8ArrayFromArray(JSContext *cx, JSObject *array);
|
|
|
|
extern JS_FRIEND_API(JSObject *)
|
|
|
|
JS_NewUint8ClampedArrayFromArray(JSContext *cx, JSObject *array);
|
|
|
|
extern JS_FRIEND_API(JSObject *)
|
|
|
|
JS_NewInt16ArrayFromArray(JSContext *cx, JSObject *array);
|
|
|
|
extern JS_FRIEND_API(JSObject *)
|
|
|
|
JS_NewUint16ArrayFromArray(JSContext *cx, JSObject *array);
|
|
|
|
extern JS_FRIEND_API(JSObject *)
|
|
|
|
JS_NewInt32ArrayFromArray(JSContext *cx, JSObject *array);
|
|
|
|
extern JS_FRIEND_API(JSObject *)
|
|
|
|
JS_NewUint32ArrayFromArray(JSContext *cx, JSObject *array);
|
|
|
|
extern JS_FRIEND_API(JSObject *)
|
|
|
|
JS_NewFloat32ArrayFromArray(JSContext *cx, JSObject *array);
|
|
|
|
extern JS_FRIEND_API(JSObject *)
|
|
|
|
JS_NewFloat64ArrayFromArray(JSContext *cx, JSObject *array);
|
|
|
|
|
|
|
|
/*
|
2013-08-07 09:43:25 +08:00
|
|
|
* Create a new typed array using the given ArrayBuffer for storage. The
|
|
|
|
* length value is optional; if -1 is passed, enough elements to use up the
|
|
|
|
* remainder of the byte array is used as the default value.
|
2012-08-28 02:41:49 +08:00
|
|
|
*/
|
|
|
|
|
|
|
|
extern JS_FRIEND_API(JSObject *)
|
|
|
|
JS_NewInt8ArrayWithBuffer(JSContext *cx, JSObject *arrayBuffer,
|
|
|
|
uint32_t byteOffset, int32_t length);
|
|
|
|
extern JS_FRIEND_API(JSObject *)
|
|
|
|
JS_NewUint8ArrayWithBuffer(JSContext *cx, JSObject *arrayBuffer,
|
|
|
|
uint32_t byteOffset, int32_t length);
|
|
|
|
extern JS_FRIEND_API(JSObject *)
|
|
|
|
JS_NewUint8ClampedArrayWithBuffer(JSContext *cx, JSObject *arrayBuffer,
|
|
|
|
uint32_t byteOffset, int32_t length);
|
|
|
|
extern JS_FRIEND_API(JSObject *)
|
|
|
|
JS_NewInt16ArrayWithBuffer(JSContext *cx, JSObject *arrayBuffer,
|
|
|
|
uint32_t byteOffset, int32_t length);
|
|
|
|
extern JS_FRIEND_API(JSObject *)
|
|
|
|
JS_NewUint16ArrayWithBuffer(JSContext *cx, JSObject *arrayBuffer,
|
|
|
|
uint32_t byteOffset, int32_t length);
|
|
|
|
extern JS_FRIEND_API(JSObject *)
|
|
|
|
JS_NewInt32ArrayWithBuffer(JSContext *cx, JSObject *arrayBuffer,
|
|
|
|
uint32_t byteOffset, int32_t length);
|
|
|
|
extern JS_FRIEND_API(JSObject *)
|
|
|
|
JS_NewUint32ArrayWithBuffer(JSContext *cx, JSObject *arrayBuffer,
|
|
|
|
uint32_t byteOffset, int32_t length);
|
|
|
|
extern JS_FRIEND_API(JSObject *)
|
|
|
|
JS_NewFloat32ArrayWithBuffer(JSContext *cx, JSObject *arrayBuffer,
|
|
|
|
uint32_t byteOffset, int32_t length);
|
|
|
|
extern JS_FRIEND_API(JSObject *)
|
|
|
|
JS_NewFloat64ArrayWithBuffer(JSContext *cx, JSObject *arrayBuffer,
|
|
|
|
uint32_t byteOffset, int32_t length);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Create a new ArrayBuffer with the given byte length.
|
|
|
|
*/
|
|
|
|
extern JS_FRIEND_API(JSObject *)
|
|
|
|
JS_NewArrayBuffer(JSContext *cx, uint32_t nbytes);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Check whether obj supports JS_GetTypedArray* APIs. Note that this may return
|
|
|
|
* false if a security wrapper is encountered that denies the unwrapping. If
|
|
|
|
* this test or one of the JS_Is*Array tests succeeds, then it is safe to call
|
|
|
|
* the various accessor JSAPI calls defined below.
|
|
|
|
*/
|
2014-02-07 15:12:54 +08:00
|
|
|
extern JS_FRIEND_API(bool)
|
2013-02-27 16:57:36 +08:00
|
|
|
JS_IsTypedArrayObject(JSObject *obj);
|
2012-08-28 02:41:49 +08:00
|
|
|
|
2012-10-19 11:48:42 +08:00
|
|
|
/*
|
|
|
|
* Check whether obj supports JS_GetArrayBufferView* APIs. Note that this may
|
|
|
|
* return false if a security wrapper is encountered that denies the
|
|
|
|
* unwrapping. If this test or one of the more specific tests succeeds, then it
|
|
|
|
* is safe to call the various ArrayBufferView accessor JSAPI calls defined
|
2013-02-27 16:57:36 +08:00
|
|
|
* below.
|
2012-10-19 11:48:42 +08:00
|
|
|
*/
|
2014-02-07 15:12:54 +08:00
|
|
|
extern JS_FRIEND_API(bool)
|
2013-02-27 16:57:36 +08:00
|
|
|
JS_IsArrayBufferViewObject(JSObject *obj);
|
2012-10-19 11:48:42 +08:00
|
|
|
|
2012-08-28 02:41:49 +08:00
|
|
|
/*
|
|
|
|
* Test for specific typed array types (ArrayBufferView subtypes)
|
|
|
|
*/
|
|
|
|
|
2014-02-07 15:12:54 +08:00
|
|
|
extern JS_FRIEND_API(bool)
|
2013-02-27 16:57:36 +08:00
|
|
|
JS_IsInt8Array(JSObject *obj);
|
2014-02-07 15:12:54 +08:00
|
|
|
extern JS_FRIEND_API(bool)
|
2013-02-27 16:57:36 +08:00
|
|
|
JS_IsUint8Array(JSObject *obj);
|
2014-02-07 15:12:54 +08:00
|
|
|
extern JS_FRIEND_API(bool)
|
2013-02-27 16:57:36 +08:00
|
|
|
JS_IsUint8ClampedArray(JSObject *obj);
|
2014-02-07 15:12:54 +08:00
|
|
|
extern JS_FRIEND_API(bool)
|
2013-02-27 16:57:36 +08:00
|
|
|
JS_IsInt16Array(JSObject *obj);
|
2014-02-07 15:12:54 +08:00
|
|
|
extern JS_FRIEND_API(bool)
|
2013-02-27 16:57:36 +08:00
|
|
|
JS_IsUint16Array(JSObject *obj);
|
2014-02-07 15:12:54 +08:00
|
|
|
extern JS_FRIEND_API(bool)
|
2013-02-27 16:57:36 +08:00
|
|
|
JS_IsInt32Array(JSObject *obj);
|
2014-02-07 15:12:54 +08:00
|
|
|
extern JS_FRIEND_API(bool)
|
2013-02-27 16:57:36 +08:00
|
|
|
JS_IsUint32Array(JSObject *obj);
|
2014-02-07 15:12:54 +08:00
|
|
|
extern JS_FRIEND_API(bool)
|
2013-02-27 16:57:36 +08:00
|
|
|
JS_IsFloat32Array(JSObject *obj);
|
2014-02-07 15:12:54 +08:00
|
|
|
extern JS_FRIEND_API(bool)
|
2013-02-27 16:57:36 +08:00
|
|
|
JS_IsFloat64Array(JSObject *obj);
|
2012-10-31 10:33:43 +08:00
|
|
|
|
|
|
|
/*
|
2014-02-07 15:12:54 +08:00
|
|
|
* Unwrap Typed arrays all at once. Return nullptr without throwing if the
|
|
|
|
* object cannot be viewed as the correct typed array, or the typed array
|
|
|
|
* object on success, filling both outparameters.
|
2012-10-31 10:33:43 +08:00
|
|
|
*/
|
|
|
|
extern JS_FRIEND_API(JSObject *)
|
2013-02-27 16:57:36 +08:00
|
|
|
JS_GetObjectAsInt8Array(JSObject *obj, uint32_t *length, int8_t **data);
|
2012-10-31 10:33:43 +08:00
|
|
|
extern JS_FRIEND_API(JSObject *)
|
2013-02-27 16:57:36 +08:00
|
|
|
JS_GetObjectAsUint8Array(JSObject *obj, uint32_t *length, uint8_t **data);
|
2012-10-31 10:33:43 +08:00
|
|
|
extern JS_FRIEND_API(JSObject *)
|
2013-02-27 16:57:36 +08:00
|
|
|
JS_GetObjectAsUint8ClampedArray(JSObject *obj, uint32_t *length, uint8_t **data);
|
2012-10-31 10:33:43 +08:00
|
|
|
extern JS_FRIEND_API(JSObject *)
|
2013-02-27 16:57:36 +08:00
|
|
|
JS_GetObjectAsInt16Array(JSObject *obj, uint32_t *length, int16_t **data);
|
2012-10-31 10:33:43 +08:00
|
|
|
extern JS_FRIEND_API(JSObject *)
|
2013-02-27 16:57:36 +08:00
|
|
|
JS_GetObjectAsUint16Array(JSObject *obj, uint32_t *length, uint16_t **data);
|
2012-10-31 10:33:43 +08:00
|
|
|
extern JS_FRIEND_API(JSObject *)
|
2013-02-27 16:57:36 +08:00
|
|
|
JS_GetObjectAsInt32Array(JSObject *obj, uint32_t *length, int32_t **data);
|
2012-10-31 10:33:43 +08:00
|
|
|
extern JS_FRIEND_API(JSObject *)
|
2013-02-27 16:57:36 +08:00
|
|
|
JS_GetObjectAsUint32Array(JSObject *obj, uint32_t *length, uint32_t **data);
|
2012-10-31 10:33:43 +08:00
|
|
|
extern JS_FRIEND_API(JSObject *)
|
2013-02-27 16:57:36 +08:00
|
|
|
JS_GetObjectAsFloat32Array(JSObject *obj, uint32_t *length, float **data);
|
2012-10-31 10:33:43 +08:00
|
|
|
extern JS_FRIEND_API(JSObject *)
|
2013-02-27 16:57:36 +08:00
|
|
|
JS_GetObjectAsFloat64Array(JSObject *obj, uint32_t *length, double **data);
|
2012-10-31 10:33:43 +08:00
|
|
|
extern JS_FRIEND_API(JSObject *)
|
2013-02-27 16:57:36 +08:00
|
|
|
JS_GetObjectAsArrayBufferView(JSObject *obj, uint32_t *length, uint8_t **data);
|
2012-10-31 10:33:43 +08:00
|
|
|
extern JS_FRIEND_API(JSObject *)
|
2013-02-27 16:57:36 +08:00
|
|
|
JS_GetObjectAsArrayBuffer(JSObject *obj, uint32_t *length, uint8_t **data);
|
2012-10-31 10:33:43 +08:00
|
|
|
|
2012-08-28 02:41:49 +08:00
|
|
|
/*
|
2013-02-27 16:57:36 +08:00
|
|
|
* Get the type of elements in a typed array, or TYPE_DATAVIEW if a DataView.
|
2012-08-28 02:41:49 +08:00
|
|
|
*
|
2013-02-27 16:57:36 +08:00
|
|
|
* |obj| must have passed a JS_IsArrayBufferView/JS_Is*Array test, or somehow
|
|
|
|
* be known that it would pass such a test: it is an ArrayBufferView or a
|
|
|
|
* wrapper of an ArrayBufferView, and the unwrapping will succeed.
|
2012-08-28 02:41:49 +08:00
|
|
|
*/
|
|
|
|
extern JS_FRIEND_API(JSArrayBufferViewType)
|
2013-02-27 16:57:36 +08:00
|
|
|
JS_GetArrayBufferViewType(JSObject *obj);
|
2012-08-28 02:41:49 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Check whether obj supports the JS_GetArrayBuffer* APIs. Note that this may
|
|
|
|
* return false if a security wrapper is encountered that denies the
|
|
|
|
* unwrapping. If this test succeeds, then it is safe to call the various
|
|
|
|
* accessor JSAPI calls defined below.
|
|
|
|
*/
|
2014-02-07 15:12:54 +08:00
|
|
|
extern JS_FRIEND_API(bool)
|
2013-02-27 16:57:36 +08:00
|
|
|
JS_IsArrayBufferObject(JSObject *obj);
|
2012-08-28 02:41:49 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Return the available byte length of an array buffer.
|
|
|
|
*
|
|
|
|
* |obj| must have passed a JS_IsArrayBufferObject test, or somehow be known
|
|
|
|
* that it would pass such a test: it is an ArrayBuffer or a wrapper of an
|
2013-02-27 16:57:36 +08:00
|
|
|
* ArrayBuffer, and the unwrapping will succeed.
|
2012-08-28 02:41:49 +08:00
|
|
|
*/
|
|
|
|
extern JS_FRIEND_API(uint32_t)
|
2013-02-27 16:57:36 +08:00
|
|
|
JS_GetArrayBufferByteLength(JSObject *obj);
|
2012-08-28 02:41:49 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Return a pointer to an array buffer's data. The buffer is still owned by the
|
2013-01-09 13:42:21 +08:00
|
|
|
* array buffer object, and should not be modified on another thread. The
|
|
|
|
* returned pointer is stable across GCs.
|
2012-08-28 02:41:49 +08:00
|
|
|
*
|
|
|
|
* |obj| must have passed a JS_IsArrayBufferObject test, or somehow be known
|
|
|
|
* that it would pass such a test: it is an ArrayBuffer or a wrapper of an
|
2013-02-27 16:57:36 +08:00
|
|
|
* ArrayBuffer, and the unwrapping will succeed.
|
2012-08-28 02:41:49 +08:00
|
|
|
*/
|
|
|
|
extern JS_FRIEND_API(uint8_t *)
|
2013-02-27 16:57:36 +08:00
|
|
|
JS_GetArrayBufferData(JSObject *obj);
|
2012-08-28 02:41:49 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Return the number of elements in a typed array.
|
|
|
|
*
|
|
|
|
* |obj| must have passed a JS_IsTypedArrayObject/JS_Is*Array test, or somehow
|
|
|
|
* be known that it would pass such a test: it is a typed array or a wrapper of
|
2013-02-27 16:57:36 +08:00
|
|
|
* a typed array, and the unwrapping will succeed.
|
2012-08-28 02:41:49 +08:00
|
|
|
*/
|
|
|
|
extern JS_FRIEND_API(uint32_t)
|
2013-02-27 16:57:36 +08:00
|
|
|
JS_GetTypedArrayLength(JSObject *obj);
|
2012-08-28 02:41:49 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Return the byte offset from the start of an array buffer to the start of a
|
|
|
|
* typed array view.
|
|
|
|
*
|
|
|
|
* |obj| must have passed a JS_IsTypedArrayObject/JS_Is*Array test, or somehow
|
|
|
|
* be known that it would pass such a test: it is a typed array or a wrapper of
|
2013-02-27 16:57:36 +08:00
|
|
|
* a typed array, and the unwrapping will succeed.
|
2012-08-28 02:41:49 +08:00
|
|
|
*/
|
|
|
|
extern JS_FRIEND_API(uint32_t)
|
2013-02-27 16:57:36 +08:00
|
|
|
JS_GetTypedArrayByteOffset(JSObject *obj);
|
2012-08-28 02:41:49 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Return the byte length of a typed array.
|
|
|
|
*
|
|
|
|
* |obj| must have passed a JS_IsTypedArrayObject/JS_Is*Array test, or somehow
|
|
|
|
* be known that it would pass such a test: it is a typed array or a wrapper of
|
2013-02-27 16:57:36 +08:00
|
|
|
* a typed array, and the unwrapping will succeed.
|
2012-08-28 02:41:49 +08:00
|
|
|
*/
|
|
|
|
extern JS_FRIEND_API(uint32_t)
|
2013-02-27 16:57:36 +08:00
|
|
|
JS_GetTypedArrayByteLength(JSObject *obj);
|
2012-08-28 02:41:49 +08:00
|
|
|
|
2012-10-19 11:48:42 +08:00
|
|
|
/*
|
|
|
|
* Check whether obj supports JS_ArrayBufferView* APIs. Note that this may
|
|
|
|
* return false if a security wrapper is encountered that denies the
|
|
|
|
* unwrapping.
|
|
|
|
*/
|
2014-02-07 15:12:54 +08:00
|
|
|
extern JS_FRIEND_API(bool)
|
2013-02-27 16:57:36 +08:00
|
|
|
JS_IsArrayBufferViewObject(JSObject *obj);
|
2012-10-19 11:48:42 +08:00
|
|
|
|
2012-08-28 02:41:49 +08:00
|
|
|
/*
|
|
|
|
* More generic name for JS_GetTypedArrayByteLength to cover DataViews as well
|
|
|
|
*/
|
|
|
|
extern JS_FRIEND_API(uint32_t)
|
2013-02-27 16:57:36 +08:00
|
|
|
JS_GetArrayBufferViewByteLength(JSObject *obj);
|
2012-08-28 02:41:49 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Return a pointer to the start of the data referenced by a typed array. The
|
|
|
|
* data is still owned by the typed array, and should not be modified on
|
|
|
|
* another thread.
|
|
|
|
*
|
|
|
|
* |obj| must have passed a JS_Is*Array test, or somehow be known that it would
|
|
|
|
* pass such a test: it is a typed array or a wrapper of a typed array, and the
|
2013-02-27 16:57:36 +08:00
|
|
|
* unwrapping will succeed.
|
2012-08-28 02:41:49 +08:00
|
|
|
*/
|
|
|
|
|
|
|
|
extern JS_FRIEND_API(int8_t *)
|
2013-02-27 16:57:36 +08:00
|
|
|
JS_GetInt8ArrayData(JSObject *obj);
|
2012-08-28 02:41:49 +08:00
|
|
|
extern JS_FRIEND_API(uint8_t *)
|
2013-02-27 16:57:36 +08:00
|
|
|
JS_GetUint8ArrayData(JSObject *obj);
|
2012-08-28 02:41:49 +08:00
|
|
|
extern JS_FRIEND_API(uint8_t *)
|
2013-02-27 16:57:36 +08:00
|
|
|
JS_GetUint8ClampedArrayData(JSObject *obj);
|
2012-08-28 02:41:49 +08:00
|
|
|
extern JS_FRIEND_API(int16_t *)
|
2013-02-27 16:57:36 +08:00
|
|
|
JS_GetInt16ArrayData(JSObject *obj);
|
2012-08-28 02:41:49 +08:00
|
|
|
extern JS_FRIEND_API(uint16_t *)
|
2013-02-27 16:57:36 +08:00
|
|
|
JS_GetUint16ArrayData(JSObject *obj);
|
2012-08-28 02:41:49 +08:00
|
|
|
extern JS_FRIEND_API(int32_t *)
|
2013-02-27 16:57:36 +08:00
|
|
|
JS_GetInt32ArrayData(JSObject *obj);
|
2012-08-28 02:41:49 +08:00
|
|
|
extern JS_FRIEND_API(uint32_t *)
|
2013-02-27 16:57:36 +08:00
|
|
|
JS_GetUint32ArrayData(JSObject *obj);
|
2012-08-28 02:41:49 +08:00
|
|
|
extern JS_FRIEND_API(float *)
|
2013-02-27 16:57:36 +08:00
|
|
|
JS_GetFloat32ArrayData(JSObject *obj);
|
2012-08-28 02:41:49 +08:00
|
|
|
extern JS_FRIEND_API(double *)
|
2013-02-27 16:57:36 +08:00
|
|
|
JS_GetFloat64ArrayData(JSObject *obj);
|
2012-08-28 02:41:49 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Same as above, but for any kind of ArrayBufferView. Prefer the type-specific
|
|
|
|
* versions when possible.
|
|
|
|
*/
|
|
|
|
extern JS_FRIEND_API(void *)
|
2013-02-27 16:57:36 +08:00
|
|
|
JS_GetArrayBufferViewData(JSObject *obj);
|
2012-08-28 02:41:49 +08:00
|
|
|
|
2012-10-19 11:48:42 +08:00
|
|
|
/*
|
2013-02-27 16:57:36 +08:00
|
|
|
* Return the ArrayBuffer underlying an ArrayBufferView. If the buffer has been
|
|
|
|
* neutered, this will still return the neutered buffer. |obj| must be an
|
|
|
|
* object that would return true for JS_IsArrayBufferViewObject().
|
|
|
|
*/
|
|
|
|
extern JS_FRIEND_API(JSObject *)
|
|
|
|
JS_GetArrayBufferViewBuffer(JSObject *obj);
|
|
|
|
|
2014-02-07 15:12:54 +08:00
|
|
|
/*
|
|
|
|
* Set an ArrayBuffer's length to 0 and neuter all of its views.
|
|
|
|
*/
|
|
|
|
extern JS_FRIEND_API(void)
|
|
|
|
JS_NeuterArrayBuffer(JSObject *obj, JSContext *cx);
|
|
|
|
|
2013-02-27 16:57:36 +08:00
|
|
|
/*
|
|
|
|
* Check whether obj supports JS_GetDataView* APIs.
|
2012-10-19 11:48:42 +08:00
|
|
|
*/
|
2014-02-07 15:12:54 +08:00
|
|
|
JS_FRIEND_API(bool)
|
2013-02-27 16:57:36 +08:00
|
|
|
JS_IsDataViewObject(JSObject *obj);
|
2012-10-19 11:48:42 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Return the byte offset of a data view into its array buffer. |obj| must be a
|
|
|
|
* DataView.
|
|
|
|
*
|
|
|
|
* |obj| must have passed a JS_IsDataViewObject test, or somehow be known that
|
|
|
|
* it would pass such a test: it is a data view or a wrapper of a data view,
|
2013-02-27 16:57:36 +08:00
|
|
|
* and the unwrapping will succeed.
|
2012-10-19 11:48:42 +08:00
|
|
|
*/
|
|
|
|
JS_FRIEND_API(uint32_t)
|
2013-02-27 16:57:36 +08:00
|
|
|
JS_GetDataViewByteOffset(JSObject *obj);
|
2012-10-19 11:48:42 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Return the byte length of a data view.
|
|
|
|
*
|
|
|
|
* |obj| must have passed a JS_IsDataViewObject test, or somehow be known that
|
|
|
|
* it would pass such a test: it is a data view or a wrapper of a data view,
|
2014-02-07 15:12:54 +08:00
|
|
|
* and the unwrapping will succeed. If cx is nullptr, then DEBUG builds may be
|
2012-10-19 11:48:42 +08:00
|
|
|
* unable to assert when unwrapping should be disallowed.
|
|
|
|
*/
|
|
|
|
JS_FRIEND_API(uint32_t)
|
2013-02-27 16:57:36 +08:00
|
|
|
JS_GetDataViewByteLength(JSObject *obj);
|
2012-10-19 11:48:42 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Return a pointer to the beginning of the data referenced by a DataView.
|
|
|
|
*
|
|
|
|
* |obj| must have passed a JS_IsDataViewObject test, or somehow be known that
|
|
|
|
* it would pass such a test: it is a data view or a wrapper of a data view,
|
2014-02-07 15:12:54 +08:00
|
|
|
* and the unwrapping will succeed. If cx is nullptr, then DEBUG builds may be
|
2012-10-19 11:48:42 +08:00
|
|
|
* unable to assert when unwrapping should be disallowed.
|
|
|
|
*/
|
|
|
|
JS_FRIEND_API(void *)
|
2013-02-27 16:57:36 +08:00
|
|
|
JS_GetDataViewData(JSObject *obj);
|
2012-10-19 11:48:42 +08:00
|
|
|
|
2014-02-07 15:12:54 +08:00
|
|
|
namespace js {
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Add a watchpoint -- in the Object.prototype.watch sense -- to |obj| for the
|
|
|
|
* property |id|, using the callable object |callable| as the function to be
|
|
|
|
* called for notifications.
|
|
|
|
*
|
|
|
|
* This is an internal function exposed -- temporarily -- only so that DOM
|
|
|
|
* proxies can be watchable. Don't use it! We'll soon kill off the
|
|
|
|
* Object.prototype.{,un}watch functions, at which point this will go too.
|
|
|
|
*/
|
|
|
|
extern JS_FRIEND_API(bool)
|
|
|
|
WatchGuts(JSContext *cx, JS::HandleObject obj, JS::HandleId id, JS::HandleObject callable);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Remove a watchpoint -- in the Object.prototype.watch sense -- from |obj| for
|
|
|
|
* the property |id|.
|
|
|
|
*
|
|
|
|
* This is an internal function exposed -- temporarily -- only so that DOM
|
|
|
|
* proxies can be watchable. Don't use it! We'll soon kill off the
|
|
|
|
* Object.prototype.{,un}watch functions, at which point this will go too.
|
|
|
|
*/
|
|
|
|
extern JS_FRIEND_API(bool)
|
|
|
|
UnwatchGuts(JSContext *cx, JS::HandleObject obj, JS::HandleId id);
|
|
|
|
|
|
|
|
} // namespace js
|
|
|
|
|
2013-10-30 21:55:19 +08:00
|
|
|
/*
|
|
|
|
* A class, expected to be passed by value, which represents the CallArgs for a
|
|
|
|
* JSJitGetterOp.
|
|
|
|
*/
|
|
|
|
class JSJitGetterCallArgs : protected JS::MutableHandleValue
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
explicit JSJitGetterCallArgs(const JS::CallArgs& args)
|
|
|
|
: JS::MutableHandleValue(args.rval())
|
|
|
|
{}
|
|
|
|
|
|
|
|
explicit JSJitGetterCallArgs(JS::Rooted<JS::Value>* rooted)
|
|
|
|
: JS::MutableHandleValue(rooted)
|
|
|
|
{}
|
|
|
|
|
|
|
|
JS::MutableHandleValue rval() {
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
* A class, expected to be passed by value, which represents the CallArgs for a
|
|
|
|
* JSJitSetterOp.
|
|
|
|
*/
|
|
|
|
class JSJitSetterCallArgs : protected JS::MutableHandleValue
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
explicit JSJitSetterCallArgs(const JS::CallArgs& args)
|
|
|
|
: JS::MutableHandleValue(args[0])
|
|
|
|
{}
|
|
|
|
|
|
|
|
JS::MutableHandleValue operator[](unsigned i) {
|
|
|
|
MOZ_ASSERT(i == 0);
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
unsigned length() const { return 1; }
|
|
|
|
|
|
|
|
// Add get() or maybe hasDefined() as needed
|
|
|
|
};
|
|
|
|
|
|
|
|
struct JSJitMethodCallArgsTraits;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* A class, expected to be passed by reference, which represents the CallArgs
|
|
|
|
* for a JSJitMethodOp.
|
|
|
|
*/
|
|
|
|
class JSJitMethodCallArgs : protected JS::detail::CallArgsBase<JS::detail::NoUsedRval>
|
|
|
|
{
|
|
|
|
private:
|
|
|
|
typedef JS::detail::CallArgsBase<JS::detail::NoUsedRval> Base;
|
|
|
|
friend struct JSJitMethodCallArgsTraits;
|
|
|
|
|
|
|
|
public:
|
|
|
|
explicit JSJitMethodCallArgs(const JS::CallArgs& args) {
|
|
|
|
argv_ = args.array();
|
|
|
|
argc_ = args.length();
|
|
|
|
}
|
|
|
|
|
|
|
|
JS::MutableHandleValue rval() const {
|
|
|
|
return Base::rval();
|
|
|
|
}
|
|
|
|
|
|
|
|
unsigned length() const { return Base::length(); }
|
|
|
|
|
|
|
|
JS::MutableHandleValue operator[](unsigned i) const {
|
|
|
|
return Base::operator[](i);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool hasDefined(unsigned i) const {
|
|
|
|
return Base::hasDefined(i);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Add get() as needed
|
|
|
|
};
|
|
|
|
|
|
|
|
struct JSJitMethodCallArgsTraits
|
|
|
|
{
|
|
|
|
static const size_t offsetOfArgv = offsetof(JSJitMethodCallArgs, argv_);
|
|
|
|
static const size_t offsetOfArgc = offsetof(JSJitMethodCallArgs, argc_);
|
|
|
|
};
|
|
|
|
|
2012-10-31 10:33:43 +08:00
|
|
|
/*
|
|
|
|
* This struct contains metadata passed from the DOM to the JS Engine for JIT
|
|
|
|
* optimizations on DOM property accessors. Eventually, this should be made
|
|
|
|
* available to general JSAPI users, but we are not currently ready to do so.
|
|
|
|
*/
|
|
|
|
typedef bool
|
2013-10-30 21:55:19 +08:00
|
|
|
(* JSJitGetterOp)(JSContext *cx, JS::HandleObject thisObj,
|
|
|
|
void *specializedThis, JSJitGetterCallArgs args);
|
2012-10-31 10:33:43 +08:00
|
|
|
typedef bool
|
2013-10-30 21:55:19 +08:00
|
|
|
(* JSJitSetterOp)(JSContext *cx, JS::HandleObject thisObj,
|
|
|
|
void *specializedThis, JSJitSetterCallArgs args);
|
|
|
|
typedef bool
|
|
|
|
(* JSJitMethodOp)(JSContext *cx, JS::HandleObject thisObj,
|
|
|
|
void *specializedThis, const JSJitMethodCallArgs& args);
|
2012-10-31 10:33:43 +08:00
|
|
|
|
|
|
|
struct JSJitInfo {
|
2013-01-09 13:42:21 +08:00
|
|
|
enum OpType {
|
|
|
|
Getter,
|
|
|
|
Setter,
|
2013-10-30 21:55:19 +08:00
|
|
|
Method,
|
|
|
|
OpType_None
|
2013-01-09 13:42:21 +08:00
|
|
|
};
|
|
|
|
|
2013-10-30 21:55:19 +08:00
|
|
|
union {
|
|
|
|
JSJitGetterOp getter;
|
|
|
|
JSJitSetterOp setter;
|
|
|
|
JSJitMethodOp method;
|
|
|
|
};
|
2012-10-31 10:33:43 +08:00
|
|
|
uint32_t protoID;
|
|
|
|
uint32_t depth;
|
2013-01-09 13:42:21 +08:00
|
|
|
OpType type;
|
2013-04-10 11:19:43 +08:00
|
|
|
bool isInfallible; /* Is op fallible? False in setters. */
|
|
|
|
bool isConstant; /* Getting a construction-time constant? */
|
2013-05-22 17:31:07 +08:00
|
|
|
bool isPure; /* As long as no non-pure DOM things happen, will
|
|
|
|
keep returning the same value for the given
|
|
|
|
"this" object" */
|
2013-04-10 11:19:43 +08:00
|
|
|
JSValueType returnType; /* The return type tag. Might be JSVAL_TYPE_UNKNOWN */
|
2013-10-30 21:55:19 +08:00
|
|
|
|
|
|
|
/* An alternative native that's safe to call in parallel mode. */
|
|
|
|
JSParallelNative parallelNative;
|
2012-10-31 10:33:43 +08:00
|
|
|
};
|
|
|
|
|
2013-10-30 21:55:19 +08:00
|
|
|
#define JS_JITINFO_NATIVE_PARALLEL(op) \
|
2014-02-07 15:12:54 +08:00
|
|
|
{{nullptr},0,0,JSJitInfo::OpType_None,false,false,false,JSVAL_TYPE_MISSING,op}
|
2013-10-30 21:55:19 +08:00
|
|
|
|
2012-10-31 10:33:43 +08:00
|
|
|
static JS_ALWAYS_INLINE const JSJitInfo *
|
|
|
|
FUNCTION_VALUE_TO_JITINFO(const JS::Value& v)
|
|
|
|
{
|
2013-10-30 21:55:19 +08:00
|
|
|
JS_ASSERT(js::GetObjectClass(&v.toObject()) == js::FunctionClassPtr);
|
2012-10-31 10:33:43 +08:00
|
|
|
return reinterpret_cast<js::shadow::Function *>(&v.toObject())->jitinfo;
|
|
|
|
}
|
|
|
|
|
2013-02-27 16:57:36 +08:00
|
|
|
/* Statically asserted in jsfun.h. */
|
|
|
|
static const unsigned JS_FUNCTION_INTERPRETED_BIT = 0x1;
|
|
|
|
|
2012-10-31 10:33:43 +08:00
|
|
|
static JS_ALWAYS_INLINE void
|
|
|
|
SET_JITINFO(JSFunction * func, const JSJitInfo *info)
|
|
|
|
{
|
|
|
|
js::shadow::Function *fun = reinterpret_cast<js::shadow::Function *>(func);
|
2013-02-27 16:57:36 +08:00
|
|
|
JS_ASSERT(!(fun->flags & JS_FUNCTION_INTERPRETED_BIT));
|
2012-10-31 10:33:43 +08:00
|
|
|
fun->jitinfo = info;
|
|
|
|
}
|
|
|
|
|
2013-01-09 13:42:21 +08:00
|
|
|
/*
|
|
|
|
* Engine-internal extensions of jsid. This code is here only until we
|
|
|
|
* eliminate Gecko's dependencies on it!
|
|
|
|
*/
|
|
|
|
|
|
|
|
static JS_ALWAYS_INLINE jsid
|
|
|
|
JSID_FROM_BITS(size_t bits)
|
|
|
|
{
|
|
|
|
jsid id;
|
|
|
|
JSID_BITS(id) = bits;
|
|
|
|
return id;
|
|
|
|
}
|
|
|
|
|
2014-02-07 15:12:54 +08:00
|
|
|
namespace js {
|
|
|
|
namespace detail {
|
|
|
|
bool IdMatchesAtom(jsid id, JSAtom *atom);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-01-09 13:42:21 +08:00
|
|
|
/*
|
|
|
|
* Must not be used on atoms that are representable as integer jsids.
|
|
|
|
* Prefer NameToId or AtomToId over this function:
|
|
|
|
*
|
|
|
|
* A PropertyName is an atom that does not contain an integer in the range
|
|
|
|
* [0, UINT32_MAX]. However, jsid can only hold an integer in the range
|
|
|
|
* [0, JSID_INT_MAX] (where JSID_INT_MAX == 2^31-1). Thus, for the range of
|
|
|
|
* integers (JSID_INT_MAX, UINT32_MAX], to represent as a jsid 'id', it must be
|
|
|
|
* the case JSID_IS_ATOM(id) and !JSID_TO_ATOM(id)->isPropertyName(). In most
|
|
|
|
* cases when creating a jsid, code does not have to care about this corner
|
|
|
|
* case because:
|
|
|
|
*
|
|
|
|
* - When given an arbitrary JSAtom*, AtomToId must be used, which checks for
|
|
|
|
* integer atoms representable as integer jsids, and does this conversion.
|
|
|
|
*
|
|
|
|
* - When given a PropertyName*, NameToId can be used which which does not need
|
|
|
|
* to do any dynamic checks.
|
|
|
|
*
|
|
|
|
* Thus, it is only the rare third case which needs this function, which
|
|
|
|
* handles any JSAtom* that is known not to be representable with an int jsid.
|
|
|
|
*/
|
|
|
|
static JS_ALWAYS_INLINE jsid
|
|
|
|
NON_INTEGER_ATOM_TO_JSID(JSAtom *atom)
|
|
|
|
{
|
|
|
|
JS_ASSERT(((size_t)atom & 0x7) == 0);
|
|
|
|
jsid id = JSID_FROM_BITS((size_t)atom);
|
2014-02-07 15:12:54 +08:00
|
|
|
JS_ASSERT(js::detail::IdMatchesAtom(id, atom));
|
2013-01-09 13:42:21 +08:00
|
|
|
return id;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* All strings stored in jsids are atomized, but are not necessarily property names. */
|
2014-02-07 15:12:54 +08:00
|
|
|
static JS_ALWAYS_INLINE bool
|
2013-01-09 13:42:21 +08:00
|
|
|
JSID_IS_ATOM(jsid id)
|
|
|
|
{
|
|
|
|
return JSID_IS_STRING(id);
|
|
|
|
}
|
|
|
|
|
2014-02-07 15:12:54 +08:00
|
|
|
static JS_ALWAYS_INLINE bool
|
2013-01-09 13:42:21 +08:00
|
|
|
JSID_IS_ATOM(jsid id, JSAtom *atom)
|
|
|
|
{
|
|
|
|
return id == JSID_FROM_BITS((size_t)atom);
|
|
|
|
}
|
|
|
|
|
|
|
|
static JS_ALWAYS_INLINE JSAtom *
|
|
|
|
JSID_TO_ATOM(jsid id)
|
|
|
|
{
|
|
|
|
return (JSAtom *)JSID_TO_STRING(id);
|
|
|
|
}
|
|
|
|
|
2014-02-07 15:12:54 +08:00
|
|
|
JS_STATIC_ASSERT(sizeof(jsid) == sizeof(void*));
|
2013-01-09 13:42:21 +08:00
|
|
|
|
|
|
|
namespace js {
|
|
|
|
|
2014-02-07 15:12:54 +08:00
|
|
|
static JS_ALWAYS_INLINE JS::Value
|
2013-01-09 13:42:21 +08:00
|
|
|
IdToValue(jsid id)
|
|
|
|
{
|
|
|
|
if (JSID_IS_STRING(id))
|
2014-02-07 15:12:54 +08:00
|
|
|
return JS::StringValue(JSID_TO_STRING(id));
|
2013-01-09 13:42:21 +08:00
|
|
|
if (JS_LIKELY(JSID_IS_INT(id)))
|
2014-02-07 15:12:54 +08:00
|
|
|
return JS::Int32Value(JSID_TO_INT(id));
|
2013-01-09 13:42:21 +08:00
|
|
|
if (JS_LIKELY(JSID_IS_OBJECT(id)))
|
2014-02-07 15:12:54 +08:00
|
|
|
return JS::ObjectValue(*JSID_TO_OBJECT(id));
|
2013-05-22 17:31:07 +08:00
|
|
|
JS_ASSERT(JSID_IS_VOID(id));
|
2014-02-07 15:12:54 +08:00
|
|
|
return JS::UndefinedValue();
|
2013-01-09 13:42:21 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static JS_ALWAYS_INLINE jsval
|
|
|
|
IdToJsval(jsid id)
|
|
|
|
{
|
|
|
|
return IdToValue(id);
|
|
|
|
}
|
|
|
|
|
2013-02-27 16:57:36 +08:00
|
|
|
extern JS_FRIEND_API(bool)
|
|
|
|
IsReadOnlyDateMethod(JS::IsAcceptableThis test, JS::NativeImpl method);
|
2013-01-09 13:42:21 +08:00
|
|
|
|
2013-02-27 16:57:36 +08:00
|
|
|
extern JS_FRIEND_API(bool)
|
|
|
|
IsTypedArrayThisCheck(JS::IsAcceptableThis test);
|
|
|
|
|
2014-02-07 15:12:54 +08:00
|
|
|
/*
|
|
|
|
* If the embedder has registered a default JSContext callback, returns the
|
|
|
|
* result of the callback. Otherwise, asserts that |rt| has exactly one
|
|
|
|
* JSContext associated with it, and returns that context.
|
|
|
|
*/
|
|
|
|
extern JS_FRIEND_API(JSContext *)
|
|
|
|
DefaultJSContext(JSRuntime *rt);
|
|
|
|
|
|
|
|
typedef JSContext*
|
|
|
|
(* DefaultJSContextCallback)(JSRuntime *rt);
|
|
|
|
|
|
|
|
JS_FRIEND_API(void)
|
|
|
|
SetDefaultJSContextCallback(JSRuntime *rt, DefaultJSContextCallback cb);
|
|
|
|
|
2013-04-10 11:19:43 +08:00
|
|
|
enum CTypesActivityType {
|
|
|
|
CTYPES_CALL_BEGIN,
|
|
|
|
CTYPES_CALL_END,
|
|
|
|
CTYPES_CALLBACK_BEGIN,
|
|
|
|
CTYPES_CALLBACK_END
|
|
|
|
};
|
|
|
|
|
|
|
|
typedef void
|
|
|
|
(* CTypesActivityCallback)(JSContext *cx, CTypesActivityType type);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Sets a callback that is run whenever js-ctypes is about to be used when
|
|
|
|
* calling into C.
|
|
|
|
*/
|
|
|
|
JS_FRIEND_API(void)
|
|
|
|
SetCTypesActivityCallback(JSRuntime *rt, CTypesActivityCallback cb);
|
|
|
|
|
|
|
|
class JS_FRIEND_API(AutoCTypesActivityCallback) {
|
|
|
|
private:
|
|
|
|
JSContext *cx;
|
|
|
|
CTypesActivityCallback callback;
|
|
|
|
CTypesActivityType endType;
|
|
|
|
MOZ_DECL_USE_GUARD_OBJECT_NOTIFIER
|
|
|
|
|
|
|
|
public:
|
|
|
|
AutoCTypesActivityCallback(JSContext *cx, CTypesActivityType beginType,
|
|
|
|
CTypesActivityType endType
|
|
|
|
MOZ_GUARD_OBJECT_NOTIFIER_PARAM);
|
|
|
|
~AutoCTypesActivityCallback() {
|
|
|
|
DoEndCallback();
|
|
|
|
}
|
|
|
|
void DoEndCallback() {
|
|
|
|
if (callback) {
|
|
|
|
callback(cx, endType);
|
2014-02-07 15:12:54 +08:00
|
|
|
callback = nullptr;
|
2013-04-10 11:19:43 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2013-06-27 16:06:05 +08:00
|
|
|
#ifdef DEBUG
|
|
|
|
extern JS_FRIEND_API(void)
|
|
|
|
assertEnteredPolicy(JSContext *cx, JSObject *obj, jsid id);
|
|
|
|
#else
|
|
|
|
inline void assertEnteredPolicy(JSContext *cx, JSObject *obj, jsid id) {};
|
|
|
|
#endif
|
|
|
|
|
2013-10-30 21:55:19 +08:00
|
|
|
typedef bool
|
|
|
|
(* ObjectMetadataCallback)(JSContext *cx, JSObject **pmetadata);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Specify a callback to invoke when creating each JS object in the current
|
|
|
|
* compartment, which may return a metadata object to associate with the
|
|
|
|
* object. Objects with different metadata have different shape hierarchies,
|
|
|
|
* so for efficiency, objects should generally try to share metadata objects.
|
|
|
|
*/
|
|
|
|
JS_FRIEND_API(void)
|
|
|
|
SetObjectMetadataCallback(JSContext *cx, ObjectMetadataCallback callback);
|
|
|
|
|
|
|
|
/* Manipulate the metadata associated with an object. */
|
|
|
|
|
|
|
|
JS_FRIEND_API(bool)
|
|
|
|
SetObjectMetadata(JSContext *cx, JS::HandleObject obj, JS::HandleObject metadata);
|
|
|
|
|
|
|
|
JS_FRIEND_API(JSObject *)
|
|
|
|
GetObjectMetadata(JSObject *obj);
|
|
|
|
|
2013-06-27 16:06:05 +08:00
|
|
|
/* ES5 8.12.8. */
|
2014-02-07 15:12:54 +08:00
|
|
|
extern JS_FRIEND_API(bool)
|
|
|
|
DefaultValue(JSContext *cx, JS::HandleObject obj, JSType hint, JS::MutableHandleValue vp);
|
2013-10-30 21:55:19 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Helper function. To approximate a call to the [[DefineOwnProperty]] internal
|
|
|
|
* method described in ES5, first call this, then call JS_DefinePropertyById.
|
|
|
|
*
|
|
|
|
* JS_DefinePropertyById by itself does not enforce the invariants on
|
|
|
|
* non-configurable properties when obj->isNative(). This function performs the
|
|
|
|
* relevant checks (specified in ES5 8.12.9 [[DefineOwnProperty]] steps 1-11),
|
|
|
|
* but only if obj is native.
|
|
|
|
*
|
|
|
|
* The reason for the messiness here is that ES5 uses [[DefineOwnProperty]] as
|
|
|
|
* a sort of extension point, but there is no hook in js::Class,
|
|
|
|
* js::ProxyHandler, or the JSAPI with precisely the right semantics for it.
|
|
|
|
*/
|
|
|
|
extern JS_FRIEND_API(bool)
|
2014-02-07 15:12:54 +08:00
|
|
|
CheckDefineProperty(JSContext *cx, JS::HandleObject obj, JS::HandleId id, JS::HandleValue value,
|
|
|
|
JSPropertyOp getter, JSStrictPropertyOp setter, unsigned attrs);
|
2013-06-27 16:06:05 +08:00
|
|
|
|
2013-02-27 16:57:36 +08:00
|
|
|
} /* namespace js */
|
2013-01-09 13:42:21 +08:00
|
|
|
|
2014-02-07 15:12:54 +08:00
|
|
|
extern JS_FRIEND_API(bool)
|
2013-06-27 16:06:05 +08:00
|
|
|
js_DefineOwnProperty(JSContext *cx, JSObject *objArg, jsid idArg,
|
2014-02-07 15:12:54 +08:00
|
|
|
JS::Handle<JSPropertyDescriptor> descriptor, bool *bp);
|
2013-06-27 16:06:05 +08:00
|
|
|
|
2014-02-07 15:12:54 +08:00
|
|
|
extern JS_FRIEND_API(bool)
|
2013-06-27 16:06:05 +08:00
|
|
|
js_ReportIsNotFunction(JSContext *cx, const JS::Value& v);
|
|
|
|
|
2013-10-30 21:55:19 +08:00
|
|
|
#ifdef JSGC_GENERATIONAL
|
|
|
|
extern JS_FRIEND_API(void)
|
|
|
|
JS_StoreObjectPostBarrierCallback(JSContext* cx,
|
|
|
|
void (*callback)(JSTracer *trc, void *key, void *data),
|
|
|
|
JSObject *key, void *data);
|
|
|
|
|
|
|
|
extern JS_FRIEND_API(void)
|
|
|
|
JS_StoreStringPostBarrierCallback(JSContext* cx,
|
|
|
|
void (*callback)(JSTracer *trc, void *key, void *data),
|
|
|
|
JSString *key, void *data);
|
|
|
|
#else
|
|
|
|
inline void
|
|
|
|
JS_StoreObjectPostBarrierCallback(JSContext* cx,
|
|
|
|
void (*callback)(JSTracer *trc, void *key, void *data),
|
|
|
|
JSObject *key, void *data) {}
|
|
|
|
|
|
|
|
inline void
|
|
|
|
JS_StoreStringPostBarrierCallback(JSContext* cx,
|
|
|
|
void (*callback)(JSTracer *trc, void *key, void *data),
|
|
|
|
JSString *key, void *data) {}
|
|
|
|
#endif /* JSGC_GENERATIONAL */
|
|
|
|
|
|
|
|
#endif /* jsfriendapi_h */
|