MCPcopy Create free account
hub / github.com/dynjs/dynjs / toNumber

Method toNumber

src/main/java/org/dynjs/runtime/Types.java:115–143  ·  view source on GitHub ↗
(ExecutionContext context, Object o)

Source from the content-addressed store, hash-verified

113 }
114
115 public static Number toNumber(ExecutionContext context, Object o) {
116 // 9.3
117 if (o instanceof Number) {
118 return (Number) o;
119 }
120
121 if (o == Types.UNDEFINED) {
122 return Double.NaN;
123 }
124
125 if (o == Types.NULL) {
126 return 0L;
127 }
128
129 if (o instanceof JSObject) {
130 return toNumber(context, toPrimitive(context, o, "Number"));
131 }
132
133 if (o instanceof Boolean) {
134 if (o == Boolean.TRUE) {
135 return 1L;
136 }
137
138 return 0L;
139 }
140
141 Number n = stringToNumber(o.toString());
142 return n;
143 }
144
145 public static String trimString(String value) {
146 int len = value.length();

Callers 15

testHexStringToNumberMethod · 0.95
addMethod · 0.95
subMethod · 0.95
interpretMethod · 0.95
interpretMethod · 0.95
interpretMethod · 0.95
interpretMethod · 0.95
interpretMethod · 0.95
interpretMethod · 0.95
defineOwnPropertyMethod · 0.95
toIntegerMethod · 0.95

Calls 3

toPrimitiveMethod · 0.95
stringToNumberMethod · 0.95
toStringMethod · 0.45

Tested by 2

testHexStringToNumberMethod · 0.76