Created
October 25, 2021 21:45
-
-
Save postmodern/91f704b05230640fadf43786feb8e170 to your computer and use it in GitHub Desktop.
Hook JavaScript's eval() using Ruby
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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