nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/linker/JavaArgumentConverters.java
equal
deleted
inserted
replaced
25 |
25 |
26 package jdk.nashorn.internal.runtime.linker; |
26 package jdk.nashorn.internal.runtime.linker; |
27 |
27 |
28 import static jdk.nashorn.internal.lookup.Lookup.MH; |
28 import static jdk.nashorn.internal.lookup.Lookup.MH; |
29 import static jdk.nashorn.internal.runtime.ECMAErrors.typeError; |
29 import static jdk.nashorn.internal.runtime.ECMAErrors.typeError; |
|
30 import static jdk.nashorn.internal.runtime.JSType.isString; |
30 import static jdk.nashorn.internal.runtime.ScriptRuntime.UNDEFINED; |
31 import static jdk.nashorn.internal.runtime.ScriptRuntime.UNDEFINED; |
31 |
32 |
32 import java.lang.invoke.MethodHandle; |
33 import java.lang.invoke.MethodHandle; |
33 import java.lang.invoke.MethodHandles; |
34 import java.lang.invoke.MethodHandles; |
34 import java.util.HashMap; |
35 import java.util.HashMap; |
76 // TODO: if/when we're allowed to use FindBugs at build time, we can use annotations to disable this warning |
77 // TODO: if/when we're allowed to use FindBugs at build time, we can use annotations to disable this warning |
77 return null; |
78 return null; |
78 } |
79 } |
79 |
80 |
80 if (obj == UNDEFINED) { |
81 if (obj == UNDEFINED) { |
81 // NOTE: same reasoning for FindBugs NP_BOOLEAN_RETURN_NUL warning as in the preceding comment. |
82 // NOTE: same reasoning for FindBugs NP_BOOLEAN_RETURN_NULL warning as in the preceding comment. |
82 return null; |
83 return null; |
83 } |
84 } |
84 |
85 |
85 if (obj instanceof Number) { |
86 if (obj instanceof Number) { |
86 final double num = ((Number) obj).doubleValue(); |
87 final double num = ((Number) obj).doubleValue(); |
87 return num != 0 && !Double.isNaN(num); |
88 return num != 0 && !Double.isNaN(num); |
88 } |
89 } |
89 |
90 |
90 if (obj instanceof String || obj instanceof ConsString) { |
91 if (isString(obj)) { |
91 return ((CharSequence) obj).length() > 0; |
92 return ((CharSequence) obj).length() > 0; |
92 } |
93 } |
93 |
94 |
94 if (obj instanceof ScriptObject) { |
95 if (obj instanceof ScriptObject) { |
95 return true; |
96 return true; |
205 return 0L; |
206 return 0L; |
206 } |
207 } |
207 return f.longValue(); |
208 return f.longValue(); |
208 } else if (obj instanceof Number) { |
209 } else if (obj instanceof Number) { |
209 return ((Number)obj).longValue(); |
210 return ((Number)obj).longValue(); |
210 } else if (obj instanceof String || obj instanceof ConsString) { |
211 } else if (isString(obj)) { |
211 return JSType.toLong(obj); |
212 return JSType.toLong(obj); |
212 } else if (obj instanceof Boolean) { |
213 } else if (obj instanceof Boolean) { |
213 return (Boolean)obj ? 1L : 0L; |
214 return (Boolean)obj ? 1L : 0L; |
214 } else if (obj instanceof ScriptObject) { |
215 } else if (obj instanceof ScriptObject) { |
215 obj = JSType.toPrimitive(obj, Number.class); |
216 obj = JSType.toPrimitive(obj, Number.class); |