Comments (4)
Thanks for the suggestion @kuoruan
I agree that the use of the work Context
is conflicting, but I guess that is why we have package scopes in Go.
One of the goals of the project is to keep the API as close to the C++ API as possible; so would be inclined to keep the idea of the v8 Context.
That said, there is a second part to the goals that state: "idiomatic Go"; which context.Context
is very much part of; which makes it a conflicting argument 🤔
Once we get closer to a stable API, I'll definitely look at how we can incorporate context.Context
; it would definitely be of benefit, especially for some of the callback logic.
from v8go.
+1 on integrating context.Context
.
from v8go.
I don't think it makes sense to hide the v8 context, since it has a broader purpose than context.Context.
Also, I think supporting the full context capabilities internally to v8go would effectively mean starting a goroutine in order to be able to handle a cancel event. If that needs to be added on each v8go call that could invoke JS execution, then that could be a lot of starting and stopping of goroutines.
Note that JS execution can happen in a lot more APIs than just running scripts. For instance, even the value casting functions could trigger JS execution. E.g. v8::Value::ToString could call the Symbol.toPrimitive method). It would add a lot of API surface to provide alternative versions of all of these methods to handle a context.
An alternative would be to just support setting and clearing deadline, which could be done using separate methods. This would also be cheaper, since it could just be done using a timer created using time.AfterFunc
, which could be stopped or reset when the deadline is cleared or set a following time. If unused, the field could just be left nil
. However, unlike TerminateExecution, we would probably want to prevent further JS execution using a boolean flag, in case TerminateExecution gets called outside of the JS code (e.g. between setting the deadline and starting JS execution or between calls that trigger JS execution).
The other thing to note is that forcing JS execution at an arbitrary point in the JS code can leave the V8 context is an unreliable state. For instance, if the JS code sets some global variable and tries to reset it in a finally block, then I think that finally block code could end up being skipped. It may be worth considering whether the feature will be supporting an anti-pattern over starting with a more graceful timeout mechanism and only using a more forceful timeout after a delay. Nothing new is needed for either approach, so anything added would just be making some approach(es) more convenient.
from v8go.
I don't think it makes sense to hide the v8 context, since it has a broader purpose than context.Context.
But v8 context could be combined with context.Context, no? So v8.NewContext
maybe should get context.Context
as a parameter?
I think supporting the full context capabilities internally to v8go would effectively mean starting a goroutine in order to be able to handle a cancel event.
Only if the context.Context
provided is a canceling context. If the caller passes such context.Context
to v8.NewContext
, then they want this behavior. Now, or they have to implement this outside of v8go, or v8go provides this feature out of the box.
from v8go.
Related Issues (20)
- Support More Than Just Primitives in ObjectTemplate.Set
- undefined: v8.NewContext HOT 2
- Golang Docker Build with v0.9.0 HOT 4
- vulnerable to CVE-2023-3079?
- `iso.TerminateExecution()` doesn't work
- How to debug the script
- How to properly build go binary that uses v8go inside docker?
- Using profiles to track allocation and release of objects
- undefined symbol: __libc_single_threaded HOT 1
- [Bug] Promise stays in infinite "pending" state HOT 1
- unable to add toString method to object
- SetAccesor method?
- OOM after multiple calls (mac air M1) (go1.21.4 darwin/arm64) HOT 1
- v0.9.0 not work on x86_64 linux
- Upgrade v8 action not finding runners (deprecated ubuntu-18.04) HOT 1
- Isolate dispose cause the memory leak
- signal: bus error on Mac
- Building on Windows
- Exactly what kinds of access to v8go must be serialized from the caller
- Using MarshallJSON() on objects yields strange results
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from v8go.