Skip to content

Feat/ergonomics 2.0 #65

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

Merged
merged 6 commits into from
Apr 2, 2025
Merged
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
2 changes: 1 addition & 1 deletion bridge/jsb_bridge_helper.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ namespace jsb
const v8::Local<v8::Object> enumeration = v8::Object::New(isolate);
for (const KeyValue<StringName, int64_t>& kv : enum_values)
{
const v8::Local<v8::String> name = impl::Helper::new_string(isolate, kv.key);
const v8::Local<v8::String> name = impl::Helper::new_string(isolate, internal::NamingUtil::get_enum_value_name(kv.key));
const v8::Local<v8::Value> value = impl::Helper::new_integer(isolate, kv.value);
enumeration->Set(context, name, value).Check();
// represents the value back to string for convenient uses, such as MyColor[MyColor.White] => 'White'
Expand Down
37 changes: 21 additions & 16 deletions bridge/jsb_bridge_module_loader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -305,24 +305,27 @@ namespace jsb
v8::Local<v8::Object> target = info[0].As<v8::Object>();
v8::Local<v8::Object> details = info[1].As<v8::Object>();

jsb_check(target->IsObject());
jsb_check(details->IsObject());

Environment* environment = Environment::wrap(isolate);
v8::Local<v8::Symbol> symbol = jsb_symbol(environment, ClassProperties);
v8::Local<v8::Array> collection;
v8::Local<v8::Value> val_test;
uint32_t index;
if (v8::MaybeLocal<v8::Value> maybe = target->Get(context, symbol); !maybe.ToLocal(&val_test) || val_test->IsUndefined())
if (target->HasOwnProperty(context, symbol).ToChecked())
{
v8::Local<v8::Value> collection_val = target->Get(context, symbol).ToLocalChecked();
jsb_check(collection_val->IsArray());
collection = collection_val.As<v8::Array>();
index = collection->Length();
}
else
{
index = 0;
collection = v8::Array::New(isolate);
jsb_quickjs_check(collection->IsArray());
target->Set(context, symbol, collection).Check();
}
else
{
jsb_check(val_test->IsArray());
collection = val_test.As<v8::Array>();
index = collection->Length();
}

collection->Set(context, index, details).Check();
JSB_LOG(VeryVerbose, "script %s define property(export) %s",
Expand Down Expand Up @@ -403,19 +406,20 @@ namespace jsb
Environment* environment = Environment::wrap(isolate);
v8::Local<v8::Symbol> symbol = jsb_symbol(environment, ClassSignals);
v8::Local<v8::Array> collection;
v8::Local<v8::Value> val_test;
uint32_t index;
if (v8::MaybeLocal<v8::Value> maybe = target->Get(context, symbol); !maybe.ToLocal(&val_test) || val_test->IsUndefined())
if (target->HasOwnProperty(context, symbol).ToChecked())
{
index = 0;
collection = v8::Array::New(isolate);
target->Set(context, symbol, collection).Check();
v8::Local<v8::Value> collection_val = target->Get(context, symbol).ToLocalChecked();
jsb_check(collection_val->IsArray());
collection = collection_val.As<v8::Array>();
index = collection->Length();
}
else
{
jsb_check(val_test->IsArray());
collection = val_test.As<v8::Array>();
index = collection->Length();
index = 0;
collection = v8::Array::New(isolate);
jsb_quickjs_check(collection->IsArray());
target->Set(context, symbol, collection).Check();
}

collection->Set(context, index, signal).Check();
Expand Down Expand Up @@ -452,6 +456,7 @@ namespace jsb
#else
jsb_obj->Set(context, impl::Helper::new_string_ascii(isolate, "DEBUG_ENABLED"), v8::Boolean::New(isolate, false)).Check();
#endif
jsb_obj->Set(context, impl::Helper::new_string_ascii(isolate, "CAMEL_CASE_BINDINGS_ENABLED"), v8::Boolean::New(isolate, internal::Settings::get_camel_case_bindings_enabled())).Check();
jsb_obj->Set(context, impl::Helper::new_string_ascii(isolate, "version"), impl::Helper::new_string(isolate, JSB_STRINGIFY(JSB_MAJOR_VERSION) "." JSB_STRINGIFY(JSB_MINOR_VERSION) "." JSB_STRINGIFY(JSB_PATCH_VERSION))).Check();
jsb_obj->Set(context, impl::Helper::new_string_ascii(isolate, "impl"), impl::Helper::new_string(isolate, JSB_IMPL_VERSION_STRING)).Check();
jsb_obj->Set(context, impl::Helper::new_string_ascii(isolate, "callable"), JSB_NEW_FUNCTION(context, _new_callable, {})).Check();
Expand Down
3 changes: 0 additions & 3 deletions bridge/jsb_class_info.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,6 @@ namespace jsb
// signals (@signal_)
{
v8::Local<v8::Value> val_test;
//TODO does prototype chain introduce unexpected behaviour if signal is decalred in super class?
if (prototype->Get(p_context, jsb_symbol(environment, ClassSignals)).ToLocal(&val_test) && val_test->IsArray())
{
v8::Local<v8::Array> collection = val_test.As<v8::Array>();
Expand All @@ -205,9 +204,7 @@ namespace jsb
// detect all exported properties (which annotated with @export_)
{
v8::Local<v8::Value> val_test;
//TODO does prototype chain introduce unexpected behaviour if signal is decalred in super class?
if (prototype->Get(p_context, jsb_symbol(environment, ClassProperties)).ToLocal(&val_test) && val_test->IsArray())
// if (prototype->Get(p_context, jsb_symbol(environment, ClassProperties)).ToLocal(&val_test) && val_test->IsArray())
{
const v8::Local<v8::Array> collection = val_test.As<v8::Array>();
const uint32_t len = collection->Length();
Expand Down
Loading