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