@ugo-studio/jspp 0.3.2 → 0.3.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -92,7 +92,7 @@ AnyValue &get_charAt_fn()
92
92
  static AnyValue fn = AnyValue::make_function([](const AnyValue &thisVal, std::span<const AnyValue> args) -> AnyValue
93
93
  {
94
94
  auto self = thisVal.as_string();
95
- double pos = args.empty() ? 0 : Operators_Private::ToNumber(args[0]);
95
+ double pos = args.empty() ? 0 : NumberOperators::ToDouble(args[0]);
96
96
  int index = static_cast<int>(pos);
97
97
  if (index < 0 || index >= self->value.length())
98
98
  {
@@ -125,7 +125,7 @@ AnyValue &get_endsWith_fn()
125
125
  if (args.empty())
126
126
  return Constants::FALSE;
127
127
  std::string search = args[0].to_std_string();
128
- size_t end_pos = (args.size() > 1 && !args[1].is_undefined()) ? static_cast<size_t>(Operators_Private::ToNumber(args[1])) : self->value.length();
128
+ size_t end_pos = (args.size() > 1 && !args[1].is_undefined()) ? static_cast<size_t>(NumberOperators::ToDouble(args[1])) : self->value.length();
129
129
 
130
130
  if (end_pos > self->value.length())
131
131
  end_pos = self->value.length();
@@ -145,7 +145,7 @@ AnyValue &get_includes_fn()
145
145
  if (args.empty())
146
146
  return Constants::FALSE;
147
147
  std::string search = args[0].to_std_string();
148
- size_t pos = (args.size() > 1) ? static_cast<size_t>(Operators_Private::ToNumber(args[1])) : 0;
148
+ size_t pos = (args.size() > 1) ? static_cast<size_t>(NumberOperators::ToDouble(args[1])) : 0;
149
149
 
150
150
  return AnyValue::make_boolean(self->value.find(search, pos) != std::string::npos); },
151
151
  "includes");
@@ -160,7 +160,7 @@ AnyValue &get_indexOf_fn()
160
160
  if (args.empty())
161
161
  return AnyValue::make_number(-1);
162
162
  std::string search = args[0].to_std_string();
163
- size_t pos = (args.size() > 1) ? static_cast<size_t>(Operators_Private::ToNumber(args[1])) : 0;
163
+ size_t pos = (args.size() > 1) ? static_cast<size_t>(NumberOperators::ToDouble(args[1])) : 0;
164
164
  size_t result = self->value.find(search, pos);
165
165
  return result == std::string::npos ? AnyValue::make_number(-1) : AnyValue::make_number(result); },
166
166
  "indexOf");
@@ -175,7 +175,7 @@ AnyValue &get_lastIndexOf_fn()
175
175
  if (args.empty())
176
176
  return AnyValue::make_number(-1);
177
177
  std::string search = args[0].to_std_string();
178
- size_t pos = (args.size() > 1 && !args[1].is_undefined()) ? static_cast<size_t>(Operators_Private::ToNumber(args[1])) : std::string::npos;
178
+ size_t pos = (args.size() > 1 && !args[1].is_undefined()) ? static_cast<size_t>(NumberOperators::ToDouble(args[1])) : std::string::npos;
179
179
  size_t result = self->value.rfind(search, pos);
180
180
  return result == std::string::npos ? AnyValue::make_number(-1) : AnyValue::make_number(result); },
181
181
  "lastIndexOf");
@@ -187,7 +187,7 @@ AnyValue &get_padEnd_fn()
187
187
  static AnyValue fn = AnyValue::make_function([](const AnyValue &thisVal, std::span<const AnyValue> args) -> AnyValue
188
188
  {
189
189
  auto self = thisVal.as_string();
190
- size_t target_length = args.empty() ? 0 : static_cast<size_t>(Operators_Private::ToNumber(args[0]));
190
+ size_t target_length = args.empty() ? 0 : static_cast<size_t>(NumberOperators::ToDouble(args[0]));
191
191
  if (self->value.length() >= target_length)
192
192
  return AnyValue::make_string(self->value);
193
193
  std::string pad_string = (args.size() > 1 && !args[1].is_undefined() && !args[1].to_std_string().empty()) ? args[1].to_std_string() : " ";
@@ -206,7 +206,7 @@ AnyValue &get_padStart_fn()
206
206
  static AnyValue fn = AnyValue::make_function([](const AnyValue &thisVal, std::span<const AnyValue> args) -> AnyValue
207
207
  {
208
208
  auto self = thisVal.as_string();
209
- size_t target_length = args.empty() ? 0 : static_cast<size_t>(Operators_Private::ToNumber(args[0]));
209
+ size_t target_length = args.empty() ? 0 : static_cast<size_t>(NumberOperators::ToDouble(args[0]));
210
210
  if (self->value.length() >= target_length)
211
211
  return AnyValue::make_string(self->value);
212
212
  std::string pad_string = (args.size() > 1 && !args[1].is_undefined() && !args[1].to_std_string().empty()) ? args[1].to_std_string() : " ";
@@ -225,7 +225,7 @@ AnyValue &get_repeat_fn()
225
225
  static AnyValue fn = AnyValue::make_function([](const AnyValue &thisVal, std::span<const AnyValue> args) -> AnyValue
226
226
  {
227
227
  auto self = thisVal.as_string();
228
- double count = args.empty() ? 0 : Operators_Private::ToNumber(args[0]);
228
+ double count = args.empty() ? 0 : NumberOperators::ToDouble(args[0]);
229
229
  if (count < 0)
230
230
  {
231
231
  // In a real implementation, this should throw a RangeError.
@@ -290,8 +290,8 @@ AnyValue &get_slice_fn()
290
290
  {
291
291
  auto self = thisVal.as_string();
292
292
  int len = self->value.length();
293
- int start = args.empty() ? 0 : Operators_Private::ToInt32(args[0]);
294
- int end = (args.size() < 2 || args[1].is_undefined()) ? len : Operators_Private::ToInt32(args[1]);
293
+ int start = args.empty() ? 0 : NumberOperators::ToInt32(args[0]);
294
+ int end = (args.size() < 2 || args[1].is_undefined()) ? len : NumberOperators::ToInt32(args[1]);
295
295
 
296
296
  if (start < 0)
297
297
  start += len;
@@ -347,7 +347,7 @@ AnyValue &get_startsWith_fn()
347
347
  if (args.empty())
348
348
  return Constants::FALSE;
349
349
  std::string search = args[0].to_std_string();
350
- size_t pos = (args.size() > 1) ? static_cast<size_t>(Operators_Private::ToNumber(args[1])) : 0;
350
+ size_t pos = (args.size() > 1) ? static_cast<size_t>(NumberOperators::ToDouble(args[1])) : 0;
351
351
  if (pos > self->value.length())
352
352
  pos = self->value.length();
353
353
 
@@ -362,8 +362,8 @@ AnyValue &get_substring_fn()
362
362
  {
363
363
  auto self = thisVal.as_string();
364
364
  int len = self->value.length();
365
- int start = args.empty() ? 0 : Operators_Private::ToInt32(args[0]);
366
- int end = (args.size() < 2 || args[1].is_undefined()) ? len : Operators_Private::ToInt32(args[1]);
365
+ int start = args.empty() ? 0 : NumberOperators::ToInt32(args[0]);
366
+ int end = (args.size() < 2 || args[1].is_undefined()) ? len : NumberOperators::ToInt32(args[1]);
367
367
 
368
368
  start = std::max(0, start);
369
369
  end = std::max(0, end);