PropertyDescriptor.cpp (3352B)
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- 2 * vim: set ts=8 sts=2 et sw=2 tw=80: 3 * This Source Code Form is subject to the terms of the Mozilla Public 4 * License, v. 2.0. If a copy of the MPL was not distributed with this 5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 6 7 #include "js/PropertyDescriptor.h" 8 9 #include "mozilla/Maybe.h" // mozilla::Maybe 10 11 #include <stddef.h> // size_t 12 #include <string.h> // strlen 13 14 #include "jstypes.h" // JS_PUBLIC_API 15 #include "js/Context.h" // js::AssertHeapIsIdle 16 #include "js/Id.h" // jsid 17 #include "js/RootingAPI.h" // JS::Rooted, JS::Handle, JS::MutableHandle 18 #include "vm/JSAtomUtils.h" // Atomize, AtomizeChars 19 #include "vm/JSContext.h" // JSContext, CHECK_THREAD 20 #include "vm/JSObject.h" // JSObject 21 #include "vm/ObjectOperations.h" // GetOwnPropertyDescriptor 22 #include "vm/StringType.h" // JSAtom 23 24 #include "vm/JSAtomUtils-inl.h" // AtomToId 25 #include "vm/JSContext-inl.h" // JSContext::check 26 27 using namespace js; 28 29 JS_PUBLIC_API bool JS_GetOwnPropertyDescriptorById( 30 JSContext* cx, JS::Handle<JSObject*> obj, JS::Handle<jsid> id, 31 JS::MutableHandle<mozilla::Maybe<JS::PropertyDescriptor>> desc) { 32 AssertHeapIsIdle(); 33 CHECK_THREAD(cx); 34 cx->check(obj, id); 35 return GetOwnPropertyDescriptor(cx, obj, id, desc); 36 } 37 38 JS_PUBLIC_API bool JS_GetOwnPropertyDescriptor( 39 JSContext* cx, JS::Handle<JSObject*> obj, const char* name, 40 JS::MutableHandle<mozilla::Maybe<JS::PropertyDescriptor>> desc) { 41 JSAtom* atom = Atomize(cx, name, strlen(name)); 42 if (!atom) { 43 return false; 44 } 45 JS::Rooted<jsid> id(cx, AtomToId(atom)); 46 return JS_GetOwnPropertyDescriptorById(cx, obj, id, desc); 47 } 48 49 JS_PUBLIC_API bool JS_GetOwnUCPropertyDescriptor( 50 JSContext* cx, JS::Handle<JSObject*> obj, const char16_t* name, 51 size_t namelen, 52 JS::MutableHandle<mozilla::Maybe<JS::PropertyDescriptor>> desc) { 53 JSAtom* atom = AtomizeChars(cx, name, namelen); 54 if (!atom) { 55 return false; 56 } 57 JS::Rooted<jsid> id(cx, AtomToId(atom)); 58 return JS_GetOwnPropertyDescriptorById(cx, obj, id, desc); 59 } 60 61 JS_PUBLIC_API bool JS_GetPropertyDescriptorById( 62 JSContext* cx, JS::Handle<JSObject*> obj, JS::Handle<jsid> id, 63 JS::MutableHandle<mozilla::Maybe<JS::PropertyDescriptor>> desc, 64 JS::MutableHandle<JSObject*> holder) { 65 cx->check(obj, id); 66 return GetPropertyDescriptor(cx, obj, id, desc, holder); 67 } 68 69 JS_PUBLIC_API bool JS_GetPropertyDescriptor( 70 JSContext* cx, JS::Handle<JSObject*> obj, const char* name, 71 JS::MutableHandle<mozilla::Maybe<JS::PropertyDescriptor>> desc, 72 JS::MutableHandle<JSObject*> holder) { 73 JSAtom* atom = Atomize(cx, name, strlen(name)); 74 if (!atom) { 75 return false; 76 } 77 JS::Rooted<jsid> id(cx, AtomToId(atom)); 78 return JS_GetPropertyDescriptorById(cx, obj, id, desc, holder); 79 } 80 81 JS_PUBLIC_API bool JS_GetUCPropertyDescriptor( 82 JSContext* cx, JS::Handle<JSObject*> obj, const char16_t* name, 83 size_t namelen, 84 JS::MutableHandle<mozilla::Maybe<JS::PropertyDescriptor>> desc, 85 JS::MutableHandle<JSObject*> holder) { 86 JSAtom* atom = AtomizeChars(cx, name, namelen); 87 if (!atom) { 88 return false; 89 } 90 JS::Rooted<jsid> id(cx, AtomToId(atom)); 91 return JS_GetPropertyDescriptorById(cx, obj, id, desc, holder); 92 }