Skip to content

Commit

Permalink
noexcept
Browse files Browse the repository at this point in the history
  • Loading branch information
li-feng-sc committed Apr 3, 2024
1 parent 3d583f7 commit ee6e977
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 62 deletions.
22 changes: 11 additions & 11 deletions src/source/ComposerGenerator.scala
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ class ComposerGenerator(spec: Spec) extends Generator(spec) {
w.wl("static CppType toCpp(const ComposerType& v);")
w.wl("static ComposerType fromCpp(const CppType& c);")
w.wl
w.wl("static const Composer::ValueSchema& schema();")
w.wl("static const Composer::ValueSchema& schema() noexcept;")
}
}), (w => {}))
writeCppFileGeneric(spec.composerOutFolder.get, helperNamespace(), composerFilenameStyle, spec.composerIncludePrefix) (ident.name, origin, refs.cpp, (w => {
Expand All @@ -219,7 +219,7 @@ class ComposerGenerator(spec: Spec) extends Generator(spec) {
}
w.wl("return Value(o);")
}
w.w(s"const ValueSchema& $helper::schema()").braced {
w.w(s"const ValueSchema& $helper::schema() noexcept").braced {
//FIXME: _djinnin_record_namespace?
w.wl(s"""static auto schema = ValueSchema::cls(STRING_LITERAL("${schemaTypeNameForRecord(ident)}"), false,""").bracedEnd(");") {
for (f <- r.fields) {
Expand All @@ -246,9 +246,9 @@ class ComposerGenerator(spec: Spec) extends Generator(spec) {
val helper = helperClass(ident)
writeHppFileGeneric(spec.composerOutFolder.get, helperNamespace(), composerFilenameStyle)(ident.name, origin, refs.hpp, Nil, (w => {
w.w(s"struct $helper : ::djinni::composer::JsInterface<$cls, $helper>").bracedSemi {
w.wl("static void registerSchema(bool resolve);")
w.wl("static const Composer::ValueSchema& schemaRef();")
w.wl("static const Composer::ValueSchema& schema();")
w.wl("static void registerSchema(bool resolve) noexcept;")
w.wl("static const Composer::ValueSchema& schemaRef() noexcept;")
w.wl("static const Composer::ValueSchema& schema() noexcept;")

// cpp marshal helper
if (i.ext.cpp) {
Expand All @@ -273,7 +273,7 @@ class ComposerGenerator(spec: Spec) extends Generator(spec) {
//static methods
val staticMethods = i.methods.filter(m => m.static)
if (!staticMethods.isEmpty) {
w.wl("static void djinniInitStaticMethods(Composer::Ref<Composer::ValueMap> m);")
w.wl("static void djinniInitStaticMethods(Composer::Ref<Composer::ValueMap> m) noexcept;")
}

//TODO ???
Expand Down Expand Up @@ -327,7 +327,7 @@ class ComposerGenerator(spec: Spec) extends Generator(spec) {
}
}
//value schema
w.w(s"static const ValueSchema& unresolvedSchema()").braced {
w.w(s"static const ValueSchema& unresolvedSchema() noexcept").braced {
w.wl(s"static auto schema = ValueSchema::cls(schemaName(), true,").bracedEnd(");") {
for (m <- i.methods.filter(m => !m.static)) {
w.w(s"""ClassPropertySchema(STRING_LITERAL("${idJs.method(m.ident)}"), ValueSchema::function(${stubRetSchema(m)},""").bracedEnd(")),") {
Expand All @@ -339,7 +339,7 @@ class ComposerGenerator(spec: Spec) extends Generator(spec) {
}
w.wl("return schema;")
}
w.w(s"void $helper::registerSchema(bool resolve)").braced {
w.w(s"void $helper::registerSchema(bool resolve) noexcept").braced {
//register dependent interfaces (params and return that are interfaces but not this one)
for (t <- refs.interfaces.filter(t => t != withNs(Some(helperNamespace), helperClass(ident)))) {
w.wl(s"${t}::registerSchema(resolve);")
Expand All @@ -348,11 +348,11 @@ class ComposerGenerator(spec: Spec) extends Generator(spec) {
w.wl("if (std::exchange(flag[resolve ? 1 : 0], true) == false) { djinni::composer::registerSchemaImpl(unresolvedSchema(), resolve); }")
}
// type reference
w.w(s"const ValueSchema& $helper::schemaRef()").braced {
w.w(s"const ValueSchema& $helper::schemaRef() noexcept").braced {
w.wl("static auto ref = ValueSchema::typeReference(ValueSchemaTypeReference::named(schemaName()));")
w.wl("return ref;")
}
w.w(s"const ValueSchema& $helper::schema()").braced {
w.w(s"const ValueSchema& $helper::schema() noexcept").braced {
w.wl(s"static auto schema = djinni::composer::getResolvedSchema<$helper>(schemaName());")
w.wl("return schema;")
}
Expand Down Expand Up @@ -385,7 +385,7 @@ class ComposerGenerator(spec: Spec) extends Generator(spec) {
val staticMethods = i.methods.filter(m => m.static && m.lang.js)
if (!staticMethods.isEmpty) {
// object for static methods
w.wl(s"void ${helper}::djinniInitStaticMethods(Ref<ValueMap> m)").braced {
w.wl(s"void ${helper}::djinniInitStaticMethods(Ref<ValueMap> m) noexcept").braced {
w.wl(s"""auto unresolvedStaticSchema = ValueSchema::cls(STRING_LITERAL("${schemaTypeNameForStaticInterface(ident)}"), false,""").bracedEnd(");") {
for (m <- staticMethods) {
w.w(s"""ClassPropertySchema(STRING_LITERAL("${idJs.method(m.ident)}"), ValueSchema::function(${stubRetSchema(m)},""").bracedEnd(")),") {
Expand Down
4 changes: 2 additions & 2 deletions support-lib/composer/Future_composer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,14 +78,14 @@ class FutureAdaptor

template<typename U>
struct ExceptionHandlingTraits<FutureAdaptor<U>> {
static Composer::Value handleNativeException(const std::exception& e, const Composer::ValueFunctionCallContext& callContext) {
static Composer::Value handleNativeException(const std::exception& e, const Composer::ValueFunctionCallContext& callContext) noexcept {
// store C++ exception in JS Error and raise in JS runtime
auto msg = STRING_FORMAT("C++: {}", e.what());
auto composerPromise = Composer::makeShared<Composer::ResolvablePromise>();
composerPromise->fulfill(Composer::Result<Composer::Value>(Composer::Error(std::move(msg))));
return Composer::Value(composerPromise);
}
static Composer::Value handleNativeException(const JsException& e, const Composer::ValueFunctionCallContext& callContext) {
static Composer::Value handleNativeException(const JsException& e, const Composer::ValueFunctionCallContext& callContext) noexcept {
// JS error passthrough
auto composerPromise = Composer::makeShared<Composer::ResolvablePromise>();
composerPromise->fulfill(Composer::Result<Composer::Value>(e.cause()));
Expand Down
16 changes: 8 additions & 8 deletions support-lib/composer/djinni_composer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,15 @@ void checkForNull(void* ptr, const char* context) {
}
}

ValueSchema resolveSchema(const ValueSchema& unresolved, std::function<void()> registerSchemaFunc) {
ValueSchema resolveSchema(const ValueSchema& unresolved, std::function<void()> registerSchemaFunc) noexcept {
registerSchemaFunc();
Composer::ValueSchemaTypeResolver resolver(Composer::ValueSchemaRegistry::sharedInstance().get());
auto result = resolver.resolveTypeReferences(unresolved);
result.ensureSuccess();
return result.moveValue();
}

void registerSchemaImpl(const ValueSchema& schema, bool resolve) {
void registerSchemaImpl(const ValueSchema& schema, bool resolve) noexcept {
auto registry = ValueSchemaRegistry::sharedInstance();
if (!resolve) {
registry->registerSchema(schema);
Expand All @@ -54,35 +54,35 @@ void registerSchemaImpl(const ValueSchema& schema, bool resolve) {
}
}

Binary::CppType Binary::toCpp(const Binary::ComposerType& v) {
Binary::CppType Binary::toCpp(const Binary::ComposerType& v) noexcept {
auto a = v.getTypedArrayRef();
auto buffer = a->getBuffer();
return CppType(buffer.begin(), buffer.end());
}

Binary::ComposerType Binary::fromCpp(const Binary::CppType& c) {
Binary::ComposerType Binary::fromCpp(const Binary::CppType& c) noexcept {
auto bytes = makeShared<Bytes>();
bytes->assignData(c.data(), c.size());
auto va = makeShared<ValueTypedArray>(TypedArrayType::Uint8Array, bytes);
return Value(va);
}

const ValueSchema& Binary::schema() {
const ValueSchema& Binary::schema() noexcept {
static auto schema = ValueSchema::valueTypedArray();
return schema;
}

Date::CppType Date::toCpp(const Date::ComposerType& v) {
Date::CppType Date::toCpp(const Date::ComposerType& v) noexcept {
auto millisecondsSinceEpoch = std::chrono::milliseconds(static_cast<int64_t>(v.toDouble()));
return CppType(std::chrono::duration_cast<std::chrono::system_clock::duration>(millisecondsSinceEpoch));
}

Date::ComposerType Date::fromCpp(const Date::CppType& c) {
Date::ComposerType Date::fromCpp(const Date::CppType& c) noexcept {
auto millisecondsSinceEpoch = std::chrono::duration_cast<std::chrono::milliseconds>(c.time_since_epoch());
return Composer::Value(static_cast<double>(millisecondsSinceEpoch.count()));
}

const ValueSchema& Date::schema() {
const ValueSchema& Date::schema() noexcept {
static auto schema = ValueSchema::date();
return schema;
}
Expand Down
Loading

0 comments on commit ee6e977

Please sign in to comment.