From 0ebf5bdf043a27fd3dfb7f92e0cb63d88954c44d Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Fri, 19 Apr 2024 03:47:29 +0200 Subject: Adding upstream version 115.8.0esr. Signed-off-by: Daniel Baumann --- js/src/vm/PropertyDescriptor.cpp | 91 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 91 insertions(+) create mode 100644 js/src/vm/PropertyDescriptor.cpp (limited to 'js/src/vm/PropertyDescriptor.cpp') diff --git a/js/src/vm/PropertyDescriptor.cpp b/js/src/vm/PropertyDescriptor.cpp new file mode 100644 index 0000000000..ca5ebbb7b1 --- /dev/null +++ b/js/src/vm/PropertyDescriptor.cpp @@ -0,0 +1,91 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- + * vim: set ts=8 sts=2 et sw=2 tw=80: + * 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/. */ + +#include "js/PropertyDescriptor.h" + +#include "mozilla/Maybe.h" // mozilla::Maybe + +#include // size_t +#include // strlen + +#include "jstypes.h" // JS_PUBLIC_API +#include "js/Context.h" // js::AssertHeapIsIdle +#include "js/Id.h" // jsid +#include "js/RootingAPI.h" // JS::Rooted, JS::Handle, JS::MutableHandle +#include "vm/JSAtom.h" // JSAtom, Atomize, AtomizeChars +#include "vm/JSContext.h" // JSContext, CHECK_THREAD +#include "vm/JSObject.h" // JSObject +#include "vm/ObjectOperations.h" // GetOwnPropertyDescriptor + +#include "vm/JSAtom-inl.h" // AtomToId +#include "vm/JSContext-inl.h" // JSContext::check + +using namespace js; + +JS_PUBLIC_API bool JS_GetOwnPropertyDescriptorById( + JSContext* cx, JS::Handle obj, JS::Handle id, + JS::MutableHandle> desc) { + AssertHeapIsIdle(); + CHECK_THREAD(cx); + cx->check(obj, id); + return GetOwnPropertyDescriptor(cx, obj, id, desc); +} + +JS_PUBLIC_API bool JS_GetOwnPropertyDescriptor( + JSContext* cx, JS::Handle obj, const char* name, + JS::MutableHandle> desc) { + JSAtom* atom = Atomize(cx, name, strlen(name)); + if (!atom) { + return false; + } + JS::Rooted id(cx, AtomToId(atom)); + return JS_GetOwnPropertyDescriptorById(cx, obj, id, desc); +} + +JS_PUBLIC_API bool JS_GetOwnUCPropertyDescriptor( + JSContext* cx, JS::Handle obj, const char16_t* name, + size_t namelen, + JS::MutableHandle> desc) { + JSAtom* atom = AtomizeChars(cx, name, namelen); + if (!atom) { + return false; + } + JS::Rooted id(cx, AtomToId(atom)); + return JS_GetOwnPropertyDescriptorById(cx, obj, id, desc); +} + +JS_PUBLIC_API bool JS_GetPropertyDescriptorById( + JSContext* cx, JS::Handle obj, JS::Handle id, + JS::MutableHandle> desc, + JS::MutableHandle holder) { + cx->check(obj, id); + return GetPropertyDescriptor(cx, obj, id, desc, holder); +} + +JS_PUBLIC_API bool JS_GetPropertyDescriptor( + JSContext* cx, JS::Handle obj, const char* name, + JS::MutableHandle> desc, + JS::MutableHandle holder) { + JSAtom* atom = Atomize(cx, name, strlen(name)); + if (!atom) { + return false; + } + JS::Rooted id(cx, AtomToId(atom)); + return JS_GetPropertyDescriptorById(cx, obj, id, desc, holder); +} + +JS_PUBLIC_API bool JS_GetUCPropertyDescriptor( + JSContext* cx, JS::Handle obj, const char16_t* name, + size_t namelen, + JS::MutableHandle> desc, + JS::MutableHandle holder) { + JSAtom* atom = AtomizeChars(cx, name, namelen); + if (!atom) { + return false; + } + JS::Rooted id(cx, AtomToId(atom)); + return JS_GetPropertyDescriptorById(cx, obj, id, desc, holder); +} -- cgit v1.2.3