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

Add plumbing for SetEnv workaround #116

Merged
merged 5 commits into from
Jul 25, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
17 changes: 17 additions & 0 deletions src/asherah.cc
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ class Asherah : public Napi::Addon<Asherah> {
&Asherah::SetSafetyPaddingOverhead),
InstanceMethod("get_setup_status", &Asherah::GetSetupStatus),
InstanceMethod("set_log_hook", &Asherah::SetLogHook),
InstanceMethod("setenv", &Asherah::SetEnv),
});
}

Expand Down Expand Up @@ -409,6 +410,22 @@ class Asherah : public Napi::Addon<Asherah> {
}
}

void SetEnv(const Napi::CallbackInfo &info) {
Napi::Env env = info.Env();
Napi::HandleScope scope(env);
try {
NapiUtils::RequireParameterCount(info, 1);
CobhanBufferNapi env_json(env, info[0]);
::SetEnv(env_json);
} catch (Napi::Error &e) {
e.ThrowAsJavaScriptException();
return;
} catch (const std::exception &e) {
Napi::Error::New(env, e.what()).ThrowAsJavaScriptException();
return;
}
}

void SetMaxStackAllocItemSize(const Napi::CallbackInfo &info) {
Napi::Env env = info.Env();
Napi::HandleScope scope(env);
Expand Down
1 change: 1 addition & 0 deletions src/asherah.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,3 +60,4 @@ export declare function set_max_stack_alloc_item_size(max_item_size: number): vo
export declare function set_safety_padding_overhead(safety_padding_overhead: number): void;
export declare function set_log_hook(logHook: LogHookCallback): void;
export declare function get_setup_status(): boolean;
export declare function setenv(environment: string): void;
8 changes: 7 additions & 1 deletion test/asherah.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ import {
shutdown_async,
get_setup_status,
set_max_stack_alloc_item_size,
set_log_hook
set_log_hook,
setenv
} from '../dist/asherah'

import { assert } from 'chai';
Expand Down Expand Up @@ -92,6 +93,11 @@ export async function asherah_setup_static_memory_async(verbose = false, session
}
}

export async function asherah_set_env(): Promise<void> {
const myString = '{"VAR": "VAL"}';
setenv(myString);
}

export function asherah_shutdown(): void {
shutdown();
}
Expand Down
Loading