summaryrefslogtreecommitdiff
path: root/Source/JavaScriptCore/runtime/RegExpConstructor.cpp
diff options
context:
space:
mode:
authorLorry Tar Creator <lorry-tar-importer@lorry>2016-04-10 09:28:39 +0000
committerLorry Tar Creator <lorry-tar-importer@lorry>2016-04-10 09:28:39 +0000
commit32761a6cee1d0dee366b885b7b9c777e67885688 (patch)
treed6bec92bebfb216f4126356e55518842c2f476a1 /Source/JavaScriptCore/runtime/RegExpConstructor.cpp
parenta4e969f4965059196ca948db781e52f7cfebf19e (diff)
downloadWebKitGtk-tarball-32761a6cee1d0dee366b885b7b9c777e67885688.tar.gz
webkitgtk-2.4.11webkitgtk-2.4.11
Diffstat (limited to 'Source/JavaScriptCore/runtime/RegExpConstructor.cpp')
-rw-r--r--Source/JavaScriptCore/runtime/RegExpConstructor.cpp157
1 files changed, 75 insertions, 82 deletions
diff --git a/Source/JavaScriptCore/runtime/RegExpConstructor.cpp b/Source/JavaScriptCore/runtime/RegExpConstructor.cpp
index ca9398a63..bc516b06d 100644
--- a/Source/JavaScriptCore/runtime/RegExpConstructor.cpp
+++ b/Source/JavaScriptCore/runtime/RegExpConstructor.cpp
@@ -1,6 +1,6 @@
/*
* Copyright (C) 1999-2000 Harri Porten (porten@kde.org)
- * Copyright (C) 2003, 2007, 2008, 2016 Apple Inc. All Rights Reserved.
+ * Copyright (C) 2003, 2007, 2008 Apple Inc. All Rights Reserved.
* Copyright (C) 2009 Torch Mobile, Inc.
*
* This library is free software; you can redistribute it and/or
@@ -23,32 +23,30 @@
#include "RegExpConstructor.h"
#include "Error.h"
-#include "GetterSetter.h"
-#include "JSCInlines.h"
+#include "Operations.h"
#include "RegExpMatchesArray.h"
#include "RegExpPrototype.h"
-#include "StructureInlines.h"
namespace JSC {
-static EncodedJSValue regExpConstructorInput(ExecState*, EncodedJSValue, PropertyName);
-static EncodedJSValue regExpConstructorMultiline(ExecState*, EncodedJSValue, PropertyName);
-static EncodedJSValue regExpConstructorLastMatch(ExecState*, EncodedJSValue, PropertyName);
-static EncodedJSValue regExpConstructorLastParen(ExecState*, EncodedJSValue, PropertyName);
-static EncodedJSValue regExpConstructorLeftContext(ExecState*, EncodedJSValue, PropertyName);
-static EncodedJSValue regExpConstructorRightContext(ExecState*, EncodedJSValue, PropertyName);
-static EncodedJSValue regExpConstructorDollar1(ExecState*, EncodedJSValue, PropertyName);
-static EncodedJSValue regExpConstructorDollar2(ExecState*, EncodedJSValue, PropertyName);
-static EncodedJSValue regExpConstructorDollar3(ExecState*, EncodedJSValue, PropertyName);
-static EncodedJSValue regExpConstructorDollar4(ExecState*, EncodedJSValue, PropertyName);
-static EncodedJSValue regExpConstructorDollar5(ExecState*, EncodedJSValue, PropertyName);
-static EncodedJSValue regExpConstructorDollar6(ExecState*, EncodedJSValue, PropertyName);
-static EncodedJSValue regExpConstructorDollar7(ExecState*, EncodedJSValue, PropertyName);
-static EncodedJSValue regExpConstructorDollar8(ExecState*, EncodedJSValue, PropertyName);
-static EncodedJSValue regExpConstructorDollar9(ExecState*, EncodedJSValue, PropertyName);
-
-static void setRegExpConstructorInput(ExecState*, EncodedJSValue, EncodedJSValue);
-static void setRegExpConstructorMultiline(ExecState*, EncodedJSValue, EncodedJSValue);
+static EncodedJSValue regExpConstructorInput(ExecState*, EncodedJSValue, EncodedJSValue, PropertyName);
+static EncodedJSValue regExpConstructorMultiline(ExecState*, EncodedJSValue, EncodedJSValue, PropertyName);
+static EncodedJSValue regExpConstructorLastMatch(ExecState*, EncodedJSValue, EncodedJSValue, PropertyName);
+static EncodedJSValue regExpConstructorLastParen(ExecState*, EncodedJSValue, EncodedJSValue, PropertyName);
+static EncodedJSValue regExpConstructorLeftContext(ExecState*, EncodedJSValue, EncodedJSValue, PropertyName);
+static EncodedJSValue regExpConstructorRightContext(ExecState*, EncodedJSValue, EncodedJSValue, PropertyName);
+static EncodedJSValue regExpConstructorDollar1(ExecState*, EncodedJSValue, EncodedJSValue, PropertyName);
+static EncodedJSValue regExpConstructorDollar2(ExecState*, EncodedJSValue, EncodedJSValue, PropertyName);
+static EncodedJSValue regExpConstructorDollar3(ExecState*, EncodedJSValue, EncodedJSValue, PropertyName);
+static EncodedJSValue regExpConstructorDollar4(ExecState*, EncodedJSValue, EncodedJSValue, PropertyName);
+static EncodedJSValue regExpConstructorDollar5(ExecState*, EncodedJSValue, EncodedJSValue, PropertyName);
+static EncodedJSValue regExpConstructorDollar6(ExecState*, EncodedJSValue, EncodedJSValue, PropertyName);
+static EncodedJSValue regExpConstructorDollar7(ExecState*, EncodedJSValue, EncodedJSValue, PropertyName);
+static EncodedJSValue regExpConstructorDollar8(ExecState*, EncodedJSValue, EncodedJSValue, PropertyName);
+static EncodedJSValue regExpConstructorDollar9(ExecState*, EncodedJSValue, EncodedJSValue, PropertyName);
+
+static void setRegExpConstructorInput(ExecState*, JSObject*, EncodedJSValue, EncodedJSValue);
+static void setRegExpConstructorMultiline(ExecState*, JSObject*, EncodedJSValue, EncodedJSValue);
} // namespace JSC
@@ -56,7 +54,7 @@ static void setRegExpConstructorMultiline(ExecState*, EncodedJSValue, EncodedJSV
namespace JSC {
-const ClassInfo RegExpConstructor::s_info = { "Function", &InternalFunction::s_info, &regExpConstructorTable, CREATE_METHOD_TABLE(RegExpConstructor) };
+const ClassInfo RegExpConstructor::s_info = { "Function", &InternalFunction::s_info, 0, ExecState::regExpConstructorTable, CREATE_METHOD_TABLE(RegExpConstructor) };
/* Source for RegExpConstructor.lut.h
@begin regExpConstructorTable
@@ -91,9 +89,9 @@ RegExpConstructor::RegExpConstructor(VM& vm, Structure* structure, RegExpPrototy
{
}
-void RegExpConstructor::finishCreation(VM& vm, RegExpPrototype* regExpPrototype, GetterSetter* speciesSymbol)
+void RegExpConstructor::finishCreation(VM& vm, RegExpPrototype* regExpPrototype)
{
- Base::finishCreation(vm, regExpPrototype->classInfo()->className);
+ Base::finishCreation(vm, Identifier(&vm, "RegExp").string());
ASSERT(inherits(info()));
// ECMA 15.10.5.1 RegExp.prototype
@@ -101,8 +99,6 @@ void RegExpConstructor::finishCreation(VM& vm, RegExpPrototype* regExpPrototype,
// no. of arguments for constructor
putDirectWithoutTransition(vm, vm.propertyNames->length, jsNumber(2), ReadOnly | DontDelete | DontEnum);
-
- putDirectNonIndexAccessor(vm, vm.propertyNames->speciesSymbol, speciesSymbol, Accessor | ReadOnly | DontEnum);
}
void RegExpConstructor::destroy(JSCell* cell)
@@ -114,13 +110,16 @@ void RegExpConstructor::visitChildren(JSCell* cell, SlotVisitor& visitor)
{
RegExpConstructor* thisObject = jsCast<RegExpConstructor*>(cell);
ASSERT_GC_OBJECT_INHERITS(thisObject, info());
+ COMPILE_ASSERT(StructureFlags & OverridesVisitChildren, OverridesVisitChildrenWithoutSettingFlag);
+ ASSERT(thisObject->structure()->typeInfo().overridesVisitChildren());
+
Base::visitChildren(thisObject, visitor);
thisObject->m_cachedResult.visitChildren(visitor);
}
JSValue RegExpConstructor::getBackref(ExecState* exec, unsigned i)
{
- JSArray* array = m_cachedResult.lastResult(exec, this);
+ RegExpMatchesArray* array = m_cachedResult.lastResult(exec, this);
if (i < array->length()) {
JSValue result = JSValue(array).get(exec, i);
@@ -133,7 +132,7 @@ JSValue RegExpConstructor::getBackref(ExecState* exec, unsigned i)
JSValue RegExpConstructor::getLastParen(ExecState* exec)
{
- JSArray* array = m_cachedResult.lastResult(exec, this);
+ RegExpMatchesArray* array = m_cachedResult.lastResult(exec, this);
unsigned length = array->length();
if (length > 1) {
JSValue result = JSValue(array).get(exec, length - 1);
@@ -146,117 +145,113 @@ JSValue RegExpConstructor::getLastParen(ExecState* exec)
JSValue RegExpConstructor::getLeftContext(ExecState* exec)
{
- return m_cachedResult.leftContext(exec, this);
+ return m_cachedResult.lastResult(exec, this)->leftContext(exec);
}
JSValue RegExpConstructor::getRightContext(ExecState* exec)
{
- return m_cachedResult.rightContext(exec, this);
+ return m_cachedResult.lastResult(exec, this)->rightContext(exec);
}
bool RegExpConstructor::getOwnPropertySlot(JSObject* object, ExecState* exec, PropertyName propertyName, PropertySlot& slot)
{
- return getStaticValueSlot<RegExpConstructor, InternalFunction>(exec, regExpConstructorTable, jsCast<RegExpConstructor*>(object), propertyName, slot);
+ return getStaticValueSlot<RegExpConstructor, InternalFunction>(exec, ExecState::regExpConstructorTable(exec->vm()), jsCast<RegExpConstructor*>(object), propertyName, slot);
+}
+
+static inline RegExpConstructor* asRegExpConstructor(EncodedJSValue value)
+{
+ return jsCast<RegExpConstructor*>(JSValue::decode(value));
}
-EncodedJSValue regExpConstructorDollar1(ExecState* exec, EncodedJSValue thisValue, PropertyName)
+EncodedJSValue regExpConstructorDollar1(ExecState* exec, EncodedJSValue slotBase, EncodedJSValue, PropertyName)
{
- return JSValue::encode(asRegExpConstructor(JSValue::decode(thisValue))->getBackref(exec, 1));
+ return JSValue::encode(asRegExpConstructor(slotBase)->getBackref(exec, 1));
}
-EncodedJSValue regExpConstructorDollar2(ExecState* exec, EncodedJSValue thisValue, PropertyName)
+EncodedJSValue regExpConstructorDollar2(ExecState* exec, EncodedJSValue slotBase, EncodedJSValue, PropertyName)
{
- return JSValue::encode(asRegExpConstructor(JSValue::decode(thisValue))->getBackref(exec, 2));
+ return JSValue::encode(asRegExpConstructor(slotBase)->getBackref(exec, 2));
}
-EncodedJSValue regExpConstructorDollar3(ExecState* exec, EncodedJSValue thisValue, PropertyName)
+EncodedJSValue regExpConstructorDollar3(ExecState* exec, EncodedJSValue slotBase, EncodedJSValue, PropertyName)
{
- return JSValue::encode(asRegExpConstructor(JSValue::decode(thisValue))->getBackref(exec, 3));
+ return JSValue::encode(asRegExpConstructor(slotBase)->getBackref(exec, 3));
}
-EncodedJSValue regExpConstructorDollar4(ExecState* exec, EncodedJSValue thisValue, PropertyName)
+EncodedJSValue regExpConstructorDollar4(ExecState* exec, EncodedJSValue slotBase, EncodedJSValue, PropertyName)
{
- return JSValue::encode(asRegExpConstructor(JSValue::decode(thisValue))->getBackref(exec, 4));
+ return JSValue::encode(asRegExpConstructor(slotBase)->getBackref(exec, 4));
}
-EncodedJSValue regExpConstructorDollar5(ExecState* exec, EncodedJSValue thisValue, PropertyName)
+EncodedJSValue regExpConstructorDollar5(ExecState* exec, EncodedJSValue slotBase, EncodedJSValue, PropertyName)
{
- return JSValue::encode(asRegExpConstructor(JSValue::decode(thisValue))->getBackref(exec, 5));
+ return JSValue::encode(asRegExpConstructor(slotBase)->getBackref(exec, 5));
}
-EncodedJSValue regExpConstructorDollar6(ExecState* exec, EncodedJSValue thisValue, PropertyName)
+EncodedJSValue regExpConstructorDollar6(ExecState* exec, EncodedJSValue slotBase, EncodedJSValue, PropertyName)
{
- return JSValue::encode(asRegExpConstructor(JSValue::decode(thisValue))->getBackref(exec, 6));
+ return JSValue::encode(asRegExpConstructor(slotBase)->getBackref(exec, 6));
}
-EncodedJSValue regExpConstructorDollar7(ExecState* exec, EncodedJSValue thisValue, PropertyName)
+EncodedJSValue regExpConstructorDollar7(ExecState* exec, EncodedJSValue slotBase, EncodedJSValue, PropertyName)
{
- return JSValue::encode(asRegExpConstructor(JSValue::decode(thisValue))->getBackref(exec, 7));
+ return JSValue::encode(asRegExpConstructor(slotBase)->getBackref(exec, 7));
}
-EncodedJSValue regExpConstructorDollar8(ExecState* exec, EncodedJSValue thisValue, PropertyName)
+EncodedJSValue regExpConstructorDollar8(ExecState* exec, EncodedJSValue slotBase, EncodedJSValue, PropertyName)
{
- return JSValue::encode(asRegExpConstructor(JSValue::decode(thisValue))->getBackref(exec, 8));
+ return JSValue::encode(asRegExpConstructor(slotBase)->getBackref(exec, 8));
}
-EncodedJSValue regExpConstructorDollar9(ExecState* exec, EncodedJSValue thisValue, PropertyName)
+EncodedJSValue regExpConstructorDollar9(ExecState* exec, EncodedJSValue slotBase, EncodedJSValue, PropertyName)
{
- return JSValue::encode(asRegExpConstructor(JSValue::decode(thisValue))->getBackref(exec, 9));
+ return JSValue::encode(asRegExpConstructor(slotBase)->getBackref(exec, 9));
}
-EncodedJSValue regExpConstructorInput(ExecState*, EncodedJSValue thisValue, PropertyName)
+EncodedJSValue regExpConstructorInput(ExecState*, EncodedJSValue slotBase, EncodedJSValue, PropertyName)
{
- return JSValue::encode(asRegExpConstructor(JSValue::decode(thisValue))->input());
+ return JSValue::encode(asRegExpConstructor(slotBase)->input());
}
-EncodedJSValue regExpConstructorMultiline(ExecState*, EncodedJSValue thisValue, PropertyName)
+EncodedJSValue regExpConstructorMultiline(ExecState*, EncodedJSValue slotBase, EncodedJSValue, PropertyName)
{
- return JSValue::encode(jsBoolean(asRegExpConstructor(JSValue::decode(thisValue))->multiline()));
+ return JSValue::encode(jsBoolean(asRegExpConstructor(slotBase)->multiline()));
}
-EncodedJSValue regExpConstructorLastMatch(ExecState* exec, EncodedJSValue thisValue, PropertyName)
+EncodedJSValue regExpConstructorLastMatch(ExecState* exec, EncodedJSValue slotBase, EncodedJSValue, PropertyName)
{
- return JSValue::encode(asRegExpConstructor(JSValue::decode(thisValue))->getBackref(exec, 0));
+ return JSValue::encode(asRegExpConstructor(slotBase)->getBackref(exec, 0));
}
-EncodedJSValue regExpConstructorLastParen(ExecState* exec, EncodedJSValue thisValue, PropertyName)
+EncodedJSValue regExpConstructorLastParen(ExecState* exec, EncodedJSValue slotBase, EncodedJSValue, PropertyName)
{
- return JSValue::encode(asRegExpConstructor(JSValue::decode(thisValue))->getLastParen(exec));
+ return JSValue::encode(asRegExpConstructor(slotBase)->getLastParen(exec));
}
-EncodedJSValue regExpConstructorLeftContext(ExecState* exec, EncodedJSValue thisValue, PropertyName)
+EncodedJSValue regExpConstructorLeftContext(ExecState* exec, EncodedJSValue slotBase, EncodedJSValue, PropertyName)
{
- return JSValue::encode(asRegExpConstructor(JSValue::decode(thisValue))->getLeftContext(exec));
+ return JSValue::encode(asRegExpConstructor(slotBase)->getLeftContext(exec));
}
-EncodedJSValue regExpConstructorRightContext(ExecState* exec, EncodedJSValue thisValue, PropertyName)
+EncodedJSValue regExpConstructorRightContext(ExecState* exec, EncodedJSValue slotBase, EncodedJSValue, PropertyName)
{
- return JSValue::encode(asRegExpConstructor(JSValue::decode(thisValue))->getRightContext(exec));
+ return JSValue::encode(asRegExpConstructor(slotBase)->getRightContext(exec));
}
-void setRegExpConstructorInput(ExecState* exec, EncodedJSValue thisValue, EncodedJSValue value)
+void setRegExpConstructorInput(ExecState* exec, JSObject* baseObject, EncodedJSValue, EncodedJSValue value)
{
- if (auto constructor = jsDynamicCast<RegExpConstructor*>(JSValue::decode(thisValue)))
+ if (auto constructor = jsDynamicCast<RegExpConstructor*>(baseObject))
constructor->setInput(exec, JSValue::decode(value).toString(exec));
}
-void setRegExpConstructorMultiline(ExecState* exec, EncodedJSValue thisValue, EncodedJSValue value)
+void setRegExpConstructorMultiline(ExecState* exec, JSObject* baseObject, EncodedJSValue, EncodedJSValue value)
{
- if (auto constructor = jsDynamicCast<RegExpConstructor*>(JSValue::decode(thisValue)))
+ if (auto constructor = jsDynamicCast<RegExpConstructor*>(baseObject))
constructor->setMultiline(JSValue::decode(value).toBoolean(exec));
}
-inline Structure* getRegExpStructure(ExecState* exec, JSGlobalObject* globalObject, JSValue newTarget)
-{
- Structure* structure = globalObject->regExpStructure();
- if (newTarget != jsUndefined()) {
- structure = InternalFunction::createSubclassStructure(exec, newTarget, structure);
- }
- return structure;
-}
-
// ECMA 15.10.4
-JSObject* constructRegExp(ExecState* exec, JSGlobalObject* globalObject, const ArgList& args, JSValue newTarget)
+JSObject* constructRegExp(ExecState* exec, JSGlobalObject* globalObject, const ArgList& args, bool callAsConstructor)
{
JSValue arg0 = args.at(0);
JSValue arg1 = args.at(1);
@@ -265,10 +260,9 @@ JSObject* constructRegExp(ExecState* exec, JSGlobalObject* globalObject, const A
if (!arg1.isUndefined())
return exec->vm().throwException(exec, createTypeError(exec, ASCIILiteral("Cannot supply flags when constructing one RegExp from another.")));
// If called as a function, this just returns the first argument (see 15.10.3.1).
- if (newTarget != jsUndefined()) {
+ if (callAsConstructor) {
RegExp* regExp = static_cast<RegExpObject*>(asObject(arg0))->regExp();
-
- return RegExpObject::create(exec->vm(), getRegExpStructure(exec, globalObject, newTarget), regExp);
+ return RegExpObject::create(exec->vm(), globalObject->regExpStructure(), regExp);
}
return asObject(arg0);
}
@@ -290,14 +284,13 @@ JSObject* constructRegExp(ExecState* exec, JSGlobalObject* globalObject, const A
RegExp* regExp = RegExp::create(vm, pattern, flags);
if (!regExp->isValid())
return vm.throwException(exec, createSyntaxError(exec, regExp->errorMessage()));
-
- return RegExpObject::create(vm, getRegExpStructure(exec, globalObject, newTarget), regExp);
+ return RegExpObject::create(vm, globalObject->regExpStructure(), regExp);
}
static EncodedJSValue JSC_HOST_CALL constructWithRegExpConstructor(ExecState* exec)
{
ArgList args(exec);
- return JSValue::encode(constructRegExp(exec, asInternalFunction(exec->callee())->globalObject(), args, exec->newTarget()));
+ return JSValue::encode(constructRegExp(exec, asInternalFunction(exec->callee())->globalObject(), args, true));
}
ConstructType RegExpConstructor::getConstructData(JSCell*, ConstructData& constructData)