1use crate::builtins::substitution::{Substitution, get_substitution};
11use crate::builtins::{arg, define_method, install_species_accessor};
12use crate::interp::{Interp, JsResult};
13use crate::object::{JsObject, Property};
14use crate::regexp::{Flags, Regex};
15use crate::value::Value;
16use js_gc::Gc;
17
18#[derive(Clone)]
23pub struct RegExpData {
24 pub regex: std::rc::Rc<Regex>,
26 pub source: String,
28 pub flags: String,
30}
31
32pub fn install(interp: &mut Interp<'_>, object_proto: &Gc<JsObject>) -> Gc<JsObject> {
34 let prototype = interp.new_object(Some(object_proto.clone()));
35 let constructor = interp.new_native_constructor("RegExp", 2, constructor);
36 constructor.define(
37 "prototype",
38 Property::with_attributes(Value::Object(prototype.clone()), false, false),
39 );
40 prototype.define(
41 "constructor",
42 Property::with_attributes(Value::Object(constructor.clone()), true, false),
43 );
44
45 define_method(&prototype, "exec", 1, exec, interp);
46 define_method(&prototype, "test", 1, test, interp);
47 define_method(&prototype, "toString", 0, to_string, interp);
48 for (name, getter) in [
49 (
50 "source",
51 source as fn(&mut Interp<'_>, Value, &[Value]) -> JsResult<Value>,
52 ),
53 ("flags", flags),
54 ("global", global),
55 ("ignoreCase", ignore_case),
56 ("multiline", multiline),
57 ("sticky", sticky),
58 ("unicode", unicode),
59 ("dotAll", dot_all),
60 ("hasIndices", has_indices),
61 ] {
62 let getter = interp.new_native(name, 0, getter);
63 prototype.define(
64 name,
65 Property {
66 getter: Some(Value::Object(getter)),
67 enumerable: false,
68 configurable: true,
69 ..Property::default()
70 },
71 );
72 }
73
74 define_method(&constructor, "escape", 1, escape, interp);
76 install_species_accessor(&constructor, interp);
77
78 install_symbol_methods(interp, &prototype, &constructor);
81 interp.realm.regexp_proto = Some(prototype.clone());
82 interp.realm.regexp_ctor = Some(constructor.clone());
83 constructor
84}
85
86fn install_symbol_methods(
87 interp: &mut Interp<'_>,
88 prototype: &Gc<JsObject>,
89 constructor: &Gc<JsObject>,
90) {
91 use crate::interp::WellKnown;
92 for (which, name, func, length) in [
93 (
94 WellKnown::Match,
95 "[Symbol.match]",
96 symbol_match as crate::object::NativeFn,
97 1,
98 ),
99 (WellKnown::Replace, "[Symbol.replace]", symbol_replace, 2),
100 (WellKnown::Search, "[Symbol.search]", symbol_search, 1),
101 (WellKnown::Split, "[Symbol.split]", symbol_split, 2),
102 ] {
103 let method = interp.new_native(name, length, func);
104 prototype.define_key(
105 &interp.realm.well_known_key(which),
106 Property::with_attributes(Value::Object(method), true, false),
107 );
108 }
109 let _ = constructor;
110}
111
112fn escape(interp: &mut Interp<'_>, _this: Value, args: &[Value]) -> JsResult<Value> {
128 let arg = arg(args, 0);
129 if !matches!(arg, Value::String(_)) {
132 return Err(interp.type_error("not a string"));
133 }
134 let source = interp.checked_to_wtf8(&arg)?.code_point_values();
135 let mut out: Vec<u32> = Vec::with_capacity(source.len());
136 for (position, cp) in source.iter().enumerate() {
137 let leading = position == 0;
140 encode_for_regexp_escape(*cp, leading, &mut out);
141 }
142 Ok(interp.string_wtf8(points_to_wtf8(&out)))
143}
144
145fn encode_for_regexp_escape(c: u32, leading: bool, out: &mut Vec<u32>) {
148 let backslash = u32::from(b'\\');
149 let ascii_alnum = matches!(c, 0x30..=0x39 | 0x41..=0x5A | 0x61..=0x7A);
152 if leading && ascii_alnum {
153 push_hex_escape(c, out);
154 return;
155 }
156 if matches!(
158 c,
159 0x2E | 0x2A | 0x2B | 0x3F | 0x5E | 0x24 | 0x7C | 0x28 | 0x29 | 0x5B | 0x5D | 0x7B | 0x7D | 0x5C | 0x2F ) {
163 out.push(backslash);
164 out.push(c);
165 return;
166 }
167 if let Some(letter) = match c {
169 0x09 => Some('t'),
170 0x0A => Some('n'),
171 0x0B => Some('v'),
172 0x0C => Some('f'),
173 0x0D => Some('r'),
174 _ => None,
175 } {
176 out.push(backslash);
177 out.push(u32::from(letter as u8));
178 return;
179 }
180 let other_punctuator = matches!(
183 c,
184 0x2C | 0x2D | 0x3D | 0x3C | 0x3E | 0x23 | 0x26 | 0x21 | 0x25 | 0x3A | 0x3B | 0x40 | 0x7E | 0x27 | 0x60 | 0x22 );
187 if other_punctuator || quickjs_regexp::is_space(c) || (0xD800..=0xDFFF).contains(&c) {
188 if c <= 0xFF {
189 push_hex_escape(c, out);
190 } else {
191 out.push(backslash);
195 out.push(u32::from(b'u'));
196 for shift in [12, 8, 4, 0] {
197 out.push(u32::from(hex_digit((c >> shift) & 0xF)));
198 }
199 }
200 return;
201 }
202 out.push(c);
204}
205
206fn push_hex_escape(c: u32, out: &mut Vec<u32>) {
208 out.push(u32::from(b'\\'));
209 out.push(u32::from(b'x'));
210 out.push(u32::from(hex_digit((c >> 4) & 0xF)));
211 out.push(u32::from(hex_digit(c & 0xF)));
212}
213
214fn hex_digit(nibble: u32) -> u8 {
216 match nibble {
217 0..=9 => b'0' + nibble as u8,
218 _ => b'a' + (nibble as u8 - 10),
219 }
220}
221
222fn constructor(interp: &mut Interp<'_>, _this: Value, args: &[Value]) -> JsResult<Value> {
224 let pattern = arg(args, 0);
225 let flags = arg(args, 1);
226 let (source, flags) = match &pattern {
228 Value::Object(object) if object.regexp().is_some() => {
229 let data = object.regexp().expect("checked");
230 let flags = if matches!(flags, Value::Undefined) {
231 data.flags.clone()
232 } else {
233 interp.to_js_string(&flags)?
234 };
235 (data.source.clone(), flags)
236 }
237 Value::Undefined => (
243 String::new(),
244 if matches!(flags, Value::Undefined) {
245 String::new()
246 } else {
247 interp.to_js_string(&flags)?
248 },
249 ),
250 other => (
251 interp.to_js_string(other)?,
252 if matches!(flags, Value::Undefined) {
253 String::new()
254 } else {
255 interp.to_js_string(&flags)?
256 },
257 ),
258 };
259 let object = allocate(interp)?;
260 Ok(Value::Object(initialise(interp, object, &source, &flags)?))
261}
262
263fn exec(interp: &mut Interp<'_>, this: Value, args: &[Value]) -> JsResult<Value> {
265 let Some(object) = this.as_object() else {
266 return Err(interp.type_error("RegExp.prototype.exec called on a non-object"));
267 };
268 let text = interp.checked_to_wtf8(&arg(args, 0))?;
269 exec_on(interp, object, &text)
270}
271
272pub fn exec_on(
274 interp: &mut Interp<'_>,
275 object: &Gc<JsObject>,
276 text: &crate::value::Wtf8,
277) -> JsResult<Value> {
278 let Some(data) = object.regexp() else {
279 return Err(interp.type_error("method called on a non-RegExp"));
280 };
281 let sticky_or_global = data.regex.flags.global || data.regex.flags.sticky;
282 let start = if sticky_or_global {
283 let index = interp.get_property(object, "lastIndex")?;
284 let index = interp.to_js_number(&index.unwrap_or(Value::Int(0)))?;
285 if !index.is_finite() || index < 0.0 {
286 interp.set_property(object, "lastIndex", Value::Int(0))?;
287 return Ok(Value::Null);
288 }
289 index as usize
290 } else {
291 0
292 };
293 let input = MatchInput::new(&data.regex, text);
294 if start > input.units_len() {
299 if sticky_or_global {
300 interp.set_property(object, "lastIndex", Value::Int(0))?;
301 }
302 return Ok(Value::Null);
303 }
304 let start = input.position(start);
305 let found = data.regex.exec_at(&input.units, start);
306 let Some(found) = found else {
307 if sticky_or_global {
308 interp.set_property(object, "lastIndex", Value::Int(0))?;
309 }
310 return Ok(Value::Null);
311 };
312 if sticky_or_global {
315 let end = input.offset(found.end);
316 interp.set_property(object, "lastIndex", Value::Int(end as i32))?;
317 }
318 let mut elements: Vec<Value> = Vec::with_capacity(found.captures.len());
321 for capture in &found.captures {
322 elements.push(match capture {
323 Some((start, end)) => interp.string_wtf8(input.slice(*start, *end)),
324 None => Value::Undefined,
325 });
326 }
327 let array = interp.new_array(elements);
328 let index = input.offset(found.start);
329 let input_value = interp.string_wtf8(text.clone());
330 interp.set_property(&array, "index", Value::Int(index as i32))?;
331 interp.set_property(&array, "input", input_value.clone())?;
332 let groups = if data.regex.names.is_empty() {
339 Value::Undefined
340 } else {
341 let groups = interp.new_object(None);
342 for (name, index) in &data.regex.names {
343 let value = match found.captures.get(*index).copied().flatten() {
344 Some((start, end)) => interp.string_wtf8(input.slice(start, end)),
345 None => Value::Undefined,
346 };
347 interp.set_property(&groups, name, value)?;
348 }
349 Value::Object(groups)
350 };
351 interp.set_property(&array, "groups", groups)?;
352 if data.regex.flags.has_indices {
353 let mut pairs = Vec::with_capacity(found.captures.len());
354 for capture in &found.captures {
355 pairs.push(match capture {
356 Some((start, end)) => {
357 let (start, end) = (input.offset(*start), input.offset(*end));
358 let pair =
359 interp.new_array(vec![Value::Int(start as i32), Value::Int(end as i32)]);
360 Value::Object(pair)
361 }
362 None => Value::Undefined,
363 });
364 }
365 let indices = interp.new_array(pairs);
366 interp.set_property(&array, "indices", Value::Object(indices))?;
367 }
368 Ok(Value::Object(array))
369}
370
371struct MatchInput {
388 units: Vec<u32>,
390 unit_start: Vec<usize>,
393}
394
395impl MatchInput {
396 fn new(regex: &quickjs_regexp::Regex, text: &crate::value::Wtf8) -> Self {
397 if regex.per_code_unit() {
398 let units: Vec<u32> = text.to_units().into_iter().map(u32::from).collect();
399 let unit_start = (0..=units.len()).collect();
400 Self { units, unit_start }
401 } else {
402 let units = text.code_point_values();
403 let mut unit_start = Vec::with_capacity(units.len() + 1);
404 let mut count = 0;
405 for point in &units {
406 unit_start.push(count);
407 count += if *point > 0xFFFF { 2 } else { 1 };
408 }
409 unit_start.push(count);
410 Self { units, unit_start }
411 }
412 }
413
414 fn units_len(&self) -> usize {
417 self.unit_start[self.unit_start.len() - 1]
418 }
419
420 fn position(&self, offset: usize) -> usize {
425 self.unit_start
426 .partition_point(|start| *start <= offset)
427 .saturating_sub(1)
428 }
429
430 fn offset(&self, position: usize) -> usize {
432 self.unit_start[position.min(self.unit_start.len() - 1)]
433 }
434
435 fn slice(&self, start: usize, end: usize) -> crate::value::Wtf8 {
441 points_to_wtf8(self.units.get(start..end).unwrap_or_default())
442 }
443}
444
445fn points_to_wtf8(points: &[u32]) -> crate::value::Wtf8 {
447 let mut units = Vec::with_capacity(points.len());
448 for point in points {
449 if *point > 0xFFFF {
450 let value = point - 0x10000;
451 units.push(0xD800 + (value >> 10) as u16);
452 units.push(0xDC00 + (value & 0x3FF) as u16);
453 } else {
454 units.push(*point as u16);
455 }
456 }
457 crate::value::Wtf8::from_units(&units)
458}
459
460fn test(interp: &mut Interp<'_>, this: Value, args: &[Value]) -> JsResult<Value> {
462 let result = exec(interp, this, args)?;
463 Ok(Value::Bool(!matches!(result, Value::Null)))
464}
465
466fn to_string(interp: &mut Interp<'_>, this: Value, _args: &[Value]) -> JsResult<Value> {
467 let Some(object) = this.as_object() else {
468 return Err(interp.type_error("RegExp.prototype.toString called on a non-object"));
469 };
470 let Some(data) = object.regexp() else {
471 return Err(interp.type_error("RegExp.prototype.toString called on a non-RegExp"));
472 };
473 let source = if data.source.is_empty() {
474 "(?:)".to_string()
475 } else {
476 data.source.clone()
477 };
478 Ok(interp.string(format!("/{source}/{}", data.flags)))
479}
480
481fn source(interp: &mut Interp<'_>, this: Value, _args: &[Value]) -> JsResult<Value> {
482 let data = data_of(interp, &this)?;
483 let text = if data.source.is_empty() {
485 "(?:)".to_string()
486 } else {
487 data.source.clone()
488 };
489 Ok(interp.string(&text))
490}
491
492fn flags(interp: &mut Interp<'_>, this: Value, _args: &[Value]) -> JsResult<Value> {
493 let data = data_of(interp, &this)?;
494 Ok(interp.string(&data.flags))
495}
496
497fn data_of(interp: &mut Interp<'_>, this: &Value) -> JsResult<RegExpData> {
498 match this.as_object().and_then(|object| object.regexp()) {
499 Some(data) => Ok(data.clone()),
500 None => Err(interp.type_error("method called on a non-RegExp")),
501 }
502}
503
504fn flag_getter(interp: &mut Interp<'_>, this: Value, pick: fn(&Flags) -> bool) -> JsResult<Value> {
506 let data = data_of(interp, &this)?;
507 Ok(Value::Bool(pick(&data.regex.flags)))
508}
509
510fn global(interp: &mut Interp<'_>, this: Value, _args: &[Value]) -> JsResult<Value> {
511 flag_getter(interp, this, |flags| flags.global)
512}
513fn ignore_case(interp: &mut Interp<'_>, this: Value, _args: &[Value]) -> JsResult<Value> {
514 flag_getter(interp, this, |flags| flags.ignore_case)
515}
516fn multiline(interp: &mut Interp<'_>, this: Value, _args: &[Value]) -> JsResult<Value> {
517 flag_getter(interp, this, |flags| flags.multiline)
518}
519fn sticky(interp: &mut Interp<'_>, this: Value, _args: &[Value]) -> JsResult<Value> {
520 flag_getter(interp, this, |flags| flags.sticky)
521}
522fn unicode(interp: &mut Interp<'_>, this: Value, _args: &[Value]) -> JsResult<Value> {
523 flag_getter(interp, this, |flags| flags.unicode)
524}
525fn dot_all(interp: &mut Interp<'_>, this: Value, _args: &[Value]) -> JsResult<Value> {
526 flag_getter(interp, this, |flags| flags.dot_all)
527}
528fn has_indices(interp: &mut Interp<'_>, this: Value, _args: &[Value]) -> JsResult<Value> {
529 flag_getter(interp, this, |flags| flags.has_indices)
530}
531
532fn symbol_match(interp: &mut Interp<'_>, this: Value, args: &[Value]) -> JsResult<Value> {
540 let Some(object) = this.as_object() else {
541 return Err(interp.type_error("Symbol.match called on a non-object"));
542 };
543 let text = interp.checked_to_wtf8(&arg(args, 0))?;
544 let is_global = interp
545 .get_property(object, "global")?
546 .unwrap_or(Value::Undefined)
547 .to_boolean();
548 if !is_global {
549 return exec_on(interp, object, &text);
550 }
551 interp.set_property(object, "lastIndex", Value::Int(0))?;
552 let mut results = Vec::new();
553 let input = MatchInput::new(
554 &data_of(interp, &Value::Object(object.clone()))?.regex,
555 &text,
556 );
557 loop {
558 let result = exec_on(interp, object, &text)?;
559 if matches!(result, Value::Null) {
560 break;
561 }
562 let Value::Object(array) = &result else {
563 break;
564 };
565 let matched = interp.get_property(array, "0")?.unwrap_or(Value::Undefined);
566 let empty = interp.to_js_string(&matched)?.is_empty();
567 results.push(result);
568 if empty {
569 let next = interp
570 .get_property(object, "lastIndex")?
571 .unwrap_or(Value::Int(0));
572 let next = interp.to_js_number(&next)? as usize + 1;
573 interp.set_property(object, "lastIndex", Value::Int(next as i32))?;
574 if next > input.units_len() {
575 break;
576 }
577 }
578 }
579 if results.is_empty() {
580 return Ok(Value::Null);
581 }
582 Ok(Value::Object(interp.new_array(results)))
583}
584
585fn symbol_search(interp: &mut Interp<'_>, this: Value, args: &[Value]) -> JsResult<Value> {
587 let Some(object) = this.as_object() else {
588 return Err(interp.type_error("Symbol.search called on a non-object"));
589 };
590 let text = interp.checked_to_wtf8(&arg(args, 0))?;
591 interp.set_property(object, "lastIndex", Value::Int(0))?;
594 let result = exec_on(interp, object, &text)?;
595 match result {
596 Value::Null => Ok(Value::Int(-1)),
597 Value::Object(array) => Ok(interp
598 .get_property(&array, "index")?
599 .unwrap_or(Value::Int(-1))),
600 other => Ok(other),
601 }
602}
603
604fn symbol_split(interp: &mut Interp<'_>, this: Value, args: &[Value]) -> JsResult<Value> {
606 let Some(object) = this.as_object() else {
607 return Err(interp.type_error("Symbol.split called on a non-object"));
608 };
609 let text = interp.checked_to_wtf8(&arg(args, 0))?;
610 let limit = match arg(args, 1) {
611 Value::Undefined => u32::MAX,
612 other => {
613 let number = interp.to_js_number(&other)?;
614 if number.is_nan() || number < 0.0 {
615 0
616 } else {
617 number as u32
618 }
619 }
620 };
621 if limit == 0 {
622 return Ok(Value::Object(interp.new_array(Vec::new())));
623 }
624 let data = data_of(interp, &Value::Object(object.clone()))?;
625 let input = MatchInput::new(&data.regex, &text);
626 let mut parts: Vec<Value> = Vec::new();
627 let mut last = 0usize;
628 let mut scan = 0usize;
629 while scan <= input.units.len() {
630 let Some(found) = data.regex.exec_at(&input.units, scan) else {
631 break;
632 };
633 if found.end == found.start {
635 scan = found.start + 1;
636 continue;
637 }
638 parts.push(interp.string_wtf8(input.slice(last, found.start)));
639 if parts.len() as u32 >= limit {
640 return Ok(Value::Object(interp.new_array(parts)));
641 }
642 for group in found.captures.iter().skip(1) {
643 parts.push(match group {
644 Some((start, end)) => interp.string_wtf8(input.slice(*start, *end)),
645 None => Value::Undefined,
646 });
647 if parts.len() as u32 >= limit {
648 return Ok(Value::Object(interp.new_array(parts)));
649 }
650 }
651 last = found.end;
652 scan = found.end;
653 }
654 parts.push(interp.string_wtf8(input.slice(last, input.units.len())));
655 Ok(Value::Object(interp.new_array(parts)))
656}
657
658fn symbol_replace(interp: &mut Interp<'_>, this: Value, args: &[Value]) -> JsResult<Value> {
661 let Some(object) = this.as_object() else {
662 return Err(interp.type_error("Symbol.replace called on a non-object"));
663 };
664 let text = interp.checked_to_wtf8(&arg(args, 0))?;
665 let replacement = arg(args, 1);
666 let is_global = interp
667 .get_property(object, "global")?
668 .unwrap_or(Value::Undefined)
669 .to_boolean();
670 let data = data_of(interp, &Value::Object(object.clone()))?;
671 let input = MatchInput::new(&data.regex, &text);
672 let units = text.to_units();
674 let mut out: Vec<u16> = Vec::new();
675 let mut last = 0usize;
676 let mut scan = 0usize;
677 let mut replaced = false;
678 while scan <= input.units.len() {
679 let Some(found) = data.regex.exec_at(&input.units, scan) else {
680 break;
681 };
682 out.extend_from_slice(&units[input.offset(last)..input.offset(found.start)]);
683 let substituted = substitute(
684 interp,
685 &replacement,
686 &input,
687 &units,
688 &found,
689 &data.regex.names,
690 )?;
691 out.extend_from_slice(&substituted);
692 last = found.end;
693 let empty = found.start == found.end;
694 scan = if empty { found.end + 1 } else { found.end };
695 replaced = true;
696 if !is_global {
697 break;
698 }
699 if empty && found.end >= input.units.len() {
700 break;
701 }
702 }
703 if !replaced {
704 return Ok(interp.string_wtf8(text.clone()));
705 }
706 out.extend_from_slice(&units[input.offset(last)..]);
707 Ok(interp.string_wtf8(crate::value::Wtf8::from_units(&out)))
708}
709
710#[allow(clippy::too_many_arguments)]
715fn substitute(
716 interp: &mut Interp<'_>,
717 replacement: &Value,
718 input: &MatchInput,
719 units: &[u16],
720 found: &crate::regexp::Match,
721 names: &[(String, usize)],
722) -> JsResult<Vec<u16>> {
723 let start = input.offset(found.start);
724 let end = input.offset(found.end);
725 if let Value::Object(function) = replacement
726 && function.is_callable()
727 {
728 let mut args: Vec<Value> = vec![interp.string_wtf8(input.slice(found.start, found.end))];
729 for group in found.captures.iter().skip(1) {
730 args.push(match group {
731 Some((start, end)) => interp.string_wtf8(input.slice(*start, *end)),
732 None => Value::Undefined,
733 });
734 }
735 args.push(Value::Int(start as i32));
738 args.push(interp.string_wtf8(crate::value::Wtf8::from_units(units)));
739 let result = interp.call_value(Value::Object(function.clone()), Value::Undefined, args)?;
740 return Ok(interp.checked_to_wtf8(&result)?.to_units());
742 }
743 let template = interp.checked_to_wtf8(replacement)?;
744 let captures: Vec<Option<(usize, usize)>> = found
747 .captures
748 .iter()
749 .map(|group| group.map(|(start, end)| (input.offset(start), input.offset(end))))
750 .collect();
751 let mut out: Vec<u16> = Vec::new();
752 get_substitution(
753 &mut out,
754 &template,
755 &Substitution {
756 input: units,
757 position: start,
758 match_len: end - start,
759 captures: &captures,
760 names: (!names.is_empty()).then_some(names),
763 },
764 );
765 Ok(out)
766}
767
768pub fn new_regexp(interp: &mut Interp<'_>, source: &str, flags: &str) -> JsResult<Gc<JsObject>> {
771 let prototype = default_prototype(interp);
772 let object = interp.new_object(Some(prototype));
773 initialise(interp, object, source, flags)
774}
775
776fn default_prototype(interp: &Interp<'_>) -> Gc<JsObject> {
778 interp
779 .realm
780 .regexp_proto
781 .clone()
782 .unwrap_or_else(|| interp.realm.object_proto.clone())
783}
784
785fn allocate(interp: &mut Interp<'_>) -> JsResult<Gc<JsObject>> {
792 let fallback = default_prototype(interp);
793 interp.new_ctor_instance(fallback)
794}
795
796fn initialise(
798 interp: &mut Interp<'_>,
799 object: Gc<JsObject>,
800 source: &str,
801 flags: &str,
802) -> JsResult<Gc<JsObject>> {
803 let Some(parsed) = Flags::parse(flags) else {
804 return Err(invalid_pattern(interp, String::new(), "flags"));
805 };
806 let regex = match Regex::compile(source, parsed) {
807 Ok(regex) => regex,
808 Err(error) => {
809 return Err(invalid_pattern(interp, error.message, ""));
811 }
812 };
813 object.set_regexp(RegExpData {
814 regex: std::rc::Rc::new(regex),
815 source: source.to_string(),
816 flags: parsed.as_flag_string(),
817 });
818 object.define(
819 "lastIndex",
820 Property::with_attributes(Value::Int(0), true, false),
821 );
822 Ok(object)
823}
824
825fn invalid_pattern(interp: &Interp<'_>, message: String, flags: &str) -> crate::interp::Signal {
830 let text = if flags.is_empty() {
831 message
832 } else {
833 "invalid regular expression flags".to_string()
834 };
835 crate::interp::Signal::Throw(interp.make_error("SyntaxError", &text))
836}
837
838pub fn is_regexp(object: &Gc<JsObject>) -> bool {
840 object.regexp().is_some()
841}