Skip to content

Commit 7dd7eeb

Browse files
committed
Fix ToNumber on Symbols
1 parent 6d436c1 commit 7dd7eeb

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

Diff for: iv/lv5/error_check.h

+6
Original file line numberDiff line numberDiff line change
@@ -34,4 +34,10 @@
3434
*/ \
3535
IV_LV5_ERROR_WITH(error, {})
3636

37+
#define IV_LV5_ERROR_REPORT(error, type, string)\
38+
do { \
39+
(error)->Report((type), (string)); \
40+
return {}; \
41+
} while (0)
42+
3743
#endif // IV_LV5_ERROR_CHECK_H_

Diff for: iv/lv5/jsval.h

+4-2
Original file line numberDiff line numberDiff line change
@@ -764,7 +764,8 @@ inline double JSLayout::ToNumber(Context* ctx, Error* e) const {
764764
} else if (IsUndefined()) {
765765
return core::kNaN;
766766
} else if (IsSymbol()) {
767-
return core::kNaN;
767+
e->Report(Error::Type, "Cannot perform ToNumber operation on Symbols");
768+
return {};
768769
} else {
769770
assert(IsObject());
770771
JSLayout prim = object()->DefaultValue(ctx, Hint::NUMBER, IV_LV5_ERROR(e));
@@ -793,7 +794,8 @@ inline JSVal JSVal::ToNumberValue(Context* ctx, Error* e) const {
793794
} else if (IsUndefined()) {
794795
return core::kNaN;
795796
} else if (IsSymbol()) {
796-
return core::kNaN;
797+
e->Report(Error::Type, "Cannot perform ToNumber operation on Symbols");
798+
return {};
797799
} else {
798800
assert(IsObject());
799801
const JSVal prim =

0 commit comments

Comments
 (0)