| 105 | } |
| 106 | |
| 107 | napi_status ExtendClass(napi_env env, napi_value constructor, const std::string& parentName) { |
| 108 | if (env == nullptr || constructor == nullptr || parentName.empty()) { |
| 109 | return napi_status::napi_invalid_arg; |
| 110 | } |
| 111 | napi_value baseConstructor = GetConstructor(env, parentName); |
| 112 | if (baseConstructor == nullptr) { |
| 113 | LOGE("ExtendClass get baseConstructor failed status"); |
| 114 | return napi_status::napi_invalid_arg; |
| 115 | } |
| 116 | napi_value basePrototype; |
| 117 | napi_status statusCode = |
| 118 | napi_get_named_property(env, baseConstructor, "prototype", &basePrototype); |
| 119 | if (statusCode != napi_status::napi_ok) { |
| 120 | LOGE("ExtendClass get baseConstructor's prototype failed status :%d", statusCode); |
| 121 | return statusCode; |
| 122 | } |
| 123 | napi_value derivedPrototype; |
| 124 | statusCode = napi_get_named_property(env, constructor, "prototype", &derivedPrototype); |
| 125 | if (statusCode != napi_status::napi_ok) { |
| 126 | LOGE("ExtendClass get constructor's prototype failed status :%d", statusCode); |
| 127 | return statusCode; |
| 128 | } |
| 129 | return napi_set_named_property(env, derivedPrototype, "__proto__", basePrototype); |
| 130 | } |
| 131 | |
| 132 | napi_status DefineClass(napi_env env, napi_value exports, const std::string& utf8name, |
| 133 | size_t propertyCount, const napi_property_descriptor* properties, |
no test coverage detected