Diff
Modified: trunk/Source/_javascript_Core/ChangeLog (199143 => 199144)
--- trunk/Source/_javascript_Core/ChangeLog 2016-04-07 02:09:07 UTC (rev 199143)
+++ trunk/Source/_javascript_Core/ChangeLog 2016-04-07 03:17:58 UTC (rev 199144)
@@ -1,3 +1,35 @@
+2016-04-06 Mark Lam <[email protected]>
+
+ String.prototype.match() should be calling internal function RegExpCreate.
+ https://bugs.webkit.org/show_bug.cgi?id=156318
+
+ Reviewed by Filip Pizlo.
+
+ RegExpCreate is not the same as the RegExp constructor. The current implementation
+ invokes new @RegExp which calls the constructor. This results in failures in
+ es6/Proxy_internal_get_calls_String.prototype.match.js, and
+ es6/Proxy_internal_get_calls_String.prototype.search.js due to observable side
+ effects.
+
+ This patch fixes this by factoring out the part of the RegExp constructor that
+ makes the RegExpCreate function, and changing String's match and search to call
+ RegExpCreate instead in accordance with the ES6 spec.
+
+ * builtins/StringPrototype.js:
+ (match):
+ (search):
+ * runtime/CommonIdentifiers.h:
+ * runtime/JSGlobalObject.cpp:
+ (JSC::JSGlobalObject::init):
+ * runtime/RegExpConstructor.cpp:
+ (JSC::toFlags):
+ (JSC::regExpCreate):
+ (JSC::constructRegExp):
+ (JSC::esSpecRegExpCreate):
+ (JSC::constructWithRegExpConstructor):
+ * runtime/RegExpConstructor.h:
+ (JSC::isRegExp):
+
2016-04-06 Keith Miller <[email protected]>
Unreviewed, uncomment accidentally commented line in test.
Modified: trunk/Source/_javascript_Core/builtins/StringPrototype.js (199143 => 199144)
--- trunk/Source/_javascript_Core/builtins/StringPrototype.js 2016-04-07 02:09:07 UTC (rev 199143)
+++ trunk/Source/_javascript_Core/builtins/StringPrototype.js 2016-04-07 03:17:58 UTC (rev 199144)
@@ -1,6 +1,7 @@
/*
* Copyright (C) 2015 Andy VanWagoner <[email protected]>.
* Copyright (C) 2016 Yusuke Suzuki <[email protected]>
+ * Copyright (C) 2016 Apple Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@@ -41,7 +42,7 @@
}
let thisString = @toString(this);
- let createdRegExp = new @RegExp(regexp, @undefined);
+ let createdRegExp = @regExpCreate(regexp, @undefined);
return createdRegExp[@symbolMatch](thisString);
}
@@ -62,7 +63,7 @@
}
var thisString = @toString(this);
- var createdRegExp = new @RegExp(regexp, @undefined);
+ var createdRegExp = @regExpCreate(regexp, @undefined);
return createdRegExp[@symbolSearch](thisString);
}
Modified: trunk/Source/_javascript_Core/runtime/CommonIdentifiers.h (199143 => 199144)
--- trunk/Source/_javascript_Core/runtime/CommonIdentifiers.h 2016-04-07 02:09:07 UTC (rev 199143)
+++ trunk/Source/_javascript_Core/runtime/CommonIdentifiers.h 2016-04-07 03:17:58 UTC (rev 199144)
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2003, 2007, 2009 Apple Inc. All rights reserved.
+ * Copyright (C) 2003, 2007, 2009, 2016 Apple Inc. All rights reserved.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
@@ -419,6 +419,7 @@
macro(print) \
macro(isSet) \
macro(isMap) \
+ macro(regExpCreate) \
macro(SetIterator) \
macro(setIteratorNext) \
macro(MapIterator) \
Modified: trunk/Source/_javascript_Core/runtime/JSGlobalObject.cpp (199143 => 199144)
--- trunk/Source/_javascript_Core/runtime/JSGlobalObject.cpp 2016-04-07 02:09:07 UTC (rev 199143)
+++ trunk/Source/_javascript_Core/runtime/JSGlobalObject.cpp 2016-04-07 03:17:58 UTC (rev 199144)
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2007, 2008, 2009, 2014-2016 Apple Inc. All rights reserved.
+ * Copyright (C) 2007-2009, 2014-2016 Apple Inc. All rights reserved.
* Copyright (C) 2008 Cameron Zwarich ([email protected])
*
* Redistribution and use in source and binary forms, with or without
@@ -613,6 +613,8 @@
GlobalPropertyInfo(vm.propertyNames->builtinNames().DateTimeFormatPrivateName(), intl->getDirect(vm, vm.propertyNames->DateTimeFormat), DontEnum | DontDelete | ReadOnly),
GlobalPropertyInfo(vm.propertyNames->builtinNames().NumberFormatPrivateName(), intl->getDirect(vm, vm.propertyNames->NumberFormat), DontEnum | DontDelete | ReadOnly),
#endif // ENABLE(INTL)
+
+ GlobalPropertyInfo(vm.propertyNames->regExpCreatePrivateName, JSFunction::create(vm, this, 2, String(), esSpecRegExpCreate, NoIntrinsic), DontEnum | DontDelete | ReadOnly),
};
addStaticGlobals(staticGlobals, WTF_ARRAY_LENGTH(staticGlobals));
Modified: trunk/Source/_javascript_Core/runtime/RegExpConstructor.cpp (199143 => 199144)
--- trunk/Source/_javascript_Core/runtime/RegExpConstructor.cpp 2016-04-07 02:09:07 UTC (rev 199143)
+++ trunk/Source/_javascript_Core/runtime/RegExpConstructor.cpp 2016-04-07 03:17:58 UTC (rev 199144)
@@ -1,6 +1,6 @@
/*
* Copyright (C) 1999-2000 Harri Porten ([email protected])
- * Copyright (C) 2003, 2007, 2008, 2016 Apple Inc. All Rights Reserved.
+ * Copyright (C) 2003, 2007-2008, 2016 Apple Inc. All Rights Reserved.
* Copyright (C) 2009 Torch Mobile, Inc.
*
* This library is free software; you can redistribute it and/or
@@ -277,6 +277,27 @@
return result;
}
+static JSObject* regExpCreate(ExecState* exec, JSGlobalObject* globalObject, JSValue newTarget, JSValue patternArg, JSValue flagsArg)
+{
+ VM& vm = exec->vm();
+ String pattern = patternArg.isUndefined() ? emptyString() : patternArg.toString(exec)->value(exec);
+ if (exec->hadException())
+ return nullptr;
+
+ RegExpFlags flags = toFlags(exec, flagsArg);
+ if (flags == InvalidFlags)
+ return nullptr;
+
+ RegExp* regExp = RegExp::create(vm, pattern, flags);
+ if (!regExp->isValid())
+ return vm.throwException(exec, createSyntaxError(exec, regExp->errorMessage()));
+
+ Structure* structure = getRegExpStructure(exec, globalObject, newTarget);
+ if (vm.exception())
+ return nullptr;
+ return RegExpObject::create(vm, structure, regExp);
+}
+
JSObject* constructRegExp(ExecState* exec, JSGlobalObject* globalObject, const ArgList& args, JSObject* callee, JSValue newTarget)
{
VM& vm = exec->vm();
@@ -319,22 +340,15 @@
patternArg = pattern;
}
- String pattern = patternArg.isUndefined() ? emptyString() : patternArg.toString(exec)->value(exec);
- if (exec->hadException())
- return nullptr;
+ return regExpCreate(exec, globalObject, newTarget, patternArg, flagsArg);
+}
- RegExpFlags flags = toFlags(exec, flagsArg);
- if (flags == InvalidFlags)
- return nullptr;
-
- RegExp* regExp = RegExp::create(vm, pattern, flags);
- if (!regExp->isValid())
- return vm.throwException(exec, createSyntaxError(exec, regExp->errorMessage()));
-
- Structure* structure = getRegExpStructure(exec, globalObject, newTarget);
- if (vm.exception())
- return nullptr;
- return RegExpObject::create(vm, structure, regExp);
+EncodedJSValue JSC_HOST_CALL esSpecRegExpCreate(ExecState* exec)
+{
+ JSGlobalObject* globalObject = exec->lexicalGlobalObject();
+ JSValue patternArg = exec->argument(0);
+ JSValue flagsArg = exec->argument(1);
+ return JSValue::encode(regExpCreate(exec, globalObject, jsUndefined(), patternArg, flagsArg));
}
static EncodedJSValue JSC_HOST_CALL constructWithRegExpConstructor(ExecState* exec)
Modified: trunk/Source/_javascript_Core/runtime/RegExpConstructor.h (199143 => 199144)
--- trunk/Source/_javascript_Core/runtime/RegExpConstructor.h 2016-04-07 02:09:07 UTC (rev 199143)
+++ trunk/Source/_javascript_Core/runtime/RegExpConstructor.h 2016-04-07 03:17:58 UTC (rev 199144)
@@ -148,6 +148,8 @@
return object->inherits(RegExpObject::info());
}
+EncodedJSValue JSC_HOST_CALL esSpecRegExpCreate(ExecState*);
+
} // namespace JSC
#endif // RegExpConstructor_h