diff options
| author | Lorry Tar Creator <lorry-tar-importer@lorry> | 2016-05-24 08:28:08 +0000 |
|---|---|---|
| committer | Lorry Tar Creator <lorry-tar-importer@lorry> | 2016-05-24 08:28:08 +0000 |
| commit | a4e969f4965059196ca948db781e52f7cfebf19e (patch) | |
| tree | 6ca352808c8fdc52006a0f33f6ae3c593b23867d /Source/JavaScriptCore/runtime/RegExpConstructor.cpp | |
| parent | 41386e9cb918eed93b3f13648cbef387e371e451 (diff) | |
| download | WebKitGtk-tarball-a4e969f4965059196ca948db781e52f7cfebf19e.tar.gz | |
webkitgtk-2.12.3webkitgtk-2.12.3
Diffstat (limited to 'Source/JavaScriptCore/runtime/RegExpConstructor.cpp')
| -rw-r--r-- | Source/JavaScriptCore/runtime/RegExpConstructor.cpp | 157 |
1 files changed, 82 insertions, 75 deletions
diff --git a/Source/JavaScriptCore/runtime/RegExpConstructor.cpp b/Source/JavaScriptCore/runtime/RegExpConstructor.cpp index bc516b06d..ca9398a63 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 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 @@ -23,30 +23,32 @@ #include "RegExpConstructor.h" #include "Error.h" -#include "Operations.h" +#include "GetterSetter.h" +#include "JSCInlines.h" #include "RegExpMatchesArray.h" #include "RegExpPrototype.h" +#include "StructureInlines.h" namespace JSC { -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); +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); } // namespace JSC @@ -54,7 +56,7 @@ static void setRegExpConstructorMultiline(ExecState*, JSObject*, EncodedJSValue, namespace JSC { -const ClassInfo RegExpConstructor::s_info = { "Function", &InternalFunction::s_info, 0, ExecState::regExpConstructorTable, CREATE_METHOD_TABLE(RegExpConstructor) }; +const ClassInfo RegExpConstructor::s_info = { "Function", &InternalFunction::s_info, ®ExpConstructorTable, CREATE_METHOD_TABLE(RegExpConstructor) }; /* Source for RegExpConstructor.lut.h @begin regExpConstructorTable @@ -89,9 +91,9 @@ RegExpConstructor::RegExpConstructor(VM& vm, Structure* structure, RegExpPrototy { } -void RegExpConstructor::finishCreation(VM& vm, RegExpPrototype* regExpPrototype) +void RegExpConstructor::finishCreation(VM& vm, RegExpPrototype* regExpPrototype, GetterSetter* speciesSymbol) { - Base::finishCreation(vm, Identifier(&vm, "RegExp").string()); + Base::finishCreation(vm, regExpPrototype->classInfo()->className); ASSERT(inherits(info())); // ECMA 15.10.5.1 RegExp.prototype @@ -99,6 +101,8 @@ 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) @@ -110,16 +114,13 @@ 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) { - RegExpMatchesArray* array = m_cachedResult.lastResult(exec, this); + JSArray* array = m_cachedResult.lastResult(exec, this); if (i < array->length()) { JSValue result = JSValue(array).get(exec, i); @@ -132,7 +133,7 @@ JSValue RegExpConstructor::getBackref(ExecState* exec, unsigned i) JSValue RegExpConstructor::getLastParen(ExecState* exec) { - RegExpMatchesArray* array = m_cachedResult.lastResult(exec, this); + JSArray* array = m_cachedResult.lastResult(exec, this); unsigned length = array->length(); if (length > 1) { JSValue result = JSValue(array).get(exec, length - 1); @@ -145,113 +146,117 @@ JSValue RegExpConstructor::getLastParen(ExecState* exec) JSValue RegExpConstructor::getLeftContext(ExecState* exec) { - return m_cachedResult.lastResult(exec, this)->leftContext(exec); + return m_cachedResult.leftContext(exec, this); } JSValue RegExpConstructor::getRightContext(ExecState* exec) { - return m_cachedResult.lastResult(exec, this)->rightContext(exec); + return m_cachedResult.rightContext(exec, this); } bool RegExpConstructor::getOwnPropertySlot(JSObject* object, ExecState* exec, PropertyName propertyName, PropertySlot& 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)); + return getStaticValueSlot<RegExpConstructor, InternalFunction>(exec, regExpConstructorTable, jsCast<RegExpConstructor*>(object), propertyName, slot); } -EncodedJSValue regExpConstructorDollar1(ExecState* exec, EncodedJSValue slotBase, EncodedJSValue, PropertyName) +EncodedJSValue regExpConstructorDollar1(ExecState* exec, EncodedJSValue thisValue, PropertyName) { - return JSValue::encode(asRegExpConstructor(slotBase)->getBackref(exec, 1)); + return JSValue::encode(asRegExpConstructor(JSValue::decode(thisValue))->getBackref(exec, 1)); } -EncodedJSValue regExpConstructorDollar2(ExecState* exec, EncodedJSValue slotBase, EncodedJSValue, PropertyName) +EncodedJSValue regExpConstructorDollar2(ExecState* exec, EncodedJSValue thisValue, PropertyName) { - return JSValue::encode(asRegExpConstructor(slotBase)->getBackref(exec, 2)); + return JSValue::encode(asRegExpConstructor(JSValue::decode(thisValue))->getBackref(exec, 2)); } -EncodedJSValue regExpConstructorDollar3(ExecState* exec, EncodedJSValue slotBase, EncodedJSValue, PropertyName) +EncodedJSValue regExpConstructorDollar3(ExecState* exec, EncodedJSValue thisValue, PropertyName) { - return JSValue::encode(asRegExpConstructor(slotBase)->getBackref(exec, 3)); + return JSValue::encode(asRegExpConstructor(JSValue::decode(thisValue))->getBackref(exec, 3)); } -EncodedJSValue regExpConstructorDollar4(ExecState* exec, EncodedJSValue slotBase, EncodedJSValue, PropertyName) +EncodedJSValue regExpConstructorDollar4(ExecState* exec, EncodedJSValue thisValue, PropertyName) { - return JSValue::encode(asRegExpConstructor(slotBase)->getBackref(exec, 4)); + return JSValue::encode(asRegExpConstructor(JSValue::decode(thisValue))->getBackref(exec, 4)); } -EncodedJSValue regExpConstructorDollar5(ExecState* exec, EncodedJSValue slotBase, EncodedJSValue, PropertyName) +EncodedJSValue regExpConstructorDollar5(ExecState* exec, EncodedJSValue thisValue, PropertyName) { - return JSValue::encode(asRegExpConstructor(slotBase)->getBackref(exec, 5)); + return JSValue::encode(asRegExpConstructor(JSValue::decode(thisValue))->getBackref(exec, 5)); } -EncodedJSValue regExpConstructorDollar6(ExecState* exec, EncodedJSValue slotBase, EncodedJSValue, PropertyName) +EncodedJSValue regExpConstructorDollar6(ExecState* exec, EncodedJSValue thisValue, PropertyName) { - return JSValue::encode(asRegExpConstructor(slotBase)->getBackref(exec, 6)); + return JSValue::encode(asRegExpConstructor(JSValue::decode(thisValue))->getBackref(exec, 6)); } -EncodedJSValue regExpConstructorDollar7(ExecState* exec, EncodedJSValue slotBase, EncodedJSValue, PropertyName) +EncodedJSValue regExpConstructorDollar7(ExecState* exec, EncodedJSValue thisValue, PropertyName) { - return JSValue::encode(asRegExpConstructor(slotBase)->getBackref(exec, 7)); + return JSValue::encode(asRegExpConstructor(JSValue::decode(thisValue))->getBackref(exec, 7)); } -EncodedJSValue regExpConstructorDollar8(ExecState* exec, EncodedJSValue slotBase, EncodedJSValue, PropertyName) +EncodedJSValue regExpConstructorDollar8(ExecState* exec, EncodedJSValue thisValue, PropertyName) { - return JSValue::encode(asRegExpConstructor(slotBase)->getBackref(exec, 8)); + return JSValue::encode(asRegExpConstructor(JSValue::decode(thisValue))->getBackref(exec, 8)); } -EncodedJSValue regExpConstructorDollar9(ExecState* exec, EncodedJSValue slotBase, EncodedJSValue, PropertyName) +EncodedJSValue regExpConstructorDollar9(ExecState* exec, EncodedJSValue thisValue, PropertyName) { - return JSValue::encode(asRegExpConstructor(slotBase)->getBackref(exec, 9)); + return JSValue::encode(asRegExpConstructor(JSValue::decode(thisValue))->getBackref(exec, 9)); } -EncodedJSValue regExpConstructorInput(ExecState*, EncodedJSValue slotBase, EncodedJSValue, PropertyName) +EncodedJSValue regExpConstructorInput(ExecState*, EncodedJSValue thisValue, PropertyName) { - return JSValue::encode(asRegExpConstructor(slotBase)->input()); + return JSValue::encode(asRegExpConstructor(JSValue::decode(thisValue))->input()); } -EncodedJSValue regExpConstructorMultiline(ExecState*, EncodedJSValue slotBase, EncodedJSValue, PropertyName) +EncodedJSValue regExpConstructorMultiline(ExecState*, EncodedJSValue thisValue, PropertyName) { - return JSValue::encode(jsBoolean(asRegExpConstructor(slotBase)->multiline())); + return JSValue::encode(jsBoolean(asRegExpConstructor(JSValue::decode(thisValue))->multiline())); } -EncodedJSValue regExpConstructorLastMatch(ExecState* exec, EncodedJSValue slotBase, EncodedJSValue, PropertyName) +EncodedJSValue regExpConstructorLastMatch(ExecState* exec, EncodedJSValue thisValue, PropertyName) { - return JSValue::encode(asRegExpConstructor(slotBase)->getBackref(exec, 0)); + return JSValue::encode(asRegExpConstructor(JSValue::decode(thisValue))->getBackref(exec, 0)); } -EncodedJSValue regExpConstructorLastParen(ExecState* exec, EncodedJSValue slotBase, EncodedJSValue, PropertyName) +EncodedJSValue regExpConstructorLastParen(ExecState* exec, EncodedJSValue thisValue, PropertyName) { - return JSValue::encode(asRegExpConstructor(slotBase)->getLastParen(exec)); + return JSValue::encode(asRegExpConstructor(JSValue::decode(thisValue))->getLastParen(exec)); } -EncodedJSValue regExpConstructorLeftContext(ExecState* exec, EncodedJSValue slotBase, EncodedJSValue, PropertyName) +EncodedJSValue regExpConstructorLeftContext(ExecState* exec, EncodedJSValue thisValue, PropertyName) { - return JSValue::encode(asRegExpConstructor(slotBase)->getLeftContext(exec)); + return JSValue::encode(asRegExpConstructor(JSValue::decode(thisValue))->getLeftContext(exec)); } -EncodedJSValue regExpConstructorRightContext(ExecState* exec, EncodedJSValue slotBase, EncodedJSValue, PropertyName) +EncodedJSValue regExpConstructorRightContext(ExecState* exec, EncodedJSValue thisValue, PropertyName) { - return JSValue::encode(asRegExpConstructor(slotBase)->getRightContext(exec)); + return JSValue::encode(asRegExpConstructor(JSValue::decode(thisValue))->getRightContext(exec)); } -void setRegExpConstructorInput(ExecState* exec, JSObject* baseObject, EncodedJSValue, EncodedJSValue value) +void setRegExpConstructorInput(ExecState* exec, EncodedJSValue thisValue, EncodedJSValue value) { - if (auto constructor = jsDynamicCast<RegExpConstructor*>(baseObject)) + if (auto constructor = jsDynamicCast<RegExpConstructor*>(JSValue::decode(thisValue))) constructor->setInput(exec, JSValue::decode(value).toString(exec)); } -void setRegExpConstructorMultiline(ExecState* exec, JSObject* baseObject, EncodedJSValue, EncodedJSValue value) +void setRegExpConstructorMultiline(ExecState* exec, EncodedJSValue thisValue, EncodedJSValue value) { - if (auto constructor = jsDynamicCast<RegExpConstructor*>(baseObject)) + if (auto constructor = jsDynamicCast<RegExpConstructor*>(JSValue::decode(thisValue))) 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, bool callAsConstructor) +JSObject* constructRegExp(ExecState* exec, JSGlobalObject* globalObject, const ArgList& args, JSValue newTarget) { JSValue arg0 = args.at(0); JSValue arg1 = args.at(1); @@ -260,9 +265,10 @@ 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 (callAsConstructor) { + if (newTarget != jsUndefined()) { RegExp* regExp = static_cast<RegExpObject*>(asObject(arg0))->regExp(); - return RegExpObject::create(exec->vm(), globalObject->regExpStructure(), regExp); + + return RegExpObject::create(exec->vm(), getRegExpStructure(exec, globalObject, newTarget), regExp); } return asObject(arg0); } @@ -284,13 +290,14 @@ 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, globalObject->regExpStructure(), regExp); + + return RegExpObject::create(vm, getRegExpStructure(exec, globalObject, newTarget), regExp); } static EncodedJSValue JSC_HOST_CALL constructWithRegExpConstructor(ExecState* exec) { ArgList args(exec); - return JSValue::encode(constructRegExp(exec, asInternalFunction(exec->callee())->globalObject(), args, true)); + return JSValue::encode(constructRegExp(exec, asInternalFunction(exec->callee())->globalObject(), args, exec->newTarget())); } ConstructType RegExpConstructor::getConstructData(JSCell*, ConstructData& constructData) |
