Skip to content

Commit

Permalink
indy fix
Browse files Browse the repository at this point in the history
  • Loading branch information
enebo committed Aug 19, 2023
1 parent 1fa1e5f commit 69ffd8f
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 1 deletion.
12 changes: 12 additions & 0 deletions core/src/main/java/org/jruby/Ruby.java
Original file line number Diff line number Diff line change
Expand Up @@ -4939,6 +4939,17 @@ public MethodHandle getNullToNilHandle() {
return this.nullToNil = nullToNil;
}

public MethodHandle getNullToUndefinedHandle() {
MethodHandle filter = this.nullToUndefined;

if (filter != null) return filter;

filter = InvokeDynamicSupport.findStatic(Helpers.class, "nullToUndefined", methodType(IRubyObject.class, IRubyObject.class));
filter = explicitCastArguments(filter, methodType(IRubyObject.class, Object.class));

return this.nullToUndefined = filter;
}

// Parser stats methods
private void addLoadParseToStats() {
if (parserStats != null) parserStats.addLoadParse();
Expand Down Expand Up @@ -5745,6 +5756,7 @@ public int applyAsInt(ThreadContext context) {
* The nullToNil filter for this runtime.
*/
private MethodHandle nullToNil;
private MethodHandle nullToUndefined;

public final ClassValue<TypePopulator> POPULATORS = new ClassValue<TypePopulator>() {
@Override
Expand Down
4 changes: 4 additions & 0 deletions core/src/main/java/org/jruby/runtime/Helpers.java
Original file line number Diff line number Diff line change
Expand Up @@ -920,6 +920,10 @@ public static IRubyObject nullToNil(IRubyObject value, IRubyObject nil) {
return value != null ? value : nil;
}

public static IRubyObject nullToUndefined(IRubyObject value) {
return value != null ? value : UndefinedValue.UNDEFINED;
}

public static void handleArgumentSizes(ThreadContext context, Ruby runtime, int given, int required, int opt, int rest) {
if (opt == 0) {
if (rest < 0) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,9 @@ public IRubyObject ivarGet(IRubyObject self) throws Throwable {
VariableAccessor accessor = realClass.getVariableAccessorForRead(name());

// produce nil if the variable has not been initialize
MethodHandle nullToNil = self.getRuntime().getNullToNilHandle();
MethodHandle nullToNil = rawValue ?
self.getRuntime().getNullToUndefinedHandle() :
self.getRuntime().getNullToNilHandle();

// get variable value and filter with nullToNil
MethodHandle getValue;
Expand Down

0 comments on commit 69ffd8f

Please sign in to comment.