diff --git a/core/src/avm2/globals/RegExp.as b/core/src/avm2/globals/RegExp.as index 98b110858769..8a5838cdd95f 100644 --- a/core/src/avm2/globals/RegExp.as +++ b/core/src/avm2/globals/RegExp.as @@ -29,9 +29,34 @@ package { } prototype.toString = function():String { - return this.valueOf(); + // Note: This function is not generic and will throw for non-regexps. + var regexp: RegExp = this; + + // ECMA-262 Edition 5.1 - RegExp.prototype.toString(): + // Return the String value formed by concatenating the Strings "/", + // the String value of the source property of this RegExp object, and "/"; + // plus "g" if the global property is true, + // "i" if the ignoreCase property is true, + // and "m" if the multiline property is true. + var string = "/" + regexp.source + "/"; + if (regexp.global) { + string += "g"; + } + if (regexp.ignoreCase) { + string += "i"; + } + if (regexp.multiline) { + string += "m"; + } + if (regexp.dotall) { + string += "s"; + } + if (regexp.extended) { + string += "x"; + } + return string; } - + prototype.setPropertyIsEnumerable("exec", false); prototype.setPropertyIsEnumerable("test", false); prototype.setPropertyIsEnumerable("toString", false); diff --git a/core/src/avm2/object/regexp_object.rs b/core/src/avm2/object/regexp_object.rs index ddbc04467426..192dfefbcebe 100644 --- a/core/src/avm2/object/regexp_object.rs +++ b/core/src/avm2/object/regexp_object.rs @@ -87,10 +87,6 @@ impl<'gc> TObject<'gc> for RegExpObject<'gc> { self.0.as_ptr() as *const ObjectPtr } - fn to_string(&self, _activation: &mut Activation<'_, 'gc>) -> Result, Error<'gc>> { - Ok(Value::Object(Object::from(*self))) - } - fn value_of(&self, mc: &Mutation<'gc>) -> Result, Error<'gc>> { let read = self.0.read(); let mut s = WString::new();