Skip to content

String.prototype.endsWith breaks Nashorn #1128

@AprilArcus

Description

@AprilArcus

The uncurryThis helper introduced in fcbc2c8 is incompatible with Nashorn. When loading the endsWith polyfill, I receive this error:

TypeError: [jdk.dynalink.beans.SimpleDynamicMethod boolean java.lang.String.endsWith(String)] is not a function

Minimal repro in jRuby:

require 'java'
java_import 'javax.script.ScriptEngineManager'
engine = ScriptEngineManager.new.get_engine_by_name('nashorn')
bindings = engine.create_bindings
engine.eval("var uncurryThis = Function.prototype.call.bind(Function.prototype.call); var nativeEndsWith = uncurryThis(''.endsWith);", bindings)

Note that

> engine.eval("'foo'.endsWith('o')", bindings)
=> true
> engine.eval("''.endsWith", bindings)
=> #<Java::JdkDynalinkBeans::SimpleDynamicMethod:0x33f349ae>
> engine.eval("String.prototype.endsWith", bindings)
=> nil

Prior 3.19, a different error is produced:

Java::JavaLang::AssertionError: unknown call type GET:METHOD|PROPERTY|ELEMENT:call(Object)[email protected]$Recompilation$6803$\^eval\_

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions