summaryrefslogtreecommitdiffstats
path: root/js/src/vm/PropertyDescriptor.cpp
blob: ca5ebbb7b1ee7a1851a278794b643a1dcf400fce (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
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 <stddef.h>  // size_t
#include <string.h>  // 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<JSObject*> obj, JS::Handle<jsid> id,
    JS::MutableHandle<mozilla::Maybe<JS::PropertyDescriptor>> 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<JSObject*> obj, const char* name,
    JS::MutableHandle<mozilla::Maybe<JS::PropertyDescriptor>> desc) {
  JSAtom* atom = Atomize(cx, name, strlen(name));
  if (!atom) {
    return false;
  }
  JS::Rooted<jsid> id(cx, AtomToId(atom));
  return JS_GetOwnPropertyDescriptorById(cx, obj, id, desc);
}

JS_PUBLIC_API bool JS_GetOwnUCPropertyDescriptor(
    JSContext* cx, JS::Handle<JSObject*> obj, const char16_t* name,
    size_t namelen,
    JS::MutableHandle<mozilla::Maybe<JS::PropertyDescriptor>> desc) {
  JSAtom* atom = AtomizeChars(cx, name, namelen);
  if (!atom) {
    return false;
  }
  JS::Rooted<jsid> id(cx, AtomToId(atom));
  return JS_GetOwnPropertyDescriptorById(cx, obj, id, desc);
}

JS_PUBLIC_API bool JS_GetPropertyDescriptorById(
    JSContext* cx, JS::Handle<JSObject*> obj, JS::Handle<jsid> id,
    JS::MutableHandle<mozilla::Maybe<JS::PropertyDescriptor>> desc,
    JS::MutableHandle<JSObject*> holder) {
  cx->check(obj, id);
  return GetPropertyDescriptor(cx, obj, id, desc, holder);
}

JS_PUBLIC_API bool JS_GetPropertyDescriptor(
    JSContext* cx, JS::Handle<JSObject*> obj, const char* name,
    JS::MutableHandle<mozilla::Maybe<JS::PropertyDescriptor>> desc,
    JS::MutableHandle<JSObject*> holder) {
  JSAtom* atom = Atomize(cx, name, strlen(name));
  if (!atom) {
    return false;
  }
  JS::Rooted<jsid> id(cx, AtomToId(atom));
  return JS_GetPropertyDescriptorById(cx, obj, id, desc, holder);
}

JS_PUBLIC_API bool JS_GetUCPropertyDescriptor(
    JSContext* cx, JS::Handle<JSObject*> obj, const char16_t* name,
    size_t namelen,
    JS::MutableHandle<mozilla::Maybe<JS::PropertyDescriptor>> desc,
    JS::MutableHandle<JSObject*> holder) {
  JSAtom* atom = AtomizeChars(cx, name, namelen);
  if (!atom) {
    return false;
  }
  JS::Rooted<jsid> id(cx, AtomToId(atom));
  return JS_GetPropertyDescriptorById(cx, obj, id, desc, holder);
}