7#pragma push_macro("None")
10#include <Ultralight/CAPI/CAPI_JSAPI.h>
11#include <Ultralight/CAPI/CAPI_JSValue.h>
12#include <Ultralight/CAPI/CAPI_String.h>
13#include <Ultralight/detail/Exceptions.h>
35template <
typename T,
typename =
void>
75 None = kULJSPropertyAttributes_None,
87 return static_cast<PropertyAttributes>(
static_cast<unsigned>(a) |
static_cast<unsigned>(b));
97enum class Type :
unsigned {
102 Number = kULJSType_Number,
106 Object = kULJSType_Object,
109static_assert(kULJSType_Count == 9,
"js::Type must list every ULJSType");
134 Map = kULJSObjectKind_Map,
135 Set = kULJSObjectKind_Set,
148static_assert(kULJSObjectKind_Count == 18,
"js::ObjectKind must list every ULJSObjectKind");
164 return static_cast<OwnKeysFlags>(
static_cast<unsigned>(a) |
static_cast<unsigned>(b));
171concept PropertyIndex = std::is_integral_v<I> && !std::is_same_v<I, bool>;
287 : handle_(other.handle_ ? ulCreateJSValueRef(other.handle_) : nullptr) {}
292 Value(
Value&& other) noexcept : handle_(other.handle_) { other.handle_ =
nullptr; }
298 std::swap(handle_, other.handle_);
310 explicit operator bool()
const {
return IsAlive(); }
315 bool IsEmpty()
const {
return handle_ ==
nullptr; }
323 bool IsAlive()
const {
return handle_ && ulJSValueIsAlive(handle_); }
331 Type type()
const {
return static_cast<Type>(ulJSValueGetType(handle_)); }
378 bool IsArray()
const {
return handle_ && ulJSValueIsArray(handle_); }
383 bool IsCallable()
const {
return handle_ && ulJSValueIsCallable(handle_); }
391 bool IsFunction()
const {
return handle_ && ulJSValueIsFunction(handle_); }
398 bool IsPromise()
const {
return handle_ && ulJSValueIsPromise(handle_); }
403 bool IsConstructor()
const {
return handle_ && ulJSValueIsConstructor(handle_); }
421 return static_cast<ObjectKind>(ulJSValueGetObjectKind(handle_));
436 return handle_ && other.handle_ && ulJSValueIsStrictEqual(handle_, other.handle_);
452 return detail::EmptyHandleError();
453 double ms_since_epoch = 0.0;
454 if (ulJSDateGetTime(handle_, &ms_since_epoch))
455 return ms_since_epoch;
468 return detail::EmptyHandleError();
470 if (!ulJSValueToBoolean(handle_, &result))
483 return detail::EmptyHandleError();
485 ULJSValue exception =
nullptr;
486 if (!ulJSValueToNumber(handle_, &result, &exception)) {
502 return detail::EmptyHandleError();
503 ULJSValue exception =
nullptr;
504 if (ulJSValueGetType(handle_) == kULJSType_String) {
506 char stack_buffer[256];
508 if (ulJSValueGetUTF8(handle_, stack_buffer,
sizeof(stack_buffer), &length, &exception))
509 return std::string(stack_buffer, length);
510 if (!exception && length >
sizeof(stack_buffer)) {
511 std::string heap(length,
'\0');
512 if (ulJSValueGetUTF8(handle_, heap.data(), heap.size(), &length, &exception))
519 ULString s = ulJSValueToString(handle_, &exception);
525 std::string result(ulStringGetData(s), ulStringGetLength(s));
542 return detail::EmptyHandleError();
543 ULJSValue exception =
nullptr;
544 ULString s = ulJSValueToJSON(handle_, indent, &exception);
550 if (ulJSValueIsAlive(handle_))
551 return Unexpected<Error>(
Error::TypeError(
"The value has no JSON representation."));
554 std::string result(ulStringGetData(s), ulStringGetLength(s));
569 return detail::EmptyHandleError();
570 ULJSValue exception =
nullptr;
571 ULJSValue result = ulJSObjectGetProperty(handle_, name ? name :
"", &exception);
577 return Adopt(result);
591 bool Has(
const char* name)
const {
592 detail::SwallowedException swallow;
593 return handle_ && ulJSObjectHasProperty(handle_, name ? name :
"", swallow.out());
606 return detail::EmptyHandleError();
607 ULJSValue exception =
nullptr;
608 bool present = ulJSObjectHasProperty(handle_, name ? name :
"", &exception);
609 return CheckedBool(present, exception);
633 const char* name,
const Value& value,
636 return detail::EmptyHandleError();
637 ULJSValue exception =
nullptr;
638 if (ulJSObjectSetProperty(handle_, name ? name :
"", value.handle_,
639 static_cast<unsigned>(attributes), &exception))
664 return detail::EmptyHandleError();
665 ULJSValue exception =
nullptr;
666 bool deleted = ulJSObjectDeleteProperty(handle_, name ? name :
"", &exception);
667 return CheckedBool(deleted, exception);
681 template <detail::PropertyIndex I>
684 return detail::EmptyHandleError();
685 ULJSValue exception =
nullptr;
686 return CheckedBool(DeleteByKey(ResolveIndex(index), &exception), exception);
698 [[nodiscard]]
bool Delete(
const char* name)
const {
699 detail::SwallowedException swallow;
700 return handle_ && ulJSObjectDeleteProperty(handle_, name ? name :
"", swallow.out());
713 template <detail::PropertyIndex I>
714 [[nodiscard]]
bool Delete(I index)
const {
715 detail::SwallowedException swallow;
716 return handle_ && DeleteByKey(ResolveIndex(index), swallow.out());
731 detail::SwallowedException swallow;
732 return handle_ && ulJSObjectHasOwnProperty(handle_, name ? name :
"", swallow.out());
744 template <detail::PropertyIndex I>
746 return HasOwn(IndexName(index).text);
760 return detail::EmptyHandleError();
761 ULJSValue exception =
nullptr;
762 bool present = ulJSObjectHasOwnProperty(handle_, name ? name :
"", &exception);
763 return CheckedBool(present, exception);
776 template <detail::PropertyIndex I>
807 return detail::EmptyHandleError();
808 ULJSValue exception =
nullptr;
809 ULJSStringList list =
810 ulJSObjectGetOwnKeys(handle_,
static_cast<unsigned>(flags), &exception);
818 std::vector<std::string> keys;
819 size_t length = ulJSStringListGetLength(list);
820 keys.reserve(length);
821 for (
size_t i = 0; i < length; i++) {
822 if (ULString key = ulJSStringListGetString(list, i)) {
823 keys.emplace_back(ulStringGetData(key), ulStringGetLength(key));
824 ulDestroyString(key);
827 ulDestroyJSStringList(list);
858 const char* name,
const Value& value,
861 return detail::EmptyHandleError();
862 ULJSValue exception =
nullptr;
863 bool defined = ulJSObjectDefineProperty(handle_, name ? name :
"", value.handle_,
864 static_cast<unsigned>(attributes), &exception);
865 return CheckedBool(defined, exception);
897 const char* name,
const Value& getter,
const Value& setter,
900 return detail::EmptyHandleError();
901 ULJSValue exception =
nullptr;
903 ulJSObjectDefineAccessor(handle_, name ? name :
"", getter.handle_, setter.handle_,
904 static_cast<unsigned>(attributes), &exception);
905 return CheckedBool(defined, exception);
922 return detail::EmptyHandleError();
923 ULJSValue exception =
nullptr;
924 if (ulJSObjectFreeze(handle_, &exception))
946 return detail::EmptyHandleError();
947 RawArgs
raw(args, argc);
948 ULJSValue exception =
nullptr;
949 ULJSValue result = ulJSFunctionCall(handle_, this_value.handle_,
raw.data, argc, &exception);
950 return AdoptResult(result, exception);
965 std::span<const Value> args)
const {
966 return Call(this_value, args.data(), args.size());
996 template <
typename T>
1004 template <
typename T>
1005 [[nodiscard]] std::optional<T>
Maybe()
const;
1017 template <
typename T>
1018 [[nodiscard]] T
Or(T fallback)
const;
1027 [[nodiscard]] std::string
Or(
const char* fallback)
const;
1047 template <
typename R =
Value,
typename... A>
1063 template <
typename R =
Value,
typename... A>
1087 template <
typename R =
Value,
typename... A>
1104 return detail::EmptyHandleError();
1105 RawArgs
raw(args.data(), args.size());
1106 ULJSValue exception =
nullptr;
1107 ULJSValue result = ulJSFunctionConstruct(handle_,
raw.data, args.size(), &exception);
1108 return AdoptResult(result, exception);
1118 template <
typename... A>
1159 template <
typename F>
1160 [[nodiscard]]
bool Then(F&& on_settled)
const {
1161 using Fn = std::decay_t<F>;
1162 static_assert(std::is_invocable_v<Fn&, Result<Value>>,
1163 "js::Value::Then takes a callable invocable with js::Result<js::Value>");
1164 auto* fn =
new Fn(std::forward<F>(on_settled));
1166 return ulJSPromiseThen(handle_, &ThenThunk<Fn>, fn, &DeleteThenCallable<Fn>);
1185 template <
typename T,
typename F>
1186 requires(!std::is_same_v<T, Value>)
1187 [[nodiscard]]
bool Then(F&& on_settled)
const {
1188 using Fn = std::decay_t<F>;
1189 static_assert(std::is_invocable_v<Fn&, Result<T>>,
1190 "js::Value::Then<T> takes a callable invocable with js::Result<T>");
1191 return Then(TypedSettleAdapter<T, Fn> { std::forward<F>(on_settled) });
1225 template <detail::PropertyIndex I>
1255 return Value(handle ? ulCreateJSValueRef(handle) :
nullptr);
1263 ULJSValue
raw()
const {
return handle_; }
1271 ULJSValue handle = handle_;
1277 explicit Value(ULJSValue handle) : handle_(handle) {}
1285 static IndexKey MakeIndexKey(
long long value) {
1287 snprintf(key.text,
sizeof(key.text),
"%lld", value);
1291 static IndexKey MakeIndexKey(
unsigned long long value) {
1293 snprintf(key.text,
sizeof(key.text),
"%llu", value);
1297 template <detail::PropertyIndex I>
1298 static IndexKey IndexName(I index) {
1299 if constexpr (std::is_signed_v<I>)
1300 return MakeIndexKey(
static_cast<long long>(index));
1302 return MakeIndexKey(
static_cast<unsigned long long>(index));
1307 struct PropertyKey {
1313 template <detail::PropertyIndex I>
1314 static PropertyKey ResolveIndex(I index) {
1315 if constexpr (std::is_signed_v<I>) {
1317 return {
false, 0, IndexName(index) };
1319 unsigned long long wide =
static_cast<unsigned long long>(index);
1320 if (wide > SIZE_MAX)
1321 return {
false, 0, IndexName(index) };
1322 return {
true,
static_cast<size_t>(wide), {} };
1325 bool DeleteByKey(
const PropertyKey& key, ULJSValue* exception)
const {
1327 return ulJSObjectDeletePropertyAtIndex(handle_, key.index, exception);
1328 return ulJSObjectDeleteProperty(handle_, key.name.text, exception);
1331 template <
typename I>
1332 Ref MakeIndexRef(I index)
const;
1336 Result<bool> CheckedBool(
bool value, ULJSValue exception)
const {
1344 static Result<Value> AdoptResult(ULJSValue result, ULJSValue exception) {
1346 return Adopt(result);
1358 RawArgs(
const Value* args,
size_t argc) : data(argc > 8 ? new ULJSValue[argc] : stack) {
1359 for (
size_t i = 0; i < argc; i++)
1360 data[i] = args[i].handle_;
1366 RawArgs(
const RawArgs&) =
delete;
1367 RawArgs& operator=(
const RawArgs&) =
delete;
1372 template <
typename T,
typename Fn>
1373 struct TypedSettleAdapter {
1377 fn(
Result<T>(Unexpected<Error>(std::move(settled).error())));
1379 fn(settled.value().To<T>());
1383 template <
typename Fn>
1384 static void ThenThunk(
void* user_data,
ULJSContext, ULJSValue result,
bool rejected) {
1385 Fn& fn = *
static_cast<Fn*
>(user_data);
1387 ultralight::detail::CallCatchingExceptions(
1397 [](
const char* what) { detail::LogNativeException(
"js::Value::Then", what); });
1400 template <
typename Fn>
1401 static void DeleteThenCallable(
void* user_data) {
1402 delete static_cast<Fn*
>(user_data);
1428 detail::SwallowedException swallow;
1431 object_.raw() ? ulJSObjectGetPropertyAtIndex(object_.raw(), index_, swallow.out())
1434 object_.raw() ? ulJSObjectGetProperty(object_.raw(), name_.c_str(), swallow.out())
1453 template <
typename T>
1465 return Chained(value, value[name]);
1467 template <detail::PropertyIndex I>
1470 return Chained(value, value[index]);
1486 template <
typename R =
Value,
typename... A>
1502 template <
typename R =
Value,
typename... A>
1512 template <
typename... A>
1522 template <
typename T>
1530 template <
typename T>
1531 [[nodiscard]] std::optional<T>
Maybe()
const;
1540 template <
typename T>
1541 [[nodiscard]] T
Or(T fallback)
const;
1550 [[nodiscard]] std::string
Or(
const char* fallback)
const {
return Get().
Or(fallback); }
1572 Ref(
Value object,
const char* name)
1573 : object_(
std::move(object)), name_(name ? name :
""), by_index_(false), index_(0) {}
1575 : object_(
std::move(object)), by_index_(true), index_(index) {}
1579 bool SourceGone()
const {
return source_gone_ || (object_.
raw() && !object_.
IsAlive()); }
1584 next.source_gone_ = value.IsEmpty() && SourceGone();
1592 bool source_gone_ =
false;
1596 return Ref(*
this, name);
1599template <
typename I>
1600Value::Ref Value::MakeIndexRef(I index)
const {
1601 PropertyKey key = ResolveIndex(index);
1603 return Ref(*
this, key.index);
1604 return Ref(*
this, key.name.text);
1607template <detail::PropertyIndex I>
1609 return MakeIndexRef(index);
1650 explicit Arg(ULJSValue borrowed) : borrowed_(borrowed) {}
1659 bool IsEmpty()
const {
return borrowed_ ==
nullptr; }
1664 Type type()
const {
return static_cast<Type>(ulJSValueGetType(borrowed_)); }
1673 template <
typename T>
1681 template <
typename T>
1682 [[nodiscard]] std::optional<T>
Maybe()
const;
1691 template <
typename T>
1692 [[nodiscard]] T
Or(T fallback)
const;
1701 [[nodiscard]] std::string
Or(
const char* fallback)
const;
1715 ULJSValue
raw()
const {
return borrowed_; }
1718 ULJSValue borrowed_;
1742template <
typename T>
1743[[nodiscard]] T
Or(
const Value& value, T fallback) {
1744 return value.
Or(std::move(fallback));
1756[[nodiscard]]
inline std::string
Or(
const Value& value,
const char* fallback) {
1757 return value.
Or(fallback);
1769template <
typename T>
1770[[nodiscard]] T
Or(
const Arg& arg, T fallback) {
1771 return arg.
Or(std::move(fallback));
1783[[nodiscard]]
inline std::string
Or(
const Arg& arg,
const char* fallback) {
1784 return arg.
Or(fallback);
1796template <
typename R,
typename T>
1797 requires std::is_same_v<std::remove_cvref_t<R>,
Result<Value>>
1798[[nodiscard]] T
Or(
const R& result, T fallback) {
1799 return result ? result.value().Or(std::move(fallback)) : fallback;
1811template <
typename R>
1812 requires std::is_same_v<std::remove_cvref_t<R>,
Result<Value>>
1813[[nodiscard]] std::string
Or(
const R& result,
const char* fallback) {
1814 return result ? result.value().Or(fallback) : std::string(fallback ? fallback :
"");
1829template <
typename T,
typename U>
1830 requires(!std::is_same_v<T, Value>)
1832 return result.value_or(std::forward<U>(fallback));
1856#pragma pop_macro("None")
struct C_JSContext * ULJSContext
Opaque handle to a JavaScript execution context (one page's script world in one View).
Definition View.h:25
Unicode string container with conversions for UTF-8, UTF-16, and UTF-32.
Definition String.h:31
An argument passed to a bound function.
Definition Value.h:1641
std::string Or(const char *fallback) const
Convert to a std::string like To() but with a string-literal fallback.
T Or(T fallback) const
Convert to a C++ type like To() but with a fallback.
bool IsEmpty() const
Whether or not the argument is absent (the call passed fewer arguments than the index given to CallIn...
Definition Value.h:1659
Result< T > To() const
Convert to a C++ type (see Value::To()).
std::optional< T > Maybe() const
Convert to a C++ type like To() but without the failure reason.
Type type() const
Get the argument's type (Type::Invalid if the argument is absent).
Definition Value.h:1664
Arg(ULJSValue borrowed)
Wrap a borrowed handle.
Definition Value.h:1650
Value ToValue() const
Get a Value that keeps the argument after the callback returns.
Definition Value.h:1708
ULJSValue raw() const
Get the C API handle.
Definition Value.h:1715
Handle to a JavaScript ArrayBuffer for sharing raw binary memory with the page.
Definition Buffer.h:88
An error from a JavaScript operation.
Definition Error.h:115
static Error AdoptException(ULJSValue exception)
Create an error from a JavaScript exception, taking ownership of the handle.
Definition Error.h:131
static Error TypeError(std::string message)
Create a native TypeError.
Definition Error.h:144
static Error PageGone()
Create a page-gone error (is_page_gone() returns true).
Definition Error.h:122
ULJSValue exception() const
Get the JavaScript exception (NULL if is_exception() is false).
Definition Error.h:268
Handle to a JavaScript typed array on a page.
Definition Buffer.h:203
A reference to a property of a Value (returned by Value::operator[]).
Definition Value.h:1419
Ref operator[](const char *name) const
Read this property and access a property of its value.
Definition Value.h:1463
Ref & operator=(const Ref &other)
Set this property to the value of another Ref's property.
Definition Value.h:1567
Ref(const Ref &)=default
Copy constructor (refers to the same property).
std::string Or(const char *fallback) const
Read the property and convert it to a std::string with a string-literal fallback.
Definition Value.h:1550
T Or(T fallback) const
Read the property and convert it to a C++ type with a fallback.
Ref & operator=(T &&value)
Set the property to value (converted through js::TypeTraits).
Value Get() const
Read the property.
Definition Value.h:1427
Result< R > Invoke(A &&... args) const
Call the property as a method of its object (otherwise the same as Value::Invoke()).
Result< Value > operator()(A &&... args) const
Call the property as a method: obj["save"](path) is the same as obj["save"].Invoke(path).
Definition Value.h:1513
Result< T > To() const
Read the property and convert it to a C++ type (see Value::To()).
Result< R > Construct(A &&... args) const
Read the property and call it as a constructor with new (otherwise the same as Value::Construct()).
friend class Context
Definition Value.h:1571
std::optional< T > Maybe() const
Read the property and convert it to a C++ type like To() but without the failure reason.
Ref operator[](I index) const
Definition Value.h:1468
friend class Value
Definition Value.h:1570
A handle to a live JavaScript value.
Definition Value.h:276
bool Has(const char *name) const
Whether or not this object has a property (own or inherited).
Definition Value.h:591
Ref operator[](const char *name) const
Access a property to read, assign, or call it.
Definition Value.h:1595
Value(Value &&other) noexcept
Move constructor (other becomes empty).
Definition Value.h:292
Value & operator=(Value other) noexcept
Assignment (copies or moves other into this Value).
Definition Value.h:297
std::string Or(const char *fallback) const
Convert to a std::string like To() but with a string-literal fallback.
static Value Adopt(ULJSValue handle)
Take ownership of a handle from the C API without adding a reference.
Definition Value.h:1242
bool IsCallable() const
Whether or not the value can be called (see Call() and Invoke()).
Definition Value.h:383
static Value FromBorrowed(ULJSValue handle)
Add a reference to a handle the library owns (eg, a callback argument) so it can outlive the callback...
Definition Value.h:1254
Result< double > ToNumber() const
Convert to a number using JavaScript's rules.
Definition Value.h:481
Result< std::string > ToString() const
Convert to a UTF-8 string using JavaScript's rules.
Definition Value.h:500
Result< void > Freeze() const
Freeze this object (like Object.freeze()), so no property can be added, removed, or changed afterward...
Definition Value.h:920
ULJSValue LeakRef()
Give up ownership of the C API handle and return it (like RefPtr::LeakRef()).
Definition Value.h:1270
T Or(T fallback) const
Convert to a C++ type like To() but with a fallback.
Result< bool > DeleteProperty(I index) const
Delete an element of this object by index (eg, arr.DeleteProperty(2)).
Definition Value.h:682
Value(const Value &other)
Copy constructor (adds a reference to the same JavaScript value).
Definition Value.h:286
Result< R > InvokeOn(const Value &this_value, A &&... args) const
Call this value as a function with an explicit this (otherwise the same as Invoke()).
Result< bool > HasProperty(const char *name) const
Whether or not this object has a property (like Has(), but reports failures).
Definition Value.h:604
Result< bool > DefineProperty(const char *name, const Value &value, PropertyAttributes attributes=PropertyAttributes::None) const
Define a data property of this object (like Reflect.defineProperty()).
Definition Value.h:857
bool Delete(I index) const
Delete an element of this object by index (like Delete(), but taking an index).
Definition Value.h:714
bool HasOwn(const char *name) const
Whether or not this object has an own property (one that isn't inherited, like Object....
Definition Value.h:730
bool StrictEquals(const Value &other) const
Whether or not this value and other are strictly equal (like JavaScript's ===).
Definition Value.h:435
bool IsNumber() const
Whether or not the value is a number.
Definition Value.h:356
Result< double > TimeValue() const
Get the time value of a Date, in milliseconds since the epoch (like date.getTime()).
Definition Value.h:450
Result< bool > ToBoolean() const
Convert to a boolean using JavaScript's rules (this never runs script).
Definition Value.h:466
Result< bool > HasOwnProperty(const char *name) const
Whether or not this object has an own property (like HasOwn(), but reports failures).
Definition Value.h:758
bool IsObject() const
Whether or not the value is an object.
Definition Value.h:373
bool IsPromise() const
Whether or not the value is a Promise.
Definition Value.h:398
Result< std::vector< std::string > > OwnKeys(OwnKeysFlags flags=OwnKeysFlags::None) const
Get the names of this object's own properties, without reading their values.
Definition Value.h:804
bool IsString() const
Whether or not the value is a string.
Definition Value.h:366
Result< bool > HasOwnProperty(I index) const
Whether or not this object has an own element at an index (like HasOwn(), but reports failures).
Definition Value.h:777
bool Then(F &&on_settled) const
Wait for this promise to settle and convert its value to a C++ type.
Definition Value.h:1187
bool IsEmpty() const
Whether or not this Value holds nothing (see "Handle States" above).
Definition Value.h:315
bool IsAlive() const
Whether or not this Value's page is still alive (the same test as operator bool).
Definition Value.h:323
bool Delete(const char *name) const
Delete a property of this object (like DeleteProperty(), but without the failure reason).
Definition Value.h:698
~Value()
Destructor (releases this handle).
Definition Value.h:305
Result< bool > DefineAccessor(const char *name, const Value &getter, const Value &setter, PropertyAttributes attributes=PropertyAttributes::None) const
Define an accessor property of this object, with a getter and a setter function (like Reflect....
Definition Value.h:896
Result< std::string > ToJSON(unsigned indent=0) const
Convert to JSON text like JSON.stringify() does.
Definition Value.h:540
Result< R > Invoke(A &&... args) const
Call this value as a function with typed arguments and result.
Result< Value > operator()(A &&... args) const
Call this value as a function: on_save(path) is the same as on_save.Invoke(path).
Definition Value.h:1119
bool IsConstructor() const
Whether or not the value can be called with new (see Construct()).
Definition Value.h:403
Result< Value > GetProperty(const char *name) const
Get a property of this object (own or inherited).
Definition Value.h:567
Result< T > To() const
Convert to a C++ type.
Result< R > Construct(A &&... args) const
Call this value as a constructor with new, with typed arguments and result.
Value(ULJSValue handle)
Definition Value.h:1277
bool IsNullish() const
Whether or not the value is null or undefined.
Definition Value.h:346
Value()
Create an empty Value.
Definition Value.h:281
Result< void > SetProperty(const char *name, const Value &value, PropertyAttributes attributes=PropertyAttributes::None) const
Set a property of this object.
Definition Value.h:632
bool IsBigInt() const
Whether or not the value is a BigInt (eg, 10n).
Definition Value.h:361
Result< Value > Construct(std::span< const Value > args) const
Call this value as a constructor with new, with the arguments in a range.
Definition Value.h:1102
bool IsNull() const
Whether or not the value is null.
Definition Value.h:341
bool IsBoolean() const
Whether or not the value is a boolean.
Definition Value.h:351
Result< Value > Call(const Value &this_value, std::span< const Value > args) const
Call this value as a function with the arguments in a range (eg, a std::vector<js::Value>).
Definition Value.h:964
ObjectKind object_kind() const
Get the kind of object the value is (eg, a Map, a Date, or an ordinary object).
Definition Value.h:420
std::optional< T > Maybe() const
Convert to a C++ type like To() but without the failure reason.
bool HasOwn(I index) const
Whether or not this object has an own element at an index (eg, arr.HasOwn(2) is false for a hole).
Definition Value.h:745
Type type() const
Get the type of the value.
Definition Value.h:331
Result< bool > DeleteProperty(const char *name) const
Delete a property of this object (like JavaScript's delete operator).
Definition Value.h:662
bool IsUndefined() const
Whether or not the value is undefined.
Definition Value.h:336
bool Then(F &&on_settled) const
Wait for this promise to settle without a coroutine.
Definition Value.h:1160
Result< Value > Call(const Value &this_value, const Value *args, size_t argc) const
Call this value as a function.
Definition Value.h:943
bool IsFunction() const
Whether or not the value is a function.
Definition Value.h:391
bool IsArray() const
Whether or not the value is an Array.
Definition Value.h:378
ULJSValue raw() const
Get the C API handle without transferring ownership.
Definition Value.h:1263
Definition StringSTL.h:166
Type-checked JavaScript bridge between C++ and web pages.
Definition JSInterop.h:141
constexpr UndefinedType undefined
The JavaScript undefined value.
Definition Value.h:59
T Or(const Value &value, T fallback)
Convert a value to a C++ type with a fallback (the free-function form of Value::Or()).
Definition Value.h:1743
Type
The type of a JavaScript value.
Definition Value.h:97
@ Symbol
Definition Value.h:104
@ String
Definition Value.h:103
@ Boolean
Definition Value.h:101
@ Object
Definition Value.h:106
@ Invalid
An empty Value, or one whose page is gone.
Definition Value.h:98
@ BigInt
Definition Value.h:105
@ Number
Definition Value.h:102
@ Null
Definition Value.h:100
@ Undefined
Definition Value.h:99
ObjectKind
The kind of a JavaScript object.
Definition Value.h:123
@ WeakSet
Definition Value.h:137
@ Array
Definition Value.h:127
@ Date
Definition Value.h:132
@ Map
Definition Value.h:134
@ Plain
An ordinary object (eg, {} or an instance of a JS class).
Definition Value.h:126
@ Set
Definition Value.h:135
@ WeakMap
Definition Value.h:136
@ Function
A callable object that isn't a Proxy (a native class constructor included, although Value::IsFunction...
Definition Value.h:130
@ DataView
Definition Value.h:142
@ Promise
Definition Value.h:138
@ RegExp
Definition Value.h:133
@ Proxy
A Proxy (callable or not).
Definition Value.h:131
constexpr NullType null
The JavaScript null value.
Definition Value.h:49
Value ExceptionValue(const Error &error)
Get the value a JavaScript exception threw, to keep it or pass it back to the page.
Definition Value.h:1849
constexpr AttachFlags operator|(AttachFlags a, AttachFlags b)
Combine attach flags.
Definition API.h:57
PropertyAttributes
Attribute flags for a property created by Value::SetProperty() or Value::DefineProperty().
Definition Value.h:74
@ DontDelete
The property can't be deleted.
Definition Value.h:78
@ ReadOnly
Script can't change its value.
Definition Value.h:76
@ DontEnum
Hidden from for...in and Object.keys.
Definition Value.h:77
@ None
No flags (a normal property).
Definition Value.h:75
OwnKeysFlags
Flags for Value::OwnKeys().
Definition Value.h:153
@ IncludeNonEnumerable
Non-enumerable keys too.
Definition Value.h:155
@ None
Enumerable keys only.
Definition Value.h:154
bool operator==(const Value &value, NullType)
Compare against the JavaScript null literal: if (v == js::null).
Definition Value.h:1617
Expected< T, Error > Result
The result of a JavaScript operation that can fail: a T or a js::Error.
Definition Error.h:520
Root namespace for every public Ultralight type, function, and enumeration.
@ Other
A focused element that is not a text-editing target (eg, a select).
Definition Editor.h:98
@ None
Definition Anchor.h:36
Tag type for the JavaScript null value (see js::null).
Definition Value.h:41
Type conversions between C++ and JavaScript across the bridge.
Definition TypeTraits.h:244
Tag type for the JavaScript undefined value (see js::undefined).
Definition Value.h:54