Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Added Object::New() taking a list of properties. #628

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions doc/object.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,33 @@ Napi::Object Napi::Object::New(napi_env env);

Creates a new `Napi::Object` value.

### New()

```cpp
Napi::Object Napi::Object::New(napi_env env,
const std::initializer_list<PropertyDescriptor> &properties);
```

- `[in] env`: The `napi_env` environment in which to construct the `Napi::Value` object.
- `[in] properties`: Initializer list of `Napi::PropertyDescriptor` describing
properties for the object. See: [Property and descriptor](property_descriptor.md).

Creates a new `Napi::Object` value.

### New()

```cpp
Napi::Object Napi::Object::New(napi_env env,
const std::vector<PropertyDescriptor> &properties);
```

- `[in] env`: The `napi_env` environment in which to construct the `Napi::Value` object.
- `[in] properties`: Vector of `Napi::PropertyDescriptor` describing properties
for the object. See: [Property and descriptor](property_descriptor.md).

Creates a new `Napi::Object` value.


### Set()

```cpp
Expand Down
12 changes: 12 additions & 0 deletions napi-inl.h
Original file line number Diff line number Diff line change
Expand Up @@ -971,6 +971,18 @@ inline Object Object::New(napi_env env) {
return Object(env, value);
}

inline Object Object::New(napi_env env, const std::initializer_list<PropertyDescriptor> &properties) {
Object obj = Object::New(env);
obj.DefineProperties(properties);
return obj;
}

inline Object Object::New(napi_env env, const std::vector<PropertyDescriptor> &properties) {
Object obj = Object::New(env);
obj.DefineProperties(properties);
return obj;
}

inline Object::Object() : Value() {
}

Expand Down
10 changes: 10 additions & 0 deletions napi.h
Original file line number Diff line number Diff line change
Expand Up @@ -526,6 +526,16 @@ namespace Napi {
napi_env env ///< N-API environment
);

static Object New(
napi_env env, ///< N-API environment
const std::initializer_list<PropertyDescriptor> &properties ///< initial prperties
);

static Object New(
napi_env env, ///< N-API environment
const std::vector<PropertyDescriptor> &properties ///< initial prperties
);

Object(); ///< Creates a new _empty_ Object instance.
Object(napi_env env, napi_value value); ///< Wraps a N-API value primitive.

Expand Down