function.rb 890 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. module V8
  2. class Function < V8::Object
  3. def methodcall(thisObject, *args)
  4. err = nil
  5. return_value = nil
  6. @portal.open do |to|
  7. C::TryCatch.try do |try|
  8. this = to.v8(thisObject)
  9. return_value = to.rb(@native.Call(this, to.v8(args)))
  10. err = JSError.new(try, to) if try.HasCaught()
  11. end
  12. end
  13. raise err if err
  14. return return_value
  15. end
  16. def call(*args)
  17. @portal.open do
  18. self.methodcall(@portal.context.native.Global(), *args)
  19. end
  20. end
  21. def new(*args)
  22. @portal.open do |to|
  23. to.rb(@native.NewInstance(to.v8(args)))
  24. end
  25. end
  26. def name
  27. @portal.open do |to|
  28. to.rb(@native.GetName())
  29. end
  30. end
  31. def name=(name)
  32. name.tap do
  33. @portal.open do |to|
  34. @native.SetName(to.v8(name))
  35. end
  36. end
  37. end
  38. end
  39. end