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 the ThrowException fn to the isolate #221

Merged
merged 10 commits into from
Nov 10, 2021
Next Next commit
Add the ThrowException fn to the isolate
  • Loading branch information
wisepythagoras committed Oct 31, 2021
commit e5e72d459adb2c151f23e7c6ccd9796757ddb835
7 changes: 7 additions & 0 deletions isolate.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,13 @@ func (i *Isolate) Dispose() {
i.ptr = nil
}

// ThrowException will schedule for an exception to be thrown.
wisepythagoras marked this conversation as resolved.
Show resolved Hide resolved
func (i *Isolate) ThrowException(value *Value) *Value {
return &Value{
ptr: C.ThrowException(value.ptr),
}
}

// Deprecated: use `iso.Dispose()`.
func (i *Isolate) Close() {
i.Dispose()
Expand Down
19 changes: 19 additions & 0 deletions v8go.cc
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,25 @@ IsolateHStatistics IsolationGetHeapStatistics(IsolatePtr iso) {
hs.number_of_detached_contexts()};
}

/********** Exceptions & Errors **********/

ValuePtr ThrowException(ValuePtr value) {
Isolate* iso = value->iso;
m_ctx* ctx = value->ctx;
wisepythagoras marked this conversation as resolved.
Show resolved Hide resolved

ISOLATE_SCOPE(iso);

Local<Value> throw_ret_val = iso->ThrowException(value->ptr.Get(iso));

m_value* new_val = new m_value;
new_val->iso = iso;
new_val->ctx = ctx;
new_val->ptr = Persistent<Value, CopyablePersistentTraits<Value>>(
iso, throw_ret_val);

return tracked_value(ctx, new_val);
}

/********** CpuProfiler **********/

CPUProfiler* NewCPUProfiler(IsolatePtr iso_ptr) {
Expand Down
2 changes: 2 additions & 0 deletions v8go.h
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,8 @@ extern void IsolateTerminateExecution(IsolatePtr ptr);
extern int IsolateIsExecutionTerminating(IsolatePtr ptr);
extern IsolateHStatistics IsolationGetHeapStatistics(IsolatePtr ptr);

extern ValuePtr ThrowException(ValuePtr value);

extern CPUProfiler* NewCPUProfiler(IsolatePtr iso_ptr);
extern void CPUProfilerDispose(CPUProfiler* ptr);
extern void CPUProfilerStartProfiling(CPUProfiler* ptr, const char* title);
Expand Down