2019-01-04 00:37:01 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* 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/. */
|
|
|
|
|
|
|
|
/* Property descriptors and flags. */
|
|
|
|
|
|
|
|
#ifndef js_PropertySpec_h
|
|
|
|
#define js_PropertySpec_h
|
|
|
|
|
|
|
|
#include "mozilla/Assertions.h" // MOZ_ASSERT{,_IF}
|
|
|
|
|
|
|
|
#include <stddef.h> // size_t
|
|
|
|
#include <stdint.h> // uint8_t, uint16_t, int32_t, uint32_t, uintptr_t
|
|
|
|
#include <type_traits> // std::enable_if
|
|
|
|
|
|
|
|
#include "jstypes.h" // JS_PUBLIC_API
|
|
|
|
|
|
|
|
#include "js/CallArgs.h" // JSNative
|
|
|
|
#include "js/PropertyDescriptor.h" // JSPROP_*
|
|
|
|
#include "js/RootingAPI.h" // JS::MutableHandle
|
2019-05-13 13:26:48 +03:00
|
|
|
#include "js/Symbol.h" // JS::SymbolCode, PropertySpecNameIsSymbol
|
2019-01-04 00:37:01 +03:00
|
|
|
#include "js/Value.h" // JS::Value
|
|
|
|
|
2019-10-28 01:34:11 +03:00
|
|
|
struct JS_PUBLIC_API JSContext;
|
2020-09-09 01:52:34 +03:00
|
|
|
class JSJitInfo;
|
2019-01-04 00:37:01 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Wrapper to relace JSNative for JSPropertySpecs and JSFunctionSpecs. This will
|
|
|
|
* allow us to pass one JSJitInfo per function with the property/function spec,
|
|
|
|
* without additional field overhead.
|
|
|
|
*/
|
|
|
|
struct JSNativeWrapper {
|
2019-04-26 04:01:15 +03:00
|
|
|
JSNative op = nullptr;
|
|
|
|
const JSJitInfo* info = nullptr;
|
2019-01-04 00:37:01 +03:00
|
|
|
|
2019-04-26 04:01:15 +03:00
|
|
|
JSNativeWrapper() = default;
|
|
|
|
|
|
|
|
JSNativeWrapper(const JSNativeWrapper& other) = default;
|
|
|
|
|
|
|
|
constexpr JSNativeWrapper(JSNative op, const JSJitInfo* info)
|
|
|
|
: op(op), info(info) {}
|
|
|
|
};
|
2019-01-04 00:37:01 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Description of a property. JS_DefineProperties and JS_InitClass take arrays
|
|
|
|
* of these and define many properties at once. JS_PSG, JS_PSGS and JS_PS_END
|
|
|
|
* are helper macros for defining such arrays.
|
|
|
|
*/
|
|
|
|
struct JSPropertySpec {
|
|
|
|
struct SelfHostedWrapper {
|
2019-04-26 04:01:15 +03:00
|
|
|
// The same type as JSNativeWrapper's first field, so that the access in
|
|
|
|
// JSPropertySpec::checkAccessorsAreSelfHosted become valid.
|
|
|
|
JSNative unused = nullptr;
|
|
|
|
|
2019-01-04 00:37:01 +03:00
|
|
|
const char* funname;
|
2019-04-26 04:01:15 +03:00
|
|
|
|
|
|
|
SelfHostedWrapper() = delete;
|
|
|
|
|
|
|
|
explicit constexpr SelfHostedWrapper(const char* funname)
|
|
|
|
: funname(funname) {}
|
2019-01-04 00:37:01 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
struct ValueWrapper {
|
2021-03-08 15:07:14 +03:00
|
|
|
enum class Type : uint8_t { String, Int32, Double };
|
|
|
|
Type type;
|
2019-01-04 00:37:01 +03:00
|
|
|
union {
|
|
|
|
const char* string;
|
|
|
|
int32_t int32;
|
2020-04-26 21:16:55 +03:00
|
|
|
double double_;
|
2019-01-04 00:37:01 +03:00
|
|
|
};
|
2019-04-26 04:01:15 +03:00
|
|
|
|
|
|
|
private:
|
|
|
|
ValueWrapper() = delete;
|
|
|
|
|
2021-03-08 15:07:14 +03:00
|
|
|
explicit constexpr ValueWrapper(int32_t n) : type(Type::Int32), int32(n) {}
|
2019-04-26 04:01:15 +03:00
|
|
|
|
|
|
|
explicit constexpr ValueWrapper(const char* s)
|
2021-03-08 15:07:14 +03:00
|
|
|
: type(Type::String), string(s) {}
|
2019-04-26 04:01:15 +03:00
|
|
|
|
2020-04-26 21:16:55 +03:00
|
|
|
explicit constexpr ValueWrapper(double d)
|
2021-03-08 15:07:14 +03:00
|
|
|
: type(Type::Double), double_(d) {}
|
2020-04-26 21:16:55 +03:00
|
|
|
|
2019-04-26 04:01:15 +03:00
|
|
|
public:
|
|
|
|
ValueWrapper(const ValueWrapper& other) = default;
|
|
|
|
|
|
|
|
static constexpr ValueWrapper int32Value(int32_t n) {
|
|
|
|
return ValueWrapper(n);
|
|
|
|
}
|
|
|
|
|
|
|
|
static constexpr ValueWrapper stringValue(const char* s) {
|
|
|
|
return ValueWrapper(s);
|
|
|
|
}
|
2020-04-26 21:16:55 +03:00
|
|
|
|
|
|
|
static constexpr ValueWrapper doubleValue(double d) {
|
|
|
|
return ValueWrapper(d);
|
|
|
|
}
|
2019-01-04 00:37:01 +03:00
|
|
|
};
|
|
|
|
|
2019-04-26 04:01:15 +03:00
|
|
|
union Accessor {
|
|
|
|
JSNativeWrapper native;
|
|
|
|
SelfHostedWrapper selfHosted;
|
|
|
|
|
|
|
|
private:
|
|
|
|
Accessor() = delete;
|
|
|
|
|
|
|
|
constexpr Accessor(JSNative op, const JSJitInfo* info) : native(op, info) {}
|
|
|
|
|
|
|
|
explicit constexpr Accessor(const char* funname) : selfHosted(funname) {}
|
|
|
|
|
|
|
|
public:
|
|
|
|
Accessor(const Accessor& other) = default;
|
|
|
|
|
|
|
|
static constexpr Accessor nativeAccessor(JSNative op,
|
|
|
|
const JSJitInfo* info = nullptr) {
|
|
|
|
return Accessor(op, info);
|
|
|
|
}
|
|
|
|
|
|
|
|
static constexpr Accessor selfHostedAccessor(const char* funname) {
|
|
|
|
return Accessor(funname);
|
|
|
|
}
|
|
|
|
|
|
|
|
static constexpr Accessor noAccessor() {
|
|
|
|
return Accessor(nullptr, nullptr);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
union AccessorsOrValue {
|
|
|
|
struct Accessors {
|
|
|
|
Accessor getter;
|
|
|
|
Accessor setter;
|
|
|
|
|
|
|
|
constexpr Accessors(Accessor getter, Accessor setter)
|
|
|
|
: getter(getter), setter(setter) {}
|
2019-01-04 00:37:01 +03:00
|
|
|
} accessors;
|
|
|
|
ValueWrapper value;
|
2019-04-26 04:01:15 +03:00
|
|
|
|
|
|
|
private:
|
|
|
|
AccessorsOrValue() = delete;
|
|
|
|
|
|
|
|
constexpr AccessorsOrValue(Accessor getter, Accessor setter)
|
|
|
|
: accessors(getter, setter) {}
|
|
|
|
|
|
|
|
explicit constexpr AccessorsOrValue(ValueWrapper value) : value(value) {}
|
|
|
|
|
|
|
|
public:
|
|
|
|
AccessorsOrValue(const AccessorsOrValue& other) = default;
|
|
|
|
|
|
|
|
static constexpr AccessorsOrValue fromAccessors(Accessor getter,
|
|
|
|
Accessor setter) {
|
|
|
|
return AccessorsOrValue(getter, setter);
|
|
|
|
}
|
|
|
|
|
|
|
|
static constexpr AccessorsOrValue fromValue(ValueWrapper value) {
|
|
|
|
return AccessorsOrValue(value);
|
|
|
|
}
|
2019-01-04 00:37:01 +03:00
|
|
|
};
|
|
|
|
|
2019-05-13 13:26:48 +03:00
|
|
|
union Name {
|
|
|
|
private:
|
|
|
|
const char* string_;
|
|
|
|
uintptr_t symbol_;
|
|
|
|
|
|
|
|
public:
|
|
|
|
Name() = delete;
|
|
|
|
|
|
|
|
explicit constexpr Name(const char* str) : string_(str) {}
|
|
|
|
explicit constexpr Name(JS::SymbolCode symbol)
|
|
|
|
: symbol_(uint32_t(symbol) + 1) {}
|
|
|
|
|
|
|
|
explicit operator bool() const { return !!symbol_; }
|
|
|
|
|
|
|
|
bool isSymbol() const { return JS::PropertySpecNameIsSymbol(symbol_); }
|
|
|
|
JS::SymbolCode symbol() const {
|
|
|
|
MOZ_ASSERT(isSymbol());
|
|
|
|
return JS::SymbolCode(symbol_ - 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool isString() const { return !isSymbol(); }
|
|
|
|
const char* string() const {
|
|
|
|
MOZ_ASSERT(isString());
|
|
|
|
return string_;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
Name name;
|
2020-04-25 17:06:40 +03:00
|
|
|
|
|
|
|
private:
|
2021-03-08 15:07:15 +03:00
|
|
|
// JSPROP_* property attributes as defined in PropertyDescriptor.h.
|
|
|
|
uint8_t attributes_;
|
2020-04-25 17:06:40 +03:00
|
|
|
|
2021-05-27 18:03:37 +03:00
|
|
|
// Whether AccessorsOrValue below stores a value, JSNative accessors, or
|
|
|
|
// self-hosted accessors.
|
|
|
|
enum class Kind : uint8_t { Value, SelfHostedAccessor, NativeAccessor };
|
|
|
|
Kind kind_;
|
2021-03-08 15:07:14 +03:00
|
|
|
|
2020-04-25 17:06:40 +03:00
|
|
|
public:
|
2019-04-26 04:01:15 +03:00
|
|
|
AccessorsOrValue u;
|
|
|
|
|
|
|
|
private:
|
|
|
|
JSPropertySpec() = delete;
|
|
|
|
|
2021-05-27 18:03:37 +03:00
|
|
|
constexpr JSPropertySpec(const char* name, uint8_t attributes, Kind kind,
|
|
|
|
AccessorsOrValue u)
|
|
|
|
: name(name), attributes_(attributes), kind_(kind), u(u) {}
|
|
|
|
constexpr JSPropertySpec(JS::SymbolCode name, uint8_t attributes, Kind kind,
|
|
|
|
AccessorsOrValue u)
|
|
|
|
: name(name), attributes_(attributes), kind_(kind), u(u) {}
|
2019-04-26 04:01:15 +03:00
|
|
|
|
|
|
|
public:
|
|
|
|
JSPropertySpec(const JSPropertySpec& other) = default;
|
|
|
|
|
|
|
|
static constexpr JSPropertySpec nativeAccessors(
|
2021-03-08 15:07:15 +03:00
|
|
|
const char* name, uint8_t attributes, JSNative getter,
|
2019-04-26 04:01:15 +03:00
|
|
|
const JSJitInfo* getterInfo, JSNative setter = nullptr,
|
|
|
|
const JSJitInfo* setterInfo = nullptr) {
|
|
|
|
return JSPropertySpec(
|
2021-05-27 18:03:37 +03:00
|
|
|
name, attributes, Kind::NativeAccessor,
|
2019-04-26 04:01:15 +03:00
|
|
|
AccessorsOrValue::fromAccessors(
|
|
|
|
JSPropertySpec::Accessor::nativeAccessor(getter, getterInfo),
|
|
|
|
JSPropertySpec::Accessor::nativeAccessor(setter, setterInfo)));
|
|
|
|
}
|
|
|
|
|
2019-05-13 13:26:48 +03:00
|
|
|
static constexpr JSPropertySpec nativeAccessors(
|
2021-03-08 15:07:15 +03:00
|
|
|
JS::SymbolCode name, uint8_t attributes, JSNative getter,
|
2019-05-13 13:26:48 +03:00
|
|
|
const JSJitInfo* getterInfo, JSNative setter = nullptr,
|
|
|
|
const JSJitInfo* setterInfo = nullptr) {
|
|
|
|
return JSPropertySpec(
|
2021-05-27 18:03:37 +03:00
|
|
|
name, attributes, Kind::NativeAccessor,
|
2019-05-13 13:26:48 +03:00
|
|
|
AccessorsOrValue::fromAccessors(
|
|
|
|
JSPropertySpec::Accessor::nativeAccessor(getter, getterInfo),
|
|
|
|
JSPropertySpec::Accessor::nativeAccessor(setter, setterInfo)));
|
|
|
|
}
|
|
|
|
|
2019-04-26 04:01:15 +03:00
|
|
|
static constexpr JSPropertySpec selfHostedAccessors(
|
2021-03-08 15:07:15 +03:00
|
|
|
const char* name, uint8_t attributes, const char* getterName,
|
2019-04-26 04:01:15 +03:00
|
|
|
const char* setterName = nullptr) {
|
|
|
|
return JSPropertySpec(
|
2021-05-27 18:03:38 +03:00
|
|
|
name, attributes, Kind::SelfHostedAccessor,
|
2019-04-26 04:01:15 +03:00
|
|
|
AccessorsOrValue::fromAccessors(
|
|
|
|
JSPropertySpec::Accessor::selfHostedAccessor(getterName),
|
|
|
|
setterName
|
|
|
|
? JSPropertySpec::Accessor::selfHostedAccessor(setterName)
|
|
|
|
: JSPropertySpec::Accessor::noAccessor()));
|
|
|
|
}
|
|
|
|
|
2019-05-13 13:26:48 +03:00
|
|
|
static constexpr JSPropertySpec selfHostedAccessors(
|
2021-03-08 15:07:15 +03:00
|
|
|
JS::SymbolCode name, uint8_t attributes, const char* getterName,
|
2019-05-13 13:26:48 +03:00
|
|
|
const char* setterName = nullptr) {
|
|
|
|
return JSPropertySpec(
|
2021-05-27 18:03:38 +03:00
|
|
|
name, attributes, Kind::SelfHostedAccessor,
|
2019-05-13 13:26:48 +03:00
|
|
|
AccessorsOrValue::fromAccessors(
|
|
|
|
JSPropertySpec::Accessor::selfHostedAccessor(getterName),
|
|
|
|
setterName
|
|
|
|
? JSPropertySpec::Accessor::selfHostedAccessor(setterName)
|
|
|
|
: JSPropertySpec::Accessor::noAccessor()));
|
|
|
|
}
|
|
|
|
|
2021-03-08 15:07:15 +03:00
|
|
|
static constexpr JSPropertySpec int32Value(const char* name,
|
|
|
|
uint8_t attributes, int32_t n) {
|
2021-05-27 18:03:37 +03:00
|
|
|
return JSPropertySpec(name, attributes, Kind::Value,
|
2019-04-26 04:01:15 +03:00
|
|
|
AccessorsOrValue::fromValue(
|
|
|
|
JSPropertySpec::ValueWrapper::int32Value(n)));
|
|
|
|
}
|
|
|
|
|
2021-03-08 15:07:15 +03:00
|
|
|
static constexpr JSPropertySpec int32Value(JS::SymbolCode name,
|
|
|
|
uint8_t attributes, int32_t n) {
|
2021-05-27 18:03:37 +03:00
|
|
|
return JSPropertySpec(name, attributes, Kind::Value,
|
2019-05-13 13:26:48 +03:00
|
|
|
AccessorsOrValue::fromValue(
|
|
|
|
JSPropertySpec::ValueWrapper::int32Value(n)));
|
|
|
|
}
|
|
|
|
|
2021-03-08 15:07:15 +03:00
|
|
|
static constexpr JSPropertySpec stringValue(const char* name,
|
|
|
|
uint8_t attributes,
|
2019-04-26 04:01:15 +03:00
|
|
|
const char* s) {
|
2021-05-27 18:03:37 +03:00
|
|
|
return JSPropertySpec(name, attributes, Kind::Value,
|
2019-04-26 04:01:15 +03:00
|
|
|
AccessorsOrValue::fromValue(
|
|
|
|
JSPropertySpec::ValueWrapper::stringValue(s)));
|
|
|
|
}
|
|
|
|
|
2019-05-13 13:26:48 +03:00
|
|
|
static constexpr JSPropertySpec stringValue(JS::SymbolCode name,
|
2021-03-08 15:07:15 +03:00
|
|
|
uint8_t attributes,
|
|
|
|
const char* s) {
|
2021-05-27 18:03:37 +03:00
|
|
|
return JSPropertySpec(name, attributes, Kind::Value,
|
2019-05-13 13:26:48 +03:00
|
|
|
AccessorsOrValue::fromValue(
|
|
|
|
JSPropertySpec::ValueWrapper::stringValue(s)));
|
|
|
|
}
|
|
|
|
|
2021-03-08 15:07:15 +03:00
|
|
|
static constexpr JSPropertySpec doubleValue(const char* name,
|
|
|
|
uint8_t attributes, double d) {
|
2021-05-27 18:03:37 +03:00
|
|
|
return JSPropertySpec(name, attributes, Kind::Value,
|
2020-04-26 21:16:55 +03:00
|
|
|
AccessorsOrValue::fromValue(
|
|
|
|
JSPropertySpec::ValueWrapper::doubleValue(d)));
|
|
|
|
}
|
|
|
|
|
2019-04-26 04:01:15 +03:00
|
|
|
static constexpr JSPropertySpec sentinel() {
|
2021-05-27 18:03:37 +03:00
|
|
|
return JSPropertySpec(nullptr, 0, Kind::NativeAccessor,
|
2019-04-26 04:01:15 +03:00
|
|
|
AccessorsOrValue::fromAccessors(
|
|
|
|
JSPropertySpec::Accessor::noAccessor(),
|
|
|
|
JSPropertySpec::Accessor::noAccessor()));
|
|
|
|
}
|
|
|
|
|
2021-03-08 15:07:15 +03:00
|
|
|
unsigned attributes() const { return attributes_; }
|
2021-05-27 18:03:37 +03:00
|
|
|
|
|
|
|
bool isAccessor() const {
|
|
|
|
return (kind_ == Kind::NativeAccessor || kind_ == Kind::SelfHostedAccessor);
|
|
|
|
}
|
2020-04-25 17:06:40 +03:00
|
|
|
|
2019-01-04 00:37:01 +03:00
|
|
|
JS_PUBLIC_API bool getValue(JSContext* cx,
|
|
|
|
JS::MutableHandle<JS::Value> value) const;
|
|
|
|
|
|
|
|
bool isSelfHosted() const {
|
|
|
|
MOZ_ASSERT(isAccessor());
|
|
|
|
#ifdef DEBUG
|
2021-05-27 18:03:37 +03:00
|
|
|
// Verify that our accessors match our Kind.
|
|
|
|
if (kind_ == Kind::SelfHostedAccessor) {
|
2019-01-04 00:37:01 +03:00
|
|
|
checkAccessorsAreSelfHosted();
|
|
|
|
} else {
|
|
|
|
checkAccessorsAreNative();
|
|
|
|
}
|
|
|
|
#endif
|
2021-05-27 18:03:37 +03:00
|
|
|
return kind_ == Kind::SelfHostedAccessor;
|
2019-01-04 00:37:01 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static_assert(sizeof(SelfHostedWrapper) == sizeof(JSNativeWrapper),
|
|
|
|
"JSPropertySpec::getter/setter must be compact");
|
2019-04-26 04:01:15 +03:00
|
|
|
static_assert(offsetof(SelfHostedWrapper, unused) ==
|
|
|
|
offsetof(JSNativeWrapper, op) &&
|
|
|
|
offsetof(SelfHostedWrapper, funname) ==
|
2019-01-04 00:37:01 +03:00
|
|
|
offsetof(JSNativeWrapper, info),
|
2019-04-26 04:01:15 +03:00
|
|
|
"checkAccessorsAreNative below require that "
|
2019-01-04 00:37:01 +03:00
|
|
|
"SelfHostedWrapper::funname overlay "
|
2019-04-26 04:01:15 +03:00
|
|
|
"JSNativeWrapper::info and "
|
|
|
|
"SelfHostedWrapper::unused overlay "
|
|
|
|
"JSNativeWrapper::op");
|
2019-01-04 00:37:01 +03:00
|
|
|
|
|
|
|
private:
|
|
|
|
void checkAccessorsAreNative() const {
|
2019-01-09 19:45:05 +03:00
|
|
|
// We may have a getter or a setter or both. And whichever ones we have
|
|
|
|
// should not have a SelfHostedWrapper for the accessor.
|
2019-04-26 04:01:15 +03:00
|
|
|
MOZ_ASSERT_IF(u.accessors.getter.native.info, u.accessors.getter.native.op);
|
|
|
|
MOZ_ASSERT_IF(u.accessors.setter.native.info, u.accessors.setter.native.op);
|
2019-01-04 00:37:01 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void checkAccessorsAreSelfHosted() const {
|
2019-04-26 04:01:15 +03:00
|
|
|
MOZ_ASSERT(!u.accessors.getter.selfHosted.unused);
|
|
|
|
MOZ_ASSERT(!u.accessors.setter.selfHosted.unused);
|
2019-01-04 00:37:01 +03:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2021-03-08 15:07:13 +03:00
|
|
|
// There can be many JSPropertySpec instances so verify the size is what we
|
|
|
|
// expect:
|
|
|
|
//
|
|
|
|
// - Name (1 word)
|
2021-03-08 15:07:15 +03:00
|
|
|
// - attributes_ + isAccessor_ (1 word)
|
2021-03-08 15:07:13 +03:00
|
|
|
// - AccessorsOrValue (4 words, native + JSJitInfo for both getter and setter)
|
|
|
|
static_assert(sizeof(JSPropertySpec) == 6 * sizeof(uintptr_t));
|
|
|
|
|
2021-03-08 15:07:15 +03:00
|
|
|
template <unsigned Attributes>
|
|
|
|
constexpr uint8_t CheckAccessorAttrs() {
|
|
|
|
static_assert((Attributes & ~(JSPROP_ENUMERATE | JSPROP_PERMANENT)) == 0,
|
|
|
|
"Unexpected flag (not JSPROP_ENUMERATE or JSPROP_PERMANENT)");
|
|
|
|
return uint8_t(Attributes);
|
|
|
|
}
|
|
|
|
|
|
|
|
#define JS_PSG(name, getter, attributes) \
|
|
|
|
JSPropertySpec::nativeAccessors(name, CheckAccessorAttrs<attributes>(), \
|
2019-04-26 04:01:15 +03:00
|
|
|
getter, nullptr)
|
2021-03-08 15:07:15 +03:00
|
|
|
#define JS_PSGS(name, getter, setter, attributes) \
|
|
|
|
JSPropertySpec::nativeAccessors(name, CheckAccessorAttrs<attributes>(), \
|
2019-04-26 04:01:15 +03:00
|
|
|
getter, nullptr, setter, nullptr)
|
2021-03-08 15:07:15 +03:00
|
|
|
#define JS_SYM_GET(symbol, getter, attributes) \
|
|
|
|
JSPropertySpec::nativeAccessors(::JS::SymbolCode::symbol, \
|
|
|
|
CheckAccessorAttrs<attributes>(), getter, \
|
2019-05-13 13:26:48 +03:00
|
|
|
nullptr)
|
2021-03-08 15:07:15 +03:00
|
|
|
#define JS_SELF_HOSTED_GET(name, getterName, attributes) \
|
|
|
|
JSPropertySpec::selfHostedAccessors(name, CheckAccessorAttrs<attributes>(), \
|
2019-04-26 04:01:15 +03:00
|
|
|
getterName)
|
2021-03-08 15:07:15 +03:00
|
|
|
#define JS_SELF_HOSTED_GETSET(name, getterName, setterName, attributes) \
|
|
|
|
JSPropertySpec::selfHostedAccessors(name, CheckAccessorAttrs<attributes>(), \
|
|
|
|
getterName, setterName)
|
|
|
|
#define JS_SELF_HOSTED_SYM_GET(symbol, getterName, attributes) \
|
|
|
|
JSPropertySpec::selfHostedAccessors( \
|
|
|
|
::JS::SymbolCode::symbol, CheckAccessorAttrs<attributes>(), getterName)
|
2021-03-08 15:07:15 +03:00
|
|
|
#define JS_STRING_PS(name, string, attributes) \
|
|
|
|
JSPropertySpec::stringValue(name, attributes, string)
|
|
|
|
#define JS_STRING_SYM_PS(symbol, string, attributes) \
|
|
|
|
JSPropertySpec::stringValue(::JS::SymbolCode::symbol, attributes, string)
|
|
|
|
#define JS_INT32_PS(name, value, attributes) \
|
|
|
|
JSPropertySpec::int32Value(name, attributes, value)
|
|
|
|
#define JS_DOUBLE_PS(name, value, attributes) \
|
|
|
|
JSPropertySpec::doubleValue(name, attributes, value)
|
2019-04-26 04:01:15 +03:00
|
|
|
#define JS_PS_END JSPropertySpec::sentinel()
|
2019-01-04 00:37:01 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* To define a native function, set call to a JSNativeWrapper. To define a
|
|
|
|
* self-hosted function, set selfHostedName to the name of a function
|
|
|
|
* compiled during JSRuntime::initSelfHosting.
|
|
|
|
*/
|
|
|
|
struct JSFunctionSpec {
|
2019-05-13 13:26:48 +03:00
|
|
|
using Name = JSPropertySpec::Name;
|
|
|
|
|
|
|
|
Name name;
|
2019-01-04 00:37:01 +03:00
|
|
|
JSNativeWrapper call;
|
|
|
|
uint16_t nargs;
|
|
|
|
uint16_t flags;
|
|
|
|
const char* selfHostedName;
|
2020-04-25 17:06:40 +03:00
|
|
|
|
|
|
|
// JSPROP_* property attributes as defined in PropertyDescriptor.h
|
|
|
|
unsigned attributes() const { return flags; }
|
2019-01-04 00:37:01 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Terminating sentinel initializer to put at the end of a JSFunctionSpec array
|
|
|
|
* that's passed to JS_DefineFunctions or JS_InitClass.
|
|
|
|
*/
|
|
|
|
#define JS_FS_END JS_FN(nullptr, nullptr, 0, 0)
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Initializer macros for a JSFunctionSpec array element. JS_FNINFO allows the
|
|
|
|
* simple adding of JSJitInfos. JS_SELF_HOSTED_FN declares a self-hosted
|
|
|
|
* function. JS_INLINABLE_FN allows specifying an InlinableNative enum value for
|
|
|
|
* natives inlined or specialized by the JIT. Finally JS_FNSPEC has slots for
|
|
|
|
* all the fields.
|
|
|
|
*
|
|
|
|
* The _SYM variants allow defining a function with a symbol key rather than a
|
|
|
|
* string key. For example, use JS_SYM_FN(iterator, ...) to define an
|
|
|
|
* @@iterator method.
|
|
|
|
*/
|
|
|
|
#define JS_FN(name, call, nargs, flags) \
|
|
|
|
JS_FNSPEC(name, call, nullptr, nargs, flags, nullptr)
|
|
|
|
#define JS_INLINABLE_FN(name, call, nargs, flags, native) \
|
|
|
|
JS_FNSPEC(name, call, &js::jit::JitInfo_##native, nargs, flags, nullptr)
|
|
|
|
#define JS_SYM_FN(symbol, call, nargs, flags) \
|
|
|
|
JS_SYM_FNSPEC(symbol, call, nullptr, nargs, flags, nullptr)
|
|
|
|
#define JS_FNINFO(name, call, info, nargs, flags) \
|
|
|
|
JS_FNSPEC(name, call, info, nargs, flags, nullptr)
|
|
|
|
#define JS_SELF_HOSTED_FN(name, selfHostedName, nargs, flags) \
|
|
|
|
JS_FNSPEC(name, nullptr, nullptr, nargs, flags, selfHostedName)
|
|
|
|
#define JS_SELF_HOSTED_SYM_FN(symbol, selfHostedName, nargs, flags) \
|
|
|
|
JS_SYM_FNSPEC(symbol, nullptr, nullptr, nargs, flags, selfHostedName)
|
2019-05-13 13:26:48 +03:00
|
|
|
#define JS_SYM_FNSPEC(symbol, call, info, nargs, flags, selfHostedName) \
|
|
|
|
JS_FNSPEC(::JS::SymbolCode::symbol, call, info, nargs, flags, selfHostedName)
|
2019-01-04 00:37:01 +03:00
|
|
|
#define JS_FNSPEC(name, call, info, nargs, flags, selfHostedName) \
|
2019-05-13 13:26:48 +03:00
|
|
|
{ JSFunctionSpec::Name(name), {call, info}, nargs, flags, selfHostedName }
|
2019-01-04 00:37:01 +03:00
|
|
|
|
|
|
|
#endif // js_PropertySpec_h
|