mirror of
https://github.com/rubyjs/therubyracer
synced 2023-03-27 23:21:42 -04:00
fix segfaulting testcases
This commit is contained in:
parent
8f8c03e207
commit
e4d96e24ed
5 changed files with 19 additions and 19 deletions
|
@ -60,7 +60,7 @@ module V8
|
|||
|
||||
def set(obj, name, value, &dontintercept)
|
||||
setter = name + "="
|
||||
methods = accessible_methods(obj)
|
||||
methods = accessible_methods(obj, true)
|
||||
if methods.include?(setter)
|
||||
obj.send(setter, value)
|
||||
elsif obj.respond_to?(:[]=)
|
||||
|
@ -101,14 +101,7 @@ module V8
|
|||
end
|
||||
|
||||
def names(obj)
|
||||
obj.public_methods(false).map {|m| m.to_s}.to_set.tap do |methods|
|
||||
ancestors = obj.class.ancestors.dup
|
||||
while ancestor = ancestors.shift
|
||||
break if ancestor == ::Object
|
||||
methods.merge(ancestor.public_instance_methods(false).map {|m| m.to_s})
|
||||
end
|
||||
methods.reject! {|m| m == "[]" || m == "[]="}
|
||||
end
|
||||
accessible_methods(obj)
|
||||
end
|
||||
|
||||
def indices(obj)
|
||||
|
@ -117,14 +110,14 @@ module V8
|
|||
|
||||
private
|
||||
|
||||
def accessible_methods(obj)
|
||||
def accessible_methods(obj, special_methods = false)
|
||||
obj.public_methods(false).map {|m| m.to_s}.to_set.tap do |methods|
|
||||
ancestors = obj.class.ancestors.dup
|
||||
while ancestor = ancestors.shift
|
||||
break if ancestor == ::Object
|
||||
methods.merge(ancestor.public_instance_methods(false).map {|m| m.to_s})
|
||||
end
|
||||
methods.reject! {|m| m == "[]" || m == "[]="}
|
||||
methods.reject! {|m| m == "[]" || m == "[]=" || m =~ /=$/} unless special_methods
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -6,7 +6,7 @@ module V8
|
|||
def initialize(opts = {})
|
||||
@to = Portal.new(self)
|
||||
@access = Access.new(@to)
|
||||
@native = opts[:with] ? C::Context::New(Access.rubyobject) : C::Context::New()
|
||||
@native = opts[:with] ? C::Context::New(@to.rubytemplate) : C::Context::New()
|
||||
@native.enter do
|
||||
@scope = @to.rb(@native.Global())
|
||||
@native.Global().SetHiddenValue(C::String::New("TheRubyRacer::RubyObject"), C::External::New(opts[:with])) if opts[:with]
|
||||
|
@ -24,11 +24,11 @@ module V8
|
|||
@native.enter do
|
||||
script = C::Script::Compile(@to.v8(javascript.to_s), @to.v8(filename.to_s))
|
||||
if try.HasCaught()
|
||||
err = JSError.new(try)
|
||||
err = JSError.new(try, @to)
|
||||
else
|
||||
result = script.Run()
|
||||
if try.HasCaught()
|
||||
err = JSError.new(try)
|
||||
err = JSError.new(try, @to)
|
||||
else
|
||||
value = @to.rb(result)
|
||||
end
|
||||
|
|
|
@ -3,7 +3,8 @@ module V8
|
|||
class JSError < StandardError
|
||||
attr_reader :value, :boundaries
|
||||
|
||||
def initialize(try)
|
||||
def initialize(try, to)
|
||||
@to = to
|
||||
begin
|
||||
super(initialize_unsafe(try))
|
||||
rescue Exception => e
|
||||
|
@ -15,7 +16,7 @@ module V8
|
|||
|
||||
def initialize_unsafe(try)
|
||||
message = nil
|
||||
ex = To.rb(try.Exception())
|
||||
ex = @to.rb(try.Exception())
|
||||
@boundaries = [Boundary.new(:rbframes => caller(3), :jsframes => parse_js_frames(try))]
|
||||
if V8::Object === ex
|
||||
if msg = ex['message']
|
||||
|
@ -87,7 +88,7 @@ module V8
|
|||
end
|
||||
|
||||
def parse_js_frames(try)
|
||||
raw = To.rb(try.StackTrace())
|
||||
raw = @to.rb(try.StackTrace())
|
||||
if raw && !raw.empty?
|
||||
raw.split("\n")[1..-1].tap do |frames|
|
||||
frames.each {|frame| frame.strip!.chomp!(",")}
|
||||
|
|
|
@ -8,7 +8,7 @@ module V8
|
|||
@portal.open do |to|
|
||||
this = to.v8(thisObject)
|
||||
return_value = to.rb(@native.Call(this, to.v8(args)))
|
||||
err = JSError.new(try) if try.HasCaught()
|
||||
err = JSError.new(try, to) if try.HasCaught()
|
||||
end
|
||||
end
|
||||
raise err if err
|
||||
|
|
|
@ -113,6 +113,12 @@ module V8
|
|||
end
|
||||
end
|
||||
|
||||
def rubytemplate
|
||||
C::ObjectTemplate::New().tap do |t|
|
||||
setuptemplate(t)
|
||||
end
|
||||
end
|
||||
|
||||
def setuptemplate(t)
|
||||
t.SetNamedPropertyHandler(
|
||||
@named_property_getter,
|
||||
|
@ -223,7 +229,7 @@ module V8
|
|||
class NamedPropertyEnumerator < Interceptor
|
||||
def call(info)
|
||||
intercept(info) do |obj, dontintercept|
|
||||
access.names(obj, &dontintercept)
|
||||
access.names(obj, &dontintercept).to_a
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Add table
Reference in a new issue