Skip to content

Commit a7d2155

Browse files
committed
Undefine allocator for Polyglot::ForeignObject
* The same way as for Integer, Symbol, etc. * Polyglot::ForeignObject.new would otherwise return a RubyBasicObject which is not actually a foreign object, and that would lead to confusion. * #new is overridden by InstantiableTrait and that works fine for InteropLibrary#isInstantiable() foreign objects.
1 parent c62fc35 commit a7d2155

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

src/main/ruby/truffleruby/core/truffle/polyglot.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -533,6 +533,14 @@ def delete(member)
533533

534534
class ForeignObject < Object
535535
include ObjectTrait
536+
537+
class << self
538+
undef_method :new
539+
end
540+
541+
def self.__allocate__
542+
raise TypeError, "allocator undefined for #{self}"
543+
end
536544
end
537545

538546
class ForeignException < Exception # rubocop:disable Lint/InheritException

0 commit comments

Comments
 (0)