Skip to content

Instantly share code, notes, and snippets.

@postmodern
Created October 25, 2021 21:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save postmodern/91f704b05230640fadf43786feb8e170 to your computer and use it in GitHub Desktop.
Save postmodern/91f704b05230640fadf43786feb8e170 to your computer and use it in GitHub Desktop.
Hook JavaScript's eval() using Ruby
begin
require 'bundler/inline'
rescue LoadError => error
abort error.message
end
gemfile do
source 'https://rubygems.org'
gem 'therubyracer'
end
require 'v8'
ctx = V8::Context.new
ctx[:eval] = ->(this, code) { puts "eval(#{code})"; ctx.eval(code) }
p ctx.eval("eval(\"1 + 1\");")
# > eval(1 + 1)
# > 2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment