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

[STAL-1960] Implement ddsa Violation bridge #392

Merged
merged 2 commits into from
Jun 7, 2024
Merged

Conversation

jasonforal
Copy link
Collaborator

What problem are you trying to solve?

JavaScript rules need to report violations back to the Rust static-analysis-kernel.

What is your solution?

This PR is small, and implements the bridge that will be used to pass Violation objects from JavaScript to Rust. We do this by passing them indirectly through a pre-allocated global v8::Array:

Flow

  1. ddsa runtime exposes a v8::Array, attached to globalThis (for now, let's call it "ddsa_violations"). This array is empty.
  2. JavaScript creates a Violation class instance: const violation = ddsa.Violation.new(/* ... */);
  3. JavaScript calls globalThis.ddsa_violations.push(violation); This mutates the global v8::Array.
  4. JavaScript rule execution ends with no return value (i.e. "undefined" return, according to v8).
  5. On the Rust side, the v8::Array is drained: each v8::Object (Violation) that was pushed by JavaScript is removed from the array and converted to a js::Violation<Instance> struct.

Alternatives considered

The JavaScript script could return a value.

  • While this would work, I passed on it because we use a "bridge" abstraction everywhere else to pass values and wanted to keep it consistent.

What the reviewer should know

  • This is not currently hooked up to anything. A future PR will integrate this as the final step in a rule's execution.

@jasonforal jasonforal requested a review from juli1 June 6, 2024 16:35
Base automatically changed from jf/STAL-1960-2 to main June 7, 2024 15:39
@jasonforal jasonforal merged commit 70203cc into main Jun 7, 2024
58 of 62 checks passed
@jasonforal jasonforal deleted the jf/STAL-1960-3 branch June 7, 2024 15:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants