2013-08-22 09:26:57 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
|
|
|
* vim: set ts=8 sts=4 et sw=4 tw=99:
|
|
|
|
* 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/. */
|
|
|
|
|
|
|
|
/* JSClass definition and its component types, plus related interfaces. */
|
|
|
|
|
|
|
|
#ifndef js_Class_h
|
|
|
|
#define js_Class_h
|
|
|
|
|
2014-11-11 13:56:44 +03:00
|
|
|
#include "mozilla/DebugOnly.h"
|
2014-09-02 13:07:22 +04:00
|
|
|
|
2013-08-22 09:26:57 +04:00
|
|
|
#include "jstypes.h"
|
|
|
|
|
|
|
|
#include "js/CallArgs.h"
|
|
|
|
#include "js/Id.h"
|
2013-08-28 06:59:14 +04:00
|
|
|
#include "js/TypeDecls.h"
|
2013-08-22 09:26:57 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* A JSClass acts as a vtable for JS objects that allows JSAPI clients to
|
|
|
|
* control various aspects of the behavior of an object like property lookup.
|
|
|
|
* js::Class is an engine-private extension that allows more control over
|
|
|
|
* object behavior and, e.g., allows custom slow layout.
|
|
|
|
*/
|
|
|
|
|
2015-04-23 16:51:28 +03:00
|
|
|
struct JSAtomState;
|
2014-06-19 04:57:51 +04:00
|
|
|
struct JSFreeOp;
|
2014-02-04 19:51:54 +04:00
|
|
|
struct JSFunctionSpec;
|
2013-08-22 09:26:57 +04:00
|
|
|
|
|
|
|
namespace js {
|
|
|
|
|
2014-06-19 04:57:51 +04:00
|
|
|
struct Class;
|
2013-08-22 09:26:57 +04:00
|
|
|
class FreeOp;
|
|
|
|
class Shape;
|
|
|
|
|
|
|
|
// This is equal to JSFunction::class_. Use it in places where you don't want
|
|
|
|
// to #include jsfun.h.
|
2013-09-11 16:49:05 +04:00
|
|
|
extern JS_FRIEND_DATA(const js::Class* const) FunctionClassPtr;
|
2013-08-22 09:26:57 +04:00
|
|
|
|
|
|
|
} // namespace js
|
|
|
|
|
2014-12-11 21:31:10 +03:00
|
|
|
namespace JS {
|
|
|
|
|
2015-05-01 18:26:10 +03:00
|
|
|
template <typename T>
|
|
|
|
class AutoVectorRooter;
|
|
|
|
typedef AutoVectorRooter<jsid> AutoIdVector;
|
2014-12-11 21:31:10 +03:00
|
|
|
|
2015-02-03 02:06:47 +03:00
|
|
|
/*
|
|
|
|
* Per ES6, the [[DefineOwnProperty]] internal method has three different
|
|
|
|
* possible outcomes:
|
|
|
|
*
|
|
|
|
* - It can throw an exception (which we indicate by returning false).
|
|
|
|
*
|
|
|
|
* - It can return true, indicating unvarnished success.
|
|
|
|
*
|
|
|
|
* - It can return false, indicating "strict failure". The property could
|
|
|
|
* not be defined. It's an error, but no exception was thrown.
|
|
|
|
*
|
|
|
|
* It's not just [[DefineOwnProperty]]: all the mutating internal methods have
|
|
|
|
* the same three outcomes. (The other affected internal methods are [[Set]],
|
|
|
|
* [[Delete]], [[SetPrototypeOf]], and [[PreventExtensions]].)
|
|
|
|
*
|
|
|
|
* If you think this design is awful, you're not alone. But as it's the
|
|
|
|
* standard, we must represent these boolean "success" values somehow.
|
|
|
|
* ObjectOpSuccess is the class for this. It's like a bool, but when it's false
|
|
|
|
* it also stores an error code.
|
|
|
|
*
|
|
|
|
* Typical usage:
|
|
|
|
*
|
|
|
|
* ObjectOpResult result;
|
|
|
|
* if (!DefineProperty(cx, obj, id, ..., result))
|
|
|
|
* return false;
|
|
|
|
* if (!result)
|
2015-02-19 03:49:17 +03:00
|
|
|
* return result.reportError(cx, obj, id);
|
2015-02-03 02:06:47 +03:00
|
|
|
*
|
|
|
|
* Users don't have to call `result.report()`; another possible ending is:
|
|
|
|
*
|
|
|
|
* argv.rval().setBoolean(bool(result));
|
|
|
|
* return true;
|
|
|
|
*/
|
|
|
|
class ObjectOpResult
|
|
|
|
{
|
|
|
|
private:
|
2015-03-10 20:22:30 +03:00
|
|
|
/*
|
|
|
|
* code_ is either one of the special codes OkCode or Uninitialized, or
|
|
|
|
* an error code. For now the error codes are private to the JS engine;
|
|
|
|
* they're defined in js/src/js.msg.
|
|
|
|
*
|
|
|
|
* code_ is uintptr_t (rather than uint32_t) for the convenience of the
|
|
|
|
* JITs, which would otherwise have to deal with either padding or stack
|
|
|
|
* alignment on 64-bit platforms.
|
|
|
|
*/
|
|
|
|
uintptr_t code_;
|
2015-02-03 02:06:47 +03:00
|
|
|
|
|
|
|
public:
|
2015-03-10 20:22:30 +03:00
|
|
|
enum SpecialCodes : uintptr_t {
|
|
|
|
OkCode = 0,
|
|
|
|
Uninitialized = uintptr_t(-1)
|
|
|
|
};
|
2015-02-03 02:06:47 +03:00
|
|
|
|
|
|
|
ObjectOpResult() : code_(Uninitialized) {}
|
|
|
|
|
2015-03-10 20:22:30 +03:00
|
|
|
/* Return true if succeed() was called. */
|
2015-02-03 02:06:47 +03:00
|
|
|
bool ok() const {
|
|
|
|
MOZ_ASSERT(code_ != Uninitialized);
|
|
|
|
return code_ == OkCode;
|
|
|
|
}
|
|
|
|
|
|
|
|
explicit operator bool() const { return ok(); }
|
|
|
|
|
|
|
|
/* Set this ObjectOpResult to true and return true. */
|
|
|
|
bool succeed() {
|
|
|
|
code_ = OkCode;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Set this ObjectOpResult to false with an error code.
|
|
|
|
*
|
|
|
|
* Always returns true, as a convenience. Typical usage will be:
|
|
|
|
*
|
|
|
|
* if (funny condition)
|
|
|
|
* return result.fail(JSMSG_CANT_DO_THE_THINGS);
|
|
|
|
*
|
|
|
|
* The true return value indicates that no exception is pending, and it
|
|
|
|
* would be OK to ignore the failure and continue.
|
|
|
|
*/
|
|
|
|
bool fail(uint32_t msg) {
|
|
|
|
MOZ_ASSERT(msg != OkCode);
|
|
|
|
code_ = msg;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2015-01-30 20:37:07 +03:00
|
|
|
JS_PUBLIC_API(bool) failCantRedefineProp();
|
|
|
|
JS_PUBLIC_API(bool) failReadOnly();
|
|
|
|
JS_PUBLIC_API(bool) failGetterOnly();
|
2015-03-09 18:49:34 +03:00
|
|
|
JS_PUBLIC_API(bool) failCantDelete();
|
2015-02-11 20:38:36 +03:00
|
|
|
|
|
|
|
JS_PUBLIC_API(bool) failCantSetInterposed();
|
|
|
|
JS_PUBLIC_API(bool) failCantDefineWindowElement();
|
2015-02-04 19:20:04 +03:00
|
|
|
JS_PUBLIC_API(bool) failCantDeleteWindowElement();
|
|
|
|
JS_PUBLIC_API(bool) failCantDeleteWindowNamedProperty();
|
2015-02-04 21:01:01 +03:00
|
|
|
JS_PUBLIC_API(bool) failCantPreventExtensions();
|
2015-06-03 00:27:39 +03:00
|
|
|
JS_PUBLIC_API(bool) failNoNamedSetter();
|
|
|
|
JS_PUBLIC_API(bool) failNoIndexedSetter();
|
2015-01-30 20:37:07 +03:00
|
|
|
|
|
|
|
uint32_t failureCode() const {
|
|
|
|
MOZ_ASSERT(!ok());
|
2015-03-10 20:22:30 +03:00
|
|
|
return uint32_t(code_);
|
2015-01-30 20:37:07 +03:00
|
|
|
}
|
|
|
|
|
2015-01-30 08:02:26 +03:00
|
|
|
/*
|
|
|
|
* Report an error or warning if necessary; return true to proceed and
|
|
|
|
* false if an error was reported. Call this when failure should cause
|
|
|
|
* a warning if extraWarnings are enabled.
|
|
|
|
*
|
|
|
|
* The precise rules are like this:
|
|
|
|
*
|
|
|
|
* - If ok(), then we succeeded. Do nothing and return true.
|
|
|
|
* - Otherwise, if |strict| is true, or if cx has both extraWarnings and
|
|
|
|
* werrorOption enabled, throw a TypeError and return false.
|
|
|
|
* - Otherwise, if cx has extraWarnings enabled, emit a warning and
|
|
|
|
* return true.
|
|
|
|
* - Otherwise, do nothing and return true.
|
|
|
|
*/
|
2015-03-29 01:22:11 +03:00
|
|
|
bool checkStrictErrorOrWarning(JSContext* cx, HandleObject obj, HandleId id, bool strict) {
|
2015-01-30 08:02:26 +03:00
|
|
|
if (ok())
|
|
|
|
return true;
|
|
|
|
return reportStrictErrorOrWarning(cx, obj, id, strict);
|
|
|
|
}
|
|
|
|
|
2015-02-03 02:06:47 +03:00
|
|
|
/*
|
2015-02-04 21:01:01 +03:00
|
|
|
* The same as checkStrictErrorOrWarning(cx, id, strict), except the
|
|
|
|
* operation is not associated with a particular property id. This is
|
|
|
|
* used for [[PreventExtensions]] and [[SetPrototypeOf]]. failureCode()
|
|
|
|
* must not be an error that has "{0}" in the error message.
|
2015-02-03 02:06:47 +03:00
|
|
|
*/
|
2015-03-29 01:22:11 +03:00
|
|
|
bool checkStrictErrorOrWarning(JSContext* cx, HandleObject obj, bool strict) {
|
2015-02-04 21:01:01 +03:00
|
|
|
return ok() || reportStrictErrorOrWarning(cx, obj, strict);
|
2015-02-03 02:06:47 +03:00
|
|
|
}
|
|
|
|
|
2015-01-30 08:02:26 +03:00
|
|
|
/* Throw a TypeError. Call this only if !ok(). */
|
2015-03-29 01:22:11 +03:00
|
|
|
bool reportError(JSContext* cx, HandleObject obj, HandleId id) {
|
2015-01-30 08:02:26 +03:00
|
|
|
return reportStrictErrorOrWarning(cx, obj, id, true);
|
|
|
|
}
|
|
|
|
|
2015-02-04 21:01:01 +03:00
|
|
|
/*
|
|
|
|
* The same as reportError(cx, obj, id), except the operation is not
|
|
|
|
* associated with a particular property id.
|
|
|
|
*/
|
2015-03-29 01:22:11 +03:00
|
|
|
bool reportError(JSContext* cx, HandleObject obj) {
|
2015-02-04 21:01:01 +03:00
|
|
|
return reportStrictErrorOrWarning(cx, obj, true);
|
|
|
|
}
|
|
|
|
|
2015-01-30 08:02:26 +03:00
|
|
|
/* Helper function for checkStrictErrorOrWarning's slow path. */
|
2015-03-29 01:22:11 +03:00
|
|
|
JS_PUBLIC_API(bool) reportStrictErrorOrWarning(JSContext* cx, HandleObject obj, HandleId id, bool strict);
|
|
|
|
JS_PUBLIC_API(bool) reportStrictErrorOrWarning(JSContext* cx, HandleObject obj, bool strict);
|
2015-02-04 21:01:01 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Convenience method. Return true if ok() or if strict is false; otherwise
|
|
|
|
* throw a TypeError and return false.
|
|
|
|
*/
|
2015-03-29 01:22:11 +03:00
|
|
|
bool checkStrict(JSContext* cx, HandleObject obj, HandleId id) {
|
2015-02-04 21:01:01 +03:00
|
|
|
return checkStrictErrorOrWarning(cx, obj, id, true);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Convenience method. The same as checkStrict(cx, id), except the
|
|
|
|
* operation is not associated with a particular property id.
|
|
|
|
*/
|
2015-03-29 01:22:11 +03:00
|
|
|
bool checkStrict(JSContext* cx, HandleObject obj) {
|
2015-02-04 21:01:01 +03:00
|
|
|
return checkStrictErrorOrWarning(cx, obj, true);
|
|
|
|
}
|
2015-02-03 02:06:47 +03:00
|
|
|
};
|
|
|
|
|
2014-12-11 21:31:10 +03:00
|
|
|
}
|
|
|
|
|
2013-08-22 09:26:57 +04:00
|
|
|
// JSClass operation signatures.
|
|
|
|
|
2015-03-28 16:47:02 +03:00
|
|
|
// Get a property named by id in obj. Note the jsid id type -- id may
|
2013-08-22 09:26:57 +04:00
|
|
|
// be a string (Unicode property identifier) or an int (element index). The
|
|
|
|
// *vp out parameter, on success, is the new property value after the action.
|
|
|
|
typedef bool
|
2015-03-29 01:22:11 +03:00
|
|
|
(* JSGetterOp)(JSContext* cx, JS::HandleObject obj, JS::HandleId id,
|
2015-01-30 22:56:15 +03:00
|
|
|
JS::MutableHandleValue vp);
|
|
|
|
|
2015-03-28 16:47:02 +03:00
|
|
|
// Add a property named by id to obj.
|
|
|
|
typedef bool
|
|
|
|
(* JSAddPropertyOp)(JSContext* cx, JS::HandleObject obj, JS::HandleId id, JS::HandleValue v);
|
2013-08-22 09:26:57 +04:00
|
|
|
|
|
|
|
// Set a property named by id in obj, treating the assignment as strict
|
|
|
|
// mode code if strict is true. Note the jsid id type -- id may be a string
|
|
|
|
// (Unicode property identifier) or an int (element index). The *vp out
|
|
|
|
// parameter, on success, is the new property value after the
|
|
|
|
// set.
|
|
|
|
typedef bool
|
2015-03-29 01:22:11 +03:00
|
|
|
(* JSSetterOp)(JSContext* cx, JS::HandleObject obj, JS::HandleId id,
|
|
|
|
JS::MutableHandleValue vp, JS::ObjectOpResult& result);
|
2013-08-22 09:26:57 +04:00
|
|
|
|
|
|
|
// Delete a property named by id in obj.
|
|
|
|
//
|
|
|
|
// If an error occurred, return false as per normal JSAPI error practice.
|
|
|
|
//
|
|
|
|
// If no error occurred, but the deletion attempt wasn't allowed (perhaps
|
2015-02-04 19:20:04 +03:00
|
|
|
// because the property was non-configurable), call result.fail() and
|
2013-08-22 09:26:57 +04:00
|
|
|
// return true. This will cause |delete obj[id]| to evaluate to false in
|
|
|
|
// non-strict mode code, and to throw a TypeError in strict mode code.
|
|
|
|
//
|
|
|
|
// If no error occurred and the deletion wasn't disallowed (this is *not* the
|
|
|
|
// same as saying that a deletion actually occurred -- deleting a non-existent
|
|
|
|
// property, or an inherited property, is allowed -- it's just pointless),
|
2015-02-04 19:20:04 +03:00
|
|
|
// call result.succeed() and return true.
|
2013-08-22 09:26:57 +04:00
|
|
|
typedef bool
|
2015-03-29 01:22:11 +03:00
|
|
|
(* JSDeletePropertyOp)(JSContext* cx, JS::HandleObject obj, JS::HandleId id,
|
|
|
|
JS::ObjectOpResult& result);
|
2013-08-22 09:26:57 +04:00
|
|
|
|
2014-12-11 21:31:10 +03:00
|
|
|
// The type of ObjectOps::enumerate. This callback overrides a portion of SpiderMonkey's default
|
|
|
|
// [[Enumerate]] internal method. When an ordinary object is enumerated, that object and each object
|
|
|
|
// on its prototype chain is tested for an enumerate op, and those ops are called in order.
|
|
|
|
// The properties each op adds to the 'properties' vector are added to the set of values the
|
|
|
|
// for-in loop will iterate over. All of this is nonstandard.
|
2013-08-22 09:26:57 +04:00
|
|
|
//
|
2014-12-11 21:31:10 +03:00
|
|
|
// An object is "enumerated" when it's the target of a for-in loop or JS_Enumerate().
|
|
|
|
// All other property inspection, including Object.keys(obj), goes through [[OwnKeys]].
|
2013-08-22 09:26:57 +04:00
|
|
|
//
|
2014-12-11 21:31:10 +03:00
|
|
|
// The callback's job is to populate 'properties' with all property keys that the for-in loop
|
|
|
|
// should visit.
|
2013-08-22 09:26:57 +04:00
|
|
|
typedef bool
|
2015-03-29 01:22:11 +03:00
|
|
|
(* JSNewEnumerateOp)(JSContext* cx, JS::HandleObject obj, JS::AutoIdVector& properties);
|
2013-08-22 09:26:57 +04:00
|
|
|
|
|
|
|
// The old-style JSClass.enumerate op should define all lazy properties not
|
|
|
|
// yet reflected in obj.
|
|
|
|
typedef bool
|
2015-03-29 01:22:11 +03:00
|
|
|
(* JSEnumerateOp)(JSContext* cx, JS::HandleObject obj);
|
2013-08-22 09:26:57 +04:00
|
|
|
|
|
|
|
// Resolve a lazy property named by id in obj by defining it directly in obj.
|
|
|
|
// Lazy properties are those reflected from some peer native property space
|
|
|
|
// (e.g., the DOM attributes for a given node reflected as obj) on demand.
|
|
|
|
//
|
|
|
|
// JS looks for a property in an object, and if not found, tries to resolve
|
2014-11-08 03:07:12 +03:00
|
|
|
// the given id. *resolvedp should be set to true iff the property was
|
|
|
|
// was defined on |obj|.
|
2013-08-22 09:26:57 +04:00
|
|
|
//
|
|
|
|
typedef bool
|
2015-03-29 01:22:11 +03:00
|
|
|
(* JSResolveOp)(JSContext* cx, JS::HandleObject obj, JS::HandleId id,
|
|
|
|
bool* resolvedp);
|
2013-08-22 09:26:57 +04:00
|
|
|
|
2015-04-23 16:51:28 +03:00
|
|
|
// A class with a resolve hook can optionally have a mayResolve hook. This hook
|
|
|
|
// must have no side effects and must return true for a given id if the resolve
|
|
|
|
// hook may resolve this id. This is useful when we're doing a "pure" lookup: if
|
|
|
|
// mayResolve returns false, we know we don't have to call the effectful resolve
|
|
|
|
// hook.
|
|
|
|
//
|
|
|
|
// maybeObj, if non-null, is the object on which we're doing the lookup. This
|
|
|
|
// can be nullptr: during JIT compilation we sometimes know the Class but not
|
|
|
|
// the object.
|
|
|
|
typedef bool
|
|
|
|
(* JSMayResolveOp)(const JSAtomState& names, jsid id, JSObject* maybeObj);
|
|
|
|
|
2013-08-22 09:26:57 +04:00
|
|
|
// Convert obj to the given type, returning true with the resulting value in
|
|
|
|
// *vp on success, and returning false on error or exception.
|
|
|
|
typedef bool
|
2015-03-29 01:22:11 +03:00
|
|
|
(* JSConvertOp)(JSContext* cx, JS::HandleObject obj, JSType type,
|
2014-01-15 14:31:00 +04:00
|
|
|
JS::MutableHandleValue vp);
|
2013-08-22 09:26:57 +04:00
|
|
|
|
|
|
|
// Finalize obj, which the garbage collector has determined to be unreachable
|
|
|
|
// from other live objects or from GC roots. Obviously, finalizers must never
|
|
|
|
// store a reference to obj.
|
|
|
|
typedef void
|
2015-03-29 01:22:11 +03:00
|
|
|
(* JSFinalizeOp)(JSFreeOp* fop, JSObject* obj);
|
2013-08-22 09:26:57 +04:00
|
|
|
|
|
|
|
// Finalizes external strings created by JS_NewExternalString.
|
|
|
|
struct JSStringFinalizer {
|
2015-03-29 01:22:11 +03:00
|
|
|
void (*finalize)(const JSStringFinalizer* fin, char16_t* chars);
|
2013-08-22 09:26:57 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
// Check whether v is an instance of obj. Return false on error or exception,
|
|
|
|
// true on success with true in *bp if v is an instance of obj, false in
|
|
|
|
// *bp otherwise.
|
|
|
|
typedef bool
|
2015-03-29 01:22:11 +03:00
|
|
|
(* JSHasInstanceOp)(JSContext* cx, JS::HandleObject obj, JS::MutableHandleValue vp,
|
|
|
|
bool* bp);
|
2013-08-22 09:26:57 +04:00
|
|
|
|
|
|
|
// Function type for trace operation of the class called to enumerate all
|
|
|
|
// traceable things reachable from obj's private data structure. For each such
|
|
|
|
// thing, a trace implementation must call one of the JS_Call*Tracer variants
|
|
|
|
// on the thing.
|
|
|
|
//
|
|
|
|
// JSTraceOp implementation can assume that no other threads mutates object
|
|
|
|
// state. It must not change state of the object or corresponding native
|
|
|
|
// structures. The only exception for this rule is the case when the embedding
|
|
|
|
// needs a tight integration with GC. In that case the embedding can check if
|
|
|
|
// the traversal is a part of the marking phase through calling
|
|
|
|
// JS_IsGCMarkingTracer and apply a special code like emptying caches or
|
|
|
|
// marking its native structures.
|
|
|
|
typedef void
|
2015-03-29 01:22:11 +03:00
|
|
|
(* JSTraceOp)(JSTracer* trc, JSObject* obj);
|
2013-08-22 09:26:57 +04:00
|
|
|
|
2015-03-29 01:22:11 +03:00
|
|
|
typedef JSObject*
|
|
|
|
(* JSWeakmapKeyDelegateOp)(JSObject* obj);
|
2013-08-22 09:26:57 +04:00
|
|
|
|
2014-09-02 13:07:22 +04:00
|
|
|
typedef void
|
2015-03-29 01:22:11 +03:00
|
|
|
(* JSObjectMovedOp)(JSObject* obj, const JSObject* old);
|
2014-09-02 13:07:22 +04:00
|
|
|
|
2013-08-22 09:26:57 +04:00
|
|
|
/* js::Class operation signatures. */
|
|
|
|
|
|
|
|
namespace js {
|
|
|
|
|
|
|
|
typedef bool
|
2015-03-29 01:22:11 +03:00
|
|
|
(* LookupPropertyOp)(JSContext* cx, JS::HandleObject obj, JS::HandleId id,
|
2015-01-29 02:12:44 +03:00
|
|
|
JS::MutableHandleObject objp, JS::MutableHandle<Shape*> propp);
|
2013-08-22 09:26:57 +04:00
|
|
|
typedef bool
|
2015-03-29 01:22:11 +03:00
|
|
|
(* DefinePropertyOp)(JSContext* cx, JS::HandleObject obj, JS::HandleId id,
|
2015-02-28 20:23:44 +03:00
|
|
|
JS::Handle<JSPropertyDescriptor> desc,
|
2015-03-29 01:22:11 +03:00
|
|
|
JS::ObjectOpResult& result);
|
2013-08-22 09:26:57 +04:00
|
|
|
typedef bool
|
2015-03-29 01:22:11 +03:00
|
|
|
(* HasPropertyOp)(JSContext* cx, JS::HandleObject obj, JS::HandleId id, bool* foundp);
|
2015-02-13 14:20:02 +03:00
|
|
|
typedef bool
|
2015-03-29 01:22:11 +03:00
|
|
|
(* GetPropertyOp)(JSContext* cx, JS::HandleObject obj, JS::HandleObject receiver, JS::HandleId id,
|
2015-01-29 02:12:44 +03:00
|
|
|
JS::MutableHandleValue vp);
|
2013-08-22 09:26:57 +04:00
|
|
|
typedef bool
|
2015-03-29 01:22:11 +03:00
|
|
|
(* SetPropertyOp)(JSContext* cx, JS::HandleObject obj, JS::HandleId id, JS::HandleValue v,
|
|
|
|
JS::HandleValue receiver, JS::ObjectOpResult& result);
|
2013-08-22 09:26:57 +04:00
|
|
|
typedef bool
|
2015-03-29 01:22:11 +03:00
|
|
|
(* GetOwnPropertyOp)(JSContext* cx, JS::HandleObject obj, JS::HandleId id,
|
2015-01-22 19:17:26 +03:00
|
|
|
JS::MutableHandle<JSPropertyDescriptor> desc);
|
|
|
|
typedef bool
|
2015-03-29 01:22:11 +03:00
|
|
|
(* DeletePropertyOp)(JSContext* cx, JS::HandleObject obj, JS::HandleId id,
|
|
|
|
JS::ObjectOpResult& result);
|
2013-08-22 09:26:57 +04:00
|
|
|
|
2013-10-30 03:39:09 +04:00
|
|
|
typedef bool
|
2015-03-29 01:22:11 +03:00
|
|
|
(* WatchOp)(JSContext* cx, JS::HandleObject obj, JS::HandleId id, JS::HandleObject callable);
|
2013-10-30 03:39:09 +04:00
|
|
|
|
|
|
|
typedef bool
|
2015-03-29 01:22:11 +03:00
|
|
|
(* UnwatchOp)(JSContext* cx, JS::HandleObject obj, JS::HandleId id);
|
2013-08-22 09:26:57 +04:00
|
|
|
|
2014-11-11 13:56:44 +03:00
|
|
|
class JS_FRIEND_API(ElementAdder)
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
enum GetBehavior {
|
|
|
|
// Check if the element exists before performing the Get and preserve
|
|
|
|
// holes.
|
|
|
|
CheckHasElemPreserveHoles,
|
|
|
|
|
|
|
|
// Perform a Get operation, like obj[index] in JS.
|
|
|
|
GetElement
|
|
|
|
};
|
|
|
|
|
|
|
|
private:
|
|
|
|
// Only one of these is used.
|
|
|
|
JS::RootedObject resObj_;
|
2015-03-29 01:22:11 +03:00
|
|
|
JS::Value* vp_;
|
2014-11-11 13:56:44 +03:00
|
|
|
|
|
|
|
uint32_t index_;
|
|
|
|
mozilla::DebugOnly<uint32_t> length_;
|
|
|
|
GetBehavior getBehavior_;
|
|
|
|
|
|
|
|
public:
|
2015-03-29 01:22:11 +03:00
|
|
|
ElementAdder(JSContext* cx, JSObject* obj, uint32_t length, GetBehavior behavior)
|
2014-11-11 13:56:44 +03:00
|
|
|
: resObj_(cx, obj), vp_(nullptr), index_(0), length_(length), getBehavior_(behavior)
|
|
|
|
{}
|
2015-03-29 01:22:11 +03:00
|
|
|
ElementAdder(JSContext* cx, JS::Value* vp, uint32_t length, GetBehavior behavior)
|
2014-11-11 13:56:44 +03:00
|
|
|
: resObj_(cx), vp_(vp), index_(0), length_(length), getBehavior_(behavior)
|
|
|
|
{}
|
|
|
|
|
|
|
|
GetBehavior getBehavior() const { return getBehavior_; }
|
|
|
|
|
2015-06-10 19:42:22 +03:00
|
|
|
bool append(JSContext* cx, JS::HandleValue v);
|
2014-11-11 13:56:44 +03:00
|
|
|
void appendHole();
|
|
|
|
};
|
|
|
|
|
2013-12-05 23:07:24 +04:00
|
|
|
typedef bool
|
2015-03-29 01:22:11 +03:00
|
|
|
(* GetElementsOp)(JSContext* cx, JS::HandleObject obj, uint32_t begin, uint32_t end,
|
|
|
|
ElementAdder* adder);
|
2013-12-05 23:07:24 +04:00
|
|
|
|
2014-05-08 17:00:36 +04:00
|
|
|
// A generic type for functions mapping an object to another object, or null
|
|
|
|
// if an error or exception was thrown on cx.
|
2015-03-29 01:22:11 +03:00
|
|
|
typedef JSObject*
|
|
|
|
(* ObjectOp)(JSContext* cx, JS::HandleObject obj);
|
2014-05-08 17:00:36 +04:00
|
|
|
|
|
|
|
// Hook to map an object to its inner object. Infallible.
|
2015-03-29 01:22:11 +03:00
|
|
|
typedef JSObject*
|
|
|
|
(* InnerObjectOp)(JSObject* obj);
|
2014-05-08 17:00:36 +04:00
|
|
|
|
2013-08-22 09:26:57 +04:00
|
|
|
typedef void
|
2015-03-29 01:22:11 +03:00
|
|
|
(* FinalizeOp)(FreeOp* fop, JSObject* obj);
|
2013-08-22 09:26:57 +04:00
|
|
|
|
2014-02-25 00:08:57 +04:00
|
|
|
#define JS_CLASS_MEMBERS(FinalizeOpType) \
|
2015-03-29 01:22:11 +03:00
|
|
|
const char* name; \
|
2013-08-22 09:26:57 +04:00
|
|
|
uint32_t flags; \
|
|
|
|
\
|
2014-11-22 21:23:39 +03:00
|
|
|
/* Function pointer members (may be null). */ \
|
2015-01-30 22:56:15 +03:00
|
|
|
JSAddPropertyOp addProperty; \
|
2013-08-22 09:26:57 +04:00
|
|
|
JSDeletePropertyOp delProperty; \
|
2015-01-30 22:56:15 +03:00
|
|
|
JSGetterOp getProperty; \
|
|
|
|
JSSetterOp setProperty; \
|
2013-08-22 09:26:57 +04:00
|
|
|
JSEnumerateOp enumerate; \
|
|
|
|
JSResolveOp resolve; \
|
2015-04-23 16:51:28 +03:00
|
|
|
JSMayResolveOp mayResolve; \
|
2013-08-22 09:26:57 +04:00
|
|
|
JSConvertOp convert; \
|
2014-02-25 00:08:57 +04:00
|
|
|
FinalizeOpType finalize; \
|
2013-08-22 09:26:57 +04:00
|
|
|
JSNative call; \
|
|
|
|
JSHasInstanceOp hasInstance; \
|
|
|
|
JSNative construct; \
|
|
|
|
JSTraceOp trace
|
|
|
|
|
2014-02-04 19:51:54 +04:00
|
|
|
// Callback for the creation of constructor and prototype objects.
|
2015-03-29 01:22:11 +03:00
|
|
|
typedef JSObject* (*ClassObjectCreationOp)(JSContext* cx, JSProtoKey key);
|
2014-02-04 19:51:54 +04:00
|
|
|
|
|
|
|
// Callback for custom post-processing after class initialization via ClassSpec.
|
2015-03-29 01:22:11 +03:00
|
|
|
typedef bool (*FinishClassInitOp)(JSContext* cx, JS::HandleObject ctor,
|
2014-02-04 19:51:54 +04:00
|
|
|
JS::HandleObject proto);
|
|
|
|
|
2014-09-19 07:06:32 +04:00
|
|
|
const size_t JSCLASS_CACHED_PROTO_WIDTH = 6;
|
|
|
|
|
2014-02-04 19:51:54 +04:00
|
|
|
struct ClassSpec
|
|
|
|
{
|
2015-05-14 07:03:14 +03:00
|
|
|
// All properties except flags should be accessed through accessor.
|
|
|
|
ClassObjectCreationOp createConstructor_;
|
|
|
|
ClassObjectCreationOp createPrototype_;
|
|
|
|
const JSFunctionSpec* constructorFunctions_;
|
|
|
|
const JSPropertySpec* constructorProperties_;
|
|
|
|
const JSFunctionSpec* prototypeFunctions_;
|
|
|
|
const JSPropertySpec* prototypeProperties_;
|
|
|
|
FinishClassInitOp finishInit_;
|
2014-09-19 07:06:32 +04:00
|
|
|
uintptr_t flags;
|
|
|
|
|
|
|
|
static const size_t ParentKeyWidth = JSCLASS_CACHED_PROTO_WIDTH;
|
|
|
|
|
|
|
|
static const uintptr_t ParentKeyMask = (1 << ParentKeyWidth) - 1;
|
|
|
|
static const uintptr_t DontDefineConstructor = 1 << ParentKeyWidth;
|
2015-05-14 07:03:14 +03:00
|
|
|
static const uintptr_t IsDelegated = 1 << (ParentKeyWidth + 1);
|
2014-09-19 07:06:32 +04:00
|
|
|
|
2015-05-14 07:03:14 +03:00
|
|
|
bool defined() const { return !!createConstructor_; }
|
|
|
|
|
|
|
|
bool delegated() const {
|
|
|
|
return (flags & IsDelegated);
|
|
|
|
}
|
2014-09-19 07:06:32 +04:00
|
|
|
|
|
|
|
bool dependent() const {
|
|
|
|
MOZ_ASSERT(defined());
|
|
|
|
return (flags & ParentKeyMask);
|
|
|
|
}
|
|
|
|
|
|
|
|
JSProtoKey parentKey() const {
|
|
|
|
static_assert(JSProto_Null == 0, "zeroed key must be null");
|
|
|
|
return JSProtoKey(flags & ParentKeyMask);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool shouldDefineConstructor() const {
|
|
|
|
MOZ_ASSERT(defined());
|
|
|
|
return !(flags & DontDefineConstructor);
|
|
|
|
}
|
2015-05-14 07:03:14 +03:00
|
|
|
|
|
|
|
const ClassSpec* delegatedClassSpec() const {
|
|
|
|
MOZ_ASSERT(delegated());
|
|
|
|
return reinterpret_cast<ClassSpec*>(createConstructor_);
|
|
|
|
}
|
|
|
|
|
|
|
|
ClassObjectCreationOp createConstructorHook() const {
|
|
|
|
if (delegated())
|
|
|
|
return delegatedClassSpec()->createConstructorHook();
|
|
|
|
return createConstructor_;
|
|
|
|
}
|
|
|
|
ClassObjectCreationOp createPrototypeHook() const {
|
|
|
|
if (delegated())
|
|
|
|
return delegatedClassSpec()->createPrototypeHook();
|
|
|
|
return createPrototype_;
|
|
|
|
}
|
|
|
|
const JSFunctionSpec* constructorFunctions() const {
|
|
|
|
if (delegated())
|
|
|
|
return delegatedClassSpec()->constructorFunctions();
|
|
|
|
return constructorFunctions_;
|
|
|
|
}
|
|
|
|
const JSPropertySpec* constructorProperties() const {
|
|
|
|
if (delegated())
|
|
|
|
return delegatedClassSpec()->constructorProperties();
|
|
|
|
return constructorProperties_;
|
|
|
|
}
|
|
|
|
const JSFunctionSpec* prototypeFunctions() const {
|
|
|
|
if (delegated())
|
|
|
|
return delegatedClassSpec()->prototypeFunctions();
|
|
|
|
return prototypeFunctions_;
|
|
|
|
}
|
|
|
|
const JSPropertySpec* prototypeProperties() const {
|
|
|
|
if (delegated())
|
|
|
|
return delegatedClassSpec()->prototypeProperties();
|
|
|
|
return prototypeProperties_;
|
|
|
|
}
|
|
|
|
FinishClassInitOp finishInitHook() const {
|
|
|
|
if (delegated())
|
|
|
|
return delegatedClassSpec()->finishInitHook();
|
|
|
|
return finishInit_;
|
|
|
|
}
|
2014-02-04 19:51:54 +04:00
|
|
|
};
|
|
|
|
|
2013-08-22 09:26:57 +04:00
|
|
|
struct ClassExtension
|
|
|
|
{
|
2014-05-08 17:00:36 +04:00
|
|
|
ObjectOp outerObject;
|
|
|
|
InnerObjectOp innerObject;
|
2013-08-22 09:26:57 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* isWrappedNative is true only if the class is an XPCWrappedNative.
|
|
|
|
* WeakMaps use this to override the wrapper disposal optimization.
|
|
|
|
*/
|
|
|
|
bool isWrappedNative;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If an object is used as a key in a weakmap, it may be desirable for the
|
|
|
|
* garbage collector to keep that object around longer than it otherwise
|
|
|
|
* would. A common case is when the key is a wrapper around an object in
|
|
|
|
* another compartment, and we want to avoid collecting the wrapper (and
|
|
|
|
* removing the weakmap entry) as long as the wrapped object is alive. In
|
|
|
|
* that case, the wrapped object is returned by the wrapper's
|
|
|
|
* weakmapKeyDelegateOp hook. As long as the wrapper is used as a weakmap
|
|
|
|
* key, it will not be collected (and remain in the weakmap) until the
|
|
|
|
* wrapped object is collected.
|
|
|
|
*/
|
|
|
|
JSWeakmapKeyDelegateOp weakmapKeyDelegateOp;
|
2014-09-02 13:07:22 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Optional hook called when an object is moved by a compacting GC.
|
|
|
|
*
|
|
|
|
* There may exist weak pointers to an object that are not traced through
|
|
|
|
* when the normal trace APIs are used, for example objects in the wrapper
|
2014-10-28 13:18:36 +03:00
|
|
|
* cache. This hook allows these pointers to be updated.
|
|
|
|
*
|
|
|
|
* Note that this hook can be called before JS_NewObject() returns if a GC
|
|
|
|
* is triggered during construction of the object. This can happen for
|
|
|
|
* global objects for example.
|
2014-09-02 13:07:22 +04:00
|
|
|
*/
|
|
|
|
JSObjectMovedOp objectMovedOp;
|
2013-08-22 09:26:57 +04:00
|
|
|
};
|
|
|
|
|
2015-05-14 07:03:14 +03:00
|
|
|
inline ClassObjectCreationOp DELEGATED_CLASSSPEC(const ClassSpec* spec) {
|
|
|
|
return reinterpret_cast<ClassObjectCreationOp>(const_cast<ClassSpec*>(spec));
|
|
|
|
}
|
|
|
|
|
2015-03-18 12:22:05 +03:00
|
|
|
#define JS_NULL_CLASS_SPEC {nullptr,nullptr,nullptr,nullptr,nullptr,nullptr,nullptr}
|
2014-11-05 22:36:49 +03:00
|
|
|
#define JS_NULL_CLASS_EXT {nullptr,nullptr,false,nullptr,nullptr}
|
2013-08-22 09:26:57 +04:00
|
|
|
|
|
|
|
struct ObjectOps
|
|
|
|
{
|
2015-01-29 02:12:44 +03:00
|
|
|
LookupPropertyOp lookupProperty;
|
|
|
|
DefinePropertyOp defineProperty;
|
2015-02-13 14:20:02 +03:00
|
|
|
HasPropertyOp hasProperty;
|
2015-01-29 02:12:44 +03:00
|
|
|
GetPropertyOp getProperty;
|
|
|
|
SetPropertyOp setProperty;
|
2015-01-22 19:17:26 +03:00
|
|
|
GetOwnPropertyOp getOwnPropertyDescriptor;
|
2015-01-29 02:12:44 +03:00
|
|
|
DeletePropertyOp deleteProperty;
|
2013-10-30 03:39:09 +04:00
|
|
|
WatchOp watch;
|
|
|
|
UnwatchOp unwatch;
|
2014-11-11 13:56:44 +03:00
|
|
|
GetElementsOp getElements;
|
2013-08-22 09:26:57 +04:00
|
|
|
JSNewEnumerateOp enumerate;
|
|
|
|
ObjectOp thisObject;
|
|
|
|
};
|
|
|
|
|
|
|
|
#define JS_NULL_OBJECT_OPS \
|
2014-06-05 21:19:23 +04:00
|
|
|
{nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, \
|
2015-02-13 14:20:02 +03:00
|
|
|
nullptr, nullptr, nullptr, nullptr}
|
2013-08-22 09:26:57 +04:00
|
|
|
|
|
|
|
} // namespace js
|
|
|
|
|
|
|
|
// Classes, objects, and properties.
|
|
|
|
|
|
|
|
typedef void (*JSClassInternal)();
|
|
|
|
|
|
|
|
struct JSClass {
|
2014-02-25 00:08:57 +04:00
|
|
|
JS_CLASS_MEMBERS(JSFinalizeOp);
|
2013-08-22 09:26:57 +04:00
|
|
|
|
2015-03-29 01:22:11 +03:00
|
|
|
void* reserved[25];
|
2013-08-22 09:26:57 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
#define JSCLASS_HAS_PRIVATE (1<<0) // objects have private slot
|
2015-03-29 01:22:11 +03:00
|
|
|
#define JSCLASS_PRIVATE_IS_NSISUPPORTS (1<<3) // private is (nsISupports*)
|
2013-08-22 09:26:57 +04:00
|
|
|
#define JSCLASS_IS_DOMJSCLASS (1<<4) // objects are DOM
|
|
|
|
#define JSCLASS_IMPLEMENTS_BARRIERS (1<<5) // Correctly implements GC read
|
|
|
|
// and write barriers
|
|
|
|
#define JSCLASS_EMULATES_UNDEFINED (1<<6) // objects of this class act
|
|
|
|
// like the value undefined,
|
|
|
|
// in some contexts
|
|
|
|
#define JSCLASS_USERBIT1 (1<<7) // Reserved for embeddings.
|
|
|
|
|
|
|
|
// To reserve slots fetched and stored via JS_Get/SetReservedSlot, bitwise-or
|
|
|
|
// JSCLASS_HAS_RESERVED_SLOTS(n) into the initializer for JSClass.flags, where
|
|
|
|
// n is a constant in [1, 255]. Reserved slots are indexed from 0 to n-1.
|
|
|
|
#define JSCLASS_RESERVED_SLOTS_SHIFT 8 // room for 8 flags below */
|
|
|
|
#define JSCLASS_RESERVED_SLOTS_WIDTH 8 // and 16 above this field */
|
|
|
|
#define JSCLASS_RESERVED_SLOTS_MASK JS_BITMASK(JSCLASS_RESERVED_SLOTS_WIDTH)
|
|
|
|
#define JSCLASS_HAS_RESERVED_SLOTS(n) (((n) & JSCLASS_RESERVED_SLOTS_MASK) \
|
|
|
|
<< JSCLASS_RESERVED_SLOTS_SHIFT)
|
|
|
|
#define JSCLASS_RESERVED_SLOTS(clasp) (((clasp)->flags \
|
|
|
|
>> JSCLASS_RESERVED_SLOTS_SHIFT) \
|
|
|
|
& JSCLASS_RESERVED_SLOTS_MASK)
|
|
|
|
|
|
|
|
#define JSCLASS_HIGH_FLAGS_SHIFT (JSCLASS_RESERVED_SLOTS_SHIFT + \
|
|
|
|
JSCLASS_RESERVED_SLOTS_WIDTH)
|
|
|
|
|
|
|
|
#define JSCLASS_IS_ANONYMOUS (1<<(JSCLASS_HIGH_FLAGS_SHIFT+0))
|
|
|
|
#define JSCLASS_IS_GLOBAL (1<<(JSCLASS_HIGH_FLAGS_SHIFT+1))
|
|
|
|
#define JSCLASS_INTERNAL_FLAG2 (1<<(JSCLASS_HIGH_FLAGS_SHIFT+2))
|
|
|
|
#define JSCLASS_INTERNAL_FLAG3 (1<<(JSCLASS_HIGH_FLAGS_SHIFT+3))
|
|
|
|
|
2014-01-30 05:20:15 +04:00
|
|
|
#define JSCLASS_IS_PROXY (1<<(JSCLASS_HIGH_FLAGS_SHIFT+4))
|
|
|
|
|
2015-05-05 02:36:54 +03:00
|
|
|
#define JSCLASS_SKIP_NURSERY_FINALIZE (1<<(JSCLASS_HIGH_FLAGS_SHIFT+5))
|
2013-08-22 09:26:57 +04:00
|
|
|
|
|
|
|
// Reserved for embeddings.
|
|
|
|
#define JSCLASS_USERBIT2 (1<<(JSCLASS_HIGH_FLAGS_SHIFT+6))
|
|
|
|
#define JSCLASS_USERBIT3 (1<<(JSCLASS_HIGH_FLAGS_SHIFT+7))
|
|
|
|
|
|
|
|
#define JSCLASS_BACKGROUND_FINALIZE (1<<(JSCLASS_HIGH_FLAGS_SHIFT+8))
|
|
|
|
|
|
|
|
// Bits 26 through 31 are reserved for the CACHED_PROTO_KEY mechanism, see
|
|
|
|
// below.
|
|
|
|
|
|
|
|
// ECMA-262 requires that most constructors used internally create objects
|
|
|
|
// with "the original Foo.prototype value" as their [[Prototype]] (__proto__)
|
|
|
|
// member initial value. The "original ... value" verbiage is there because
|
|
|
|
// in ECMA-262, global properties naming class objects are read/write and
|
|
|
|
// deleteable, for the most part.
|
|
|
|
//
|
|
|
|
// Implementing this efficiently requires that global objects have classes
|
|
|
|
// with the following flags. Failure to use JSCLASS_GLOBAL_FLAGS was
|
2013-10-15 00:24:11 +04:00
|
|
|
// previously allowed, but is now an ES5 violation and thus unsupported.
|
2013-08-22 09:26:57 +04:00
|
|
|
//
|
2014-05-08 06:28:57 +04:00
|
|
|
// JSCLASS_GLOBAL_APPLICATION_SLOTS is the number of slots reserved at
|
|
|
|
// the beginning of every global object's slots for use by the
|
|
|
|
// application.
|
2015-04-27 20:38:12 +03:00
|
|
|
#define JSCLASS_GLOBAL_APPLICATION_SLOTS 5
|
2015-07-07 16:31:44 +03:00
|
|
|
#define JSCLASS_GLOBAL_SLOT_COUNT (JSCLASS_GLOBAL_APPLICATION_SLOTS + JSProto_LIMIT * 3 + 32)
|
2013-08-22 09:26:57 +04:00
|
|
|
#define JSCLASS_GLOBAL_FLAGS_WITH_SLOTS(n) \
|
|
|
|
(JSCLASS_IS_GLOBAL | JSCLASS_HAS_RESERVED_SLOTS(JSCLASS_GLOBAL_SLOT_COUNT + (n)))
|
|
|
|
#define JSCLASS_GLOBAL_FLAGS \
|
|
|
|
JSCLASS_GLOBAL_FLAGS_WITH_SLOTS(0)
|
|
|
|
#define JSCLASS_HAS_GLOBAL_FLAG_AND_SLOTS(clasp) \
|
|
|
|
(((clasp)->flags & JSCLASS_IS_GLOBAL) \
|
|
|
|
&& JSCLASS_RESERVED_SLOTS(clasp) >= JSCLASS_GLOBAL_SLOT_COUNT)
|
|
|
|
|
|
|
|
// Fast access to the original value of each standard class's prototype.
|
|
|
|
#define JSCLASS_CACHED_PROTO_SHIFT (JSCLASS_HIGH_FLAGS_SHIFT + 10)
|
|
|
|
#define JSCLASS_CACHED_PROTO_MASK JS_BITMASK(JSCLASS_CACHED_PROTO_WIDTH)
|
|
|
|
#define JSCLASS_HAS_CACHED_PROTO(key) (uint32_t(key) << JSCLASS_CACHED_PROTO_SHIFT)
|
|
|
|
#define JSCLASS_CACHED_PROTO_KEY(clasp) ((JSProtoKey) \
|
|
|
|
(((clasp)->flags \
|
|
|
|
>> JSCLASS_CACHED_PROTO_SHIFT) \
|
|
|
|
& JSCLASS_CACHED_PROTO_MASK))
|
|
|
|
|
|
|
|
// Initializer for unused members of statically initialized JSClass structs.
|
|
|
|
#define JSCLASS_NO_INTERNAL_MEMBERS {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}
|
|
|
|
#define JSCLASS_NO_OPTIONAL_MEMBERS 0,0,0,0,0,JSCLASS_NO_INTERNAL_MEMBERS
|
|
|
|
|
|
|
|
namespace js {
|
|
|
|
|
|
|
|
struct Class
|
|
|
|
{
|
2014-02-25 00:08:57 +04:00
|
|
|
JS_CLASS_MEMBERS(FinalizeOp);
|
2014-02-04 19:51:54 +04:00
|
|
|
ClassSpec spec;
|
2013-08-22 09:26:57 +04:00
|
|
|
ClassExtension ext;
|
|
|
|
ObjectOps ops;
|
|
|
|
|
2014-12-18 22:28:06 +03:00
|
|
|
/*
|
|
|
|
* Objects of this class aren't native objects. They don't have Shapes that
|
|
|
|
* describe their properties and layout. Classes using this flag must
|
|
|
|
* provide their own property behavior, either by being proxy classes (do
|
|
|
|
* this) or by overriding all the ObjectOps except getElements, watch,
|
|
|
|
* unwatch, and thisObject (don't do this).
|
|
|
|
*/
|
2013-08-22 09:26:57 +04:00
|
|
|
static const uint32_t NON_NATIVE = JSCLASS_INTERNAL_FLAG2;
|
|
|
|
|
|
|
|
bool isNative() const {
|
|
|
|
return !(flags & NON_NATIVE);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool hasPrivate() const {
|
|
|
|
return !!(flags & JSCLASS_HAS_PRIVATE);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool emulatesUndefined() const {
|
|
|
|
return flags & JSCLASS_EMULATES_UNDEFINED;
|
|
|
|
}
|
|
|
|
|
2014-09-11 02:42:36 +04:00
|
|
|
bool isJSFunction() const {
|
|
|
|
return this == js::FunctionClassPtr;
|
|
|
|
}
|
|
|
|
|
2014-09-11 02:52:36 +04:00
|
|
|
bool nonProxyCallable() const {
|
|
|
|
MOZ_ASSERT(!isProxy());
|
2014-09-11 02:42:36 +04:00
|
|
|
return isJSFunction() || call;
|
2013-08-22 09:26:57 +04:00
|
|
|
}
|
|
|
|
|
2014-01-30 05:20:15 +04:00
|
|
|
bool isProxy() const {
|
|
|
|
return flags & JSCLASS_IS_PROXY;
|
|
|
|
}
|
|
|
|
|
2014-04-16 06:58:45 +04:00
|
|
|
bool isDOMClass() const {
|
|
|
|
return flags & JSCLASS_IS_DOMJSCLASS;
|
|
|
|
}
|
|
|
|
|
2013-08-22 09:26:57 +04:00
|
|
|
static size_t offsetOfFlags() { return offsetof(Class, flags); }
|
|
|
|
};
|
|
|
|
|
2014-10-23 02:17:38 +04:00
|
|
|
static_assert(offsetof(JSClass, name) == offsetof(Class, name),
|
|
|
|
"Class and JSClass must be consistent");
|
|
|
|
static_assert(offsetof(JSClass, flags) == offsetof(Class, flags),
|
|
|
|
"Class and JSClass must be consistent");
|
|
|
|
static_assert(offsetof(JSClass, addProperty) == offsetof(Class, addProperty),
|
|
|
|
"Class and JSClass must be consistent");
|
|
|
|
static_assert(offsetof(JSClass, delProperty) == offsetof(Class, delProperty),
|
|
|
|
"Class and JSClass must be consistent");
|
|
|
|
static_assert(offsetof(JSClass, getProperty) == offsetof(Class, getProperty),
|
|
|
|
"Class and JSClass must be consistent");
|
|
|
|
static_assert(offsetof(JSClass, setProperty) == offsetof(Class, setProperty),
|
|
|
|
"Class and JSClass must be consistent");
|
|
|
|
static_assert(offsetof(JSClass, enumerate) == offsetof(Class, enumerate),
|
|
|
|
"Class and JSClass must be consistent");
|
|
|
|
static_assert(offsetof(JSClass, resolve) == offsetof(Class, resolve),
|
|
|
|
"Class and JSClass must be consistent");
|
2015-04-23 16:51:28 +03:00
|
|
|
static_assert(offsetof(JSClass, mayResolve) == offsetof(Class, mayResolve),
|
|
|
|
"Class and JSClass must be consistent");
|
2014-10-23 02:17:38 +04:00
|
|
|
static_assert(offsetof(JSClass, convert) == offsetof(Class, convert),
|
|
|
|
"Class and JSClass must be consistent");
|
|
|
|
static_assert(offsetof(JSClass, finalize) == offsetof(Class, finalize),
|
|
|
|
"Class and JSClass must be consistent");
|
|
|
|
static_assert(offsetof(JSClass, call) == offsetof(Class, call),
|
|
|
|
"Class and JSClass must be consistent");
|
|
|
|
static_assert(offsetof(JSClass, construct) == offsetof(Class, construct),
|
|
|
|
"Class and JSClass must be consistent");
|
|
|
|
static_assert(offsetof(JSClass, hasInstance) == offsetof(Class, hasInstance),
|
|
|
|
"Class and JSClass must be consistent");
|
|
|
|
static_assert(offsetof(JSClass, trace) == offsetof(Class, trace),
|
|
|
|
"Class and JSClass must be consistent");
|
|
|
|
static_assert(sizeof(JSClass) == sizeof(Class),
|
|
|
|
"Class and JSClass must be consistent");
|
2013-08-22 09:26:57 +04:00
|
|
|
|
2015-03-29 01:22:11 +03:00
|
|
|
static MOZ_ALWAYS_INLINE const JSClass*
|
|
|
|
Jsvalify(const Class* c)
|
2013-08-22 09:26:57 +04:00
|
|
|
{
|
2015-03-29 01:22:11 +03:00
|
|
|
return (const JSClass*)c;
|
2013-08-22 09:26:57 +04:00
|
|
|
}
|
|
|
|
|
2015-03-29 01:22:11 +03:00
|
|
|
static MOZ_ALWAYS_INLINE const Class*
|
|
|
|
Valueify(const JSClass* c)
|
2013-08-22 09:26:57 +04:00
|
|
|
{
|
2015-03-29 01:22:11 +03:00
|
|
|
return (const Class*)c;
|
2013-08-22 09:26:57 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Enumeration describing possible values of the [[Class]] internal property
|
|
|
|
* value of objects.
|
|
|
|
*/
|
|
|
|
enum ESClassValue {
|
2014-08-19 01:18:39 +04:00
|
|
|
ESClass_Object, ESClass_Array, ESClass_Number, ESClass_String,
|
2014-09-16 20:45:31 +04:00
|
|
|
ESClass_Boolean, ESClass_RegExp, ESClass_ArrayBuffer, ESClass_SharedArrayBuffer,
|
2015-01-25 23:42:10 +03:00
|
|
|
ESClass_Date, ESClass_Set, ESClass_Map,
|
|
|
|
|
|
|
|
// Special snowflake for the ES6 IsArray method.
|
|
|
|
// Please don't use it without calling that function.
|
|
|
|
ESClass_IsArray
|
2013-08-22 09:26:57 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Return whether the given object has the given [[Class]] internal property
|
|
|
|
* value. Beware, this query says nothing about the js::Class of the JSObject
|
|
|
|
* so the caller must not assume anything about obj's representation (e.g., obj
|
|
|
|
* may be a proxy).
|
|
|
|
*/
|
|
|
|
inline bool
|
2015-03-29 01:22:11 +03:00
|
|
|
ObjectClassIs(JSObject& obj, ESClassValue classValue, JSContext* cx);
|
2013-08-22 09:26:57 +04:00
|
|
|
|
|
|
|
/* Just a helper that checks v.isObject before calling ObjectClassIs. */
|
|
|
|
inline bool
|
2015-03-29 01:22:11 +03:00
|
|
|
IsObjectWithClass(const JS::Value& v, ESClassValue classValue, JSContext* cx);
|
2013-08-22 09:26:57 +04:00
|
|
|
|
2014-08-19 01:18:39 +04:00
|
|
|
/* Fills |vp| with the unboxed value for boxed types, or undefined otherwise. */
|
|
|
|
inline bool
|
2015-03-29 01:22:11 +03:00
|
|
|
Unbox(JSContext* cx, JS::HandleObject obj, JS::MutableHandleValue vp);
|
2014-08-19 01:18:39 +04:00
|
|
|
|
2014-09-02 13:07:22 +04:00
|
|
|
#ifdef DEBUG
|
|
|
|
JS_FRIEND_API(bool)
|
2015-03-29 01:22:11 +03:00
|
|
|
HasObjectMovedOp(JSObject* obj);
|
2014-09-02 13:07:22 +04:00
|
|
|
#endif
|
|
|
|
|
2013-08-22 09:26:57 +04:00
|
|
|
} /* namespace js */
|
|
|
|
|
|
|
|
#endif /* js_Class_h */
|