]> git.saurik.com Git - apple/javascriptcore.git/blobdiff - runtime/RegExpConstructor.cpp
JavaScriptCore-7601.1.46.3.tar.gz
[apple/javascriptcore.git] / runtime / RegExpConstructor.cpp
index ee67bc629ececb28ed5a7cf2f6f57cbd718dc957..ee1d8b3fc69f943b94a5259cf7c186cac6373f74 100644 (file)
 #include "RegExpConstructor.h"
 
 #include "Error.h"
 #include "RegExpConstructor.h"
 
 #include "Error.h"
-#include "Operations.h"
+#include "JSCInlines.h"
 #include "RegExpMatchesArray.h"
 #include "RegExpPrototype.h"
 
 #include "RegExpMatchesArray.h"
 #include "RegExpPrototype.h"
 
-#if PLATFORM(IOS)
-#include <wtf/PassOwnPtr.h>
-#endif
-
 namespace JSC {
 
 namespace JSC {
 
-static JSValue regExpConstructorInput(ExecState*, JSValue, PropertyName);
-static JSValue regExpConstructorMultiline(ExecState*, JSValue, PropertyName);
-static JSValue regExpConstructorLastMatch(ExecState*, JSValue, PropertyName);
-static JSValue regExpConstructorLastParen(ExecState*, JSValue, PropertyName);
-static JSValue regExpConstructorLeftContext(ExecState*, JSValue, PropertyName);
-static JSValue regExpConstructorRightContext(ExecState*, JSValue, PropertyName);
-static JSValue regExpConstructorDollar1(ExecState*, JSValue, PropertyName);
-static JSValue regExpConstructorDollar2(ExecState*, JSValue, PropertyName);
-static JSValue regExpConstructorDollar3(ExecState*, JSValue, PropertyName);
-static JSValue regExpConstructorDollar4(ExecState*, JSValue, PropertyName);
-static JSValue regExpConstructorDollar5(ExecState*, JSValue, PropertyName);
-static JSValue regExpConstructorDollar6(ExecState*, JSValue, PropertyName);
-static JSValue regExpConstructorDollar7(ExecState*, JSValue, PropertyName);
-static JSValue regExpConstructorDollar8(ExecState*, JSValue, PropertyName);
-static JSValue regExpConstructorDollar9(ExecState*, JSValue, PropertyName);
-
-static void setRegExpConstructorInput(ExecState*, JSObject*, JSValue);
-static void setRegExpConstructorMultiline(ExecState*, JSObject*, JSValue);
+static EncodedJSValue regExpConstructorInput(ExecState*, JSObject*, EncodedJSValue, PropertyName);
+static EncodedJSValue regExpConstructorMultiline(ExecState*, JSObject*, EncodedJSValue, PropertyName);
+static EncodedJSValue regExpConstructorLastMatch(ExecState*, JSObject*, EncodedJSValue, PropertyName);
+static EncodedJSValue regExpConstructorLastParen(ExecState*, JSObject*, EncodedJSValue, PropertyName);
+static EncodedJSValue regExpConstructorLeftContext(ExecState*, JSObject*, EncodedJSValue, PropertyName);
+static EncodedJSValue regExpConstructorRightContext(ExecState*, JSObject*, EncodedJSValue, PropertyName);
+static EncodedJSValue regExpConstructorDollar1(ExecState*, JSObject*, EncodedJSValue, PropertyName);
+static EncodedJSValue regExpConstructorDollar2(ExecState*, JSObject*, EncodedJSValue, PropertyName);
+static EncodedJSValue regExpConstructorDollar3(ExecState*, JSObject*, EncodedJSValue, PropertyName);
+static EncodedJSValue regExpConstructorDollar4(ExecState*, JSObject*, EncodedJSValue, PropertyName);
+static EncodedJSValue regExpConstructorDollar5(ExecState*, JSObject*, EncodedJSValue, PropertyName);
+static EncodedJSValue regExpConstructorDollar6(ExecState*, JSObject*, EncodedJSValue, PropertyName);
+static EncodedJSValue regExpConstructorDollar7(ExecState*, JSObject*, EncodedJSValue, PropertyName);
+static EncodedJSValue regExpConstructorDollar8(ExecState*, JSObject*, EncodedJSValue, PropertyName);
+static EncodedJSValue regExpConstructorDollar9(ExecState*, JSObject*, EncodedJSValue, PropertyName);
+
+static void setRegExpConstructorInput(ExecState*, JSObject*, EncodedJSValue, EncodedJSValue);
+static void setRegExpConstructorMultiline(ExecState*, JSObject*, EncodedJSValue, EncodedJSValue);
 
 } // namespace JSC
 
 
 } // namespace JSC
 
@@ -58,7 +54,7 @@ static void setRegExpConstructorMultiline(ExecState*, JSObject*, JSValue);
 
 namespace JSC {
 
 
 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, &regExpConstructorTable, CREATE_METHOD_TABLE(RegExpConstructor) };
 
 /* Source for RegExpConstructor.lut.h
 @begin regExpConstructorTable
 
 /* Source for RegExpConstructor.lut.h
 @begin regExpConstructorTable
@@ -86,23 +82,23 @@ const ClassInfo RegExpConstructor::s_info = { "Function", &InternalFunction::s_i
 @end
 */
 
 @end
 */
 
-RegExpConstructor::RegExpConstructor(JSGlobalObject* globalObject, Structure* structure, RegExpPrototype* regExpPrototype)
-    : InternalFunction(globalObject, structure)
-    , m_cachedResult(globalObject->vm(), this, regExpPrototype->regExp())
+RegExpConstructor::RegExpConstructor(VM& vm, Structure* structure, RegExpPrototype* regExpPrototype)
+    : InternalFunction(vm, structure)
+    , m_cachedResult(vm, this, regExpPrototype->regExp())
     , m_multiline(false)
 {
 }
 
     , m_multiline(false)
 {
 }
 
-void RegExpConstructor::finishCreation(ExecState* exec, RegExpPrototype* regExpPrototype)
+void RegExpConstructor::finishCreation(VM& vm, RegExpPrototype* regExpPrototype)
 {
 {
-    Base::finishCreation(exec->vm(), Identifier(exec, "RegExp").string());
-    ASSERT(inherits(&s_info));
+    Base::finishCreation(vm, regExpPrototype->classInfo()->className);
+    ASSERT(inherits(info()));
 
     // ECMA 15.10.5.1 RegExp.prototype
 
     // ECMA 15.10.5.1 RegExp.prototype
-    putDirectWithoutTransition(exec->vm(), exec->propertyNames().prototype, regExpPrototype, DontEnum | DontDelete | ReadOnly);
+    putDirectWithoutTransition(vm, vm.propertyNames->prototype, regExpPrototype, DontEnum | DontDelete | ReadOnly);
 
     // no. of arguments for constructor
 
     // no. of arguments for constructor
-    putDirectWithoutTransition(exec->vm(), exec->propertyNames().length, jsNumber(2), ReadOnly | DontDelete | DontEnum);
+    putDirectWithoutTransition(vm, vm.propertyNames->length, jsNumber(2), ReadOnly | DontDelete | DontEnum);
 }
 
 void RegExpConstructor::destroy(JSCell* cell)
 }
 
 void RegExpConstructor::destroy(JSCell* cell)
@@ -113,17 +109,14 @@ void RegExpConstructor::destroy(JSCell* cell)
 void RegExpConstructor::visitChildren(JSCell* cell, SlotVisitor& visitor)
 {
     RegExpConstructor* thisObject = jsCast<RegExpConstructor*>(cell);
 void RegExpConstructor::visitChildren(JSCell* cell, SlotVisitor& visitor)
 {
     RegExpConstructor* thisObject = jsCast<RegExpConstructor*>(cell);
-    ASSERT_GC_OBJECT_INHERITS(thisObject, &s_info);
-    COMPILE_ASSERT(StructureFlags & OverridesVisitChildren, OverridesVisitChildrenWithoutSettingFlag);
-    ASSERT(thisObject->structure()->typeInfo().overridesVisitChildren());
-
+    ASSERT_GC_OBJECT_INHERITS(thisObject, info());
     Base::visitChildren(thisObject, visitor);
     thisObject->m_cachedResult.visitChildren(visitor);
 }
 
 JSValue RegExpConstructor::getBackref(ExecState* exec, unsigned i)
 {
     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);
 
     if (i < array->length()) {
         JSValue result = JSValue(array).get(exec, i);
@@ -136,7 +129,7 @@ JSValue RegExpConstructor::getBackref(ExecState* exec, unsigned i)
 
 JSValue RegExpConstructor::getLastParen(ExecState* exec)
 {
 
 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);
     unsigned length = array->length();
     if (length > 1) {
         JSValue result = JSValue(array).get(exec, length - 1);
@@ -149,112 +142,104 @@ JSValue RegExpConstructor::getLastParen(ExecState* exec)
 
 JSValue RegExpConstructor::getLeftContext(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)
 {
 }
 
 JSValue RegExpConstructor::getRightContext(ExecState* exec)
 {
-    return m_cachedResult.lastResult(exec, this)->rightContext(exec);
+    return m_cachedResult.rightContext(exec, this);
 }
     
 }
     
-bool RegExpConstructor::getOwnPropertySlot(JSCell* cell, ExecState* exec, PropertyName propertyName, PropertySlot& slot)
-{
-    return getStaticValueSlot<RegExpConstructor, InternalFunction>(exec, ExecState::regExpConstructorTable(exec), jsCast<RegExpConstructor*>(cell), propertyName, slot);
-}
-
-bool RegExpConstructor::getOwnPropertyDescriptor(JSObject* object, ExecState* exec, PropertyName propertyName, PropertyDescriptor& descriptor)
+bool RegExpConstructor::getOwnPropertySlot(JSObject* object, ExecState* exec, PropertyName propertyName, PropertySlot& slot)
 {
 {
-    return getStaticValueDescriptor<RegExpConstructor, InternalFunction>(exec, ExecState::regExpConstructorTable(exec), jsCast<RegExpConstructor*>(object), propertyName, descriptor);
+    return getStaticValueSlot<RegExpConstructor, InternalFunction>(exec, regExpConstructorTable, jsCast<RegExpConstructor*>(object), propertyName, slot);
 }
 }
-
-JSValue regExpConstructorDollar1(ExecState* exec, JSValue slotBase, PropertyName)
-{
-    return asRegExpConstructor(slotBase)->getBackref(exec, 1);
-}
-
-JSValue regExpConstructorDollar2(ExecState* exec, JSValue slotBase, PropertyName)
+    
+EncodedJSValue regExpConstructorDollar1(ExecState* exec, JSObject* slotBase, EncodedJSValue, PropertyName)
 {
 {
-    return asRegExpConstructor(slotBase)->getBackref(exec, 2);
+    return JSValue::encode(asRegExpConstructor(slotBase)->getBackref(exec, 1));
 }
 
 }
 
-JSValue regExpConstructorDollar3(ExecState* exec, JSValue slotBase, PropertyName)
+EncodedJSValue regExpConstructorDollar2(ExecState* exec, JSObject* slotBase, EncodedJSValue, PropertyName)
 {
 {
-    return asRegExpConstructor(slotBase)->getBackref(exec, 3);
+    return JSValue::encode(asRegExpConstructor(slotBase)->getBackref(exec, 2));
 }
 
 }
 
-JSValue regExpConstructorDollar4(ExecState* exec, JSValue slotBase, PropertyName)
+EncodedJSValue regExpConstructorDollar3(ExecState* exec, JSObject* slotBase, EncodedJSValue, PropertyName)
 {
 {
-    return asRegExpConstructor(slotBase)->getBackref(exec, 4);
+    return JSValue::encode(asRegExpConstructor(slotBase)->getBackref(exec, 3));
 }
 
 }
 
-JSValue regExpConstructorDollar5(ExecState* exec, JSValue slotBase, PropertyName)
+EncodedJSValue regExpConstructorDollar4(ExecState* exec, JSObject* slotBase, EncodedJSValue, PropertyName)
 {
 {
-    return asRegExpConstructor(slotBase)->getBackref(exec, 5);
+    return JSValue::encode(asRegExpConstructor(slotBase)->getBackref(exec, 4));
 }
 
 }
 
-JSValue regExpConstructorDollar6(ExecState* exec, JSValue slotBase, PropertyName)
+EncodedJSValue regExpConstructorDollar5(ExecState* exec, JSObject* slotBase, EncodedJSValue, PropertyName)
 {
 {
-    return asRegExpConstructor(slotBase)->getBackref(exec, 6);
+    return JSValue::encode(asRegExpConstructor(slotBase)->getBackref(exec, 5));
 }
 
 }
 
-JSValue regExpConstructorDollar7(ExecState* exec, JSValue slotBase, PropertyName)
+EncodedJSValue regExpConstructorDollar6(ExecState* exec, JSObject* slotBase, EncodedJSValue, PropertyName)
 {
 {
-    return asRegExpConstructor(slotBase)->getBackref(exec, 7);
+    return JSValue::encode(asRegExpConstructor(slotBase)->getBackref(exec, 6));
 }
 
 }
 
-JSValue regExpConstructorDollar8(ExecState* exec, JSValue slotBase, PropertyName)
+EncodedJSValue regExpConstructorDollar7(ExecState* exec, JSObject* slotBase, EncodedJSValue, PropertyName)
 {
 {
-    return asRegExpConstructor(slotBase)->getBackref(exec, 8);
+    return JSValue::encode(asRegExpConstructor(slotBase)->getBackref(exec, 7));
 }
 
 }
 
-JSValue regExpConstructorDollar9(ExecState* exec, JSValue slotBase, PropertyName)
+EncodedJSValue regExpConstructorDollar8(ExecState* exec, JSObject* slotBase, EncodedJSValue, PropertyName)
 {
 {
-    return asRegExpConstructor(slotBase)->getBackref(exec, 9);
+    return JSValue::encode(asRegExpConstructor(slotBase)->getBackref(exec, 8));
 }
 
 }
 
-JSValue regExpConstructorInput(ExecState*, JSValue slotBase, PropertyName)
+EncodedJSValue regExpConstructorDollar9(ExecState* exec, JSObject* slotBase, EncodedJSValue, PropertyName)
 {
 {
-    return asRegExpConstructor(slotBase)->input();
+    return JSValue::encode(asRegExpConstructor(slotBase)->getBackref(exec, 9));
 }
 
 }
 
-JSValue regExpConstructorMultiline(ExecState*, JSValue slotBase, PropertyName)
+EncodedJSValue regExpConstructorInput(ExecState*, JSObject* slotBase, EncodedJSValue, PropertyName)
 {
 {
-    return jsBoolean(asRegExpConstructor(slotBase)->multiline());
+    return JSValue::encode(asRegExpConstructor(slotBase)->input());
 }
 
 }
 
-JSValue regExpConstructorLastMatch(ExecState* exec, JSValue slotBase, PropertyName)
+EncodedJSValue regExpConstructorMultiline(ExecState*, JSObject* slotBase, EncodedJSValue, PropertyName)
 {
 {
-    return asRegExpConstructor(slotBase)->getBackref(exec, 0);
+    return JSValue::encode(jsBoolean(asRegExpConstructor(slotBase)->multiline()));
 }
 
 }
 
-JSValue regExpConstructorLastParen(ExecState* exec, JSValue slotBase, PropertyName)
+EncodedJSValue regExpConstructorLastMatch(ExecState* exec, JSObject* slotBase, EncodedJSValue, PropertyName)
 {
 {
-    return asRegExpConstructor(slotBase)->getLastParen(exec);
+    return JSValue::encode(asRegExpConstructor(slotBase)->getBackref(exec, 0));
 }
 
 }
 
-JSValue regExpConstructorLeftContext(ExecState* exec, JSValue slotBase, PropertyName)
+EncodedJSValue regExpConstructorLastParen(ExecState* exec, JSObject* slotBase, EncodedJSValue, PropertyName)
 {
 {
-    return asRegExpConstructor(slotBase)->getLeftContext(exec);
+    return JSValue::encode(asRegExpConstructor(slotBase)->getLastParen(exec));
 }
 
 }
 
-JSValue regExpConstructorRightContext(ExecState* exec, JSValue slotBase, PropertyName)
+EncodedJSValue regExpConstructorLeftContext(ExecState* exec, JSObject* slotBase, EncodedJSValue, PropertyName)
 {
 {
-    return asRegExpConstructor(slotBase)->getRightContext(exec);
+    return JSValue::encode(asRegExpConstructor(slotBase)->getLeftContext(exec));
 }
 
 }
 
-void RegExpConstructor::put(JSCell* cell, ExecState* exec, PropertyName propertyName, JSValue value, PutPropertySlot& slot)
+EncodedJSValue regExpConstructorRightContext(ExecState* exec, JSObject* slotBase, EncodedJSValue, PropertyName)
 {
 {
-    lookupPut<RegExpConstructor, InternalFunction>(exec, propertyName, value, ExecState::regExpConstructorTable(exec), jsCast<RegExpConstructor*>(cell), slot);
+    return JSValue::encode(asRegExpConstructor(slotBase)->getRightContext(exec));
 }
 
 }
 
-void setRegExpConstructorInput(ExecState* exec, JSObject* baseObject, JSValue value)
+void setRegExpConstructorInput(ExecState* exec, JSObject* baseObject, EncodedJSValue, EncodedJSValue value)
 {
 {
-    asRegExpConstructor(baseObject)->setInput(exec, value.toString(exec));
+    if (auto constructor = jsDynamicCast<RegExpConstructor*>(baseObject))
+        constructor->setInput(exec, JSValue::decode(value).toString(exec));
 }
 
 }
 
-void setRegExpConstructorMultiline(ExecState* exec, JSObject* baseObject, JSValue value)
+void setRegExpConstructorMultiline(ExecState* exec, JSObject* baseObject, EncodedJSValue, EncodedJSValue value)
 {
 {
-    asRegExpConstructor(baseObject)->setMultiline(value.toBoolean(exec));
+    if (auto constructor = jsDynamicCast<RegExpConstructor*>(baseObject))
+        constructor->setMultiline(JSValue::decode(value).toBoolean(exec));
 }
 
 // ECMA 15.10.4
 }
 
 // ECMA 15.10.4
@@ -263,18 +248,18 @@ JSObject* constructRegExp(ExecState* exec, JSGlobalObject* globalObject, const A
     JSValue arg0 = args.at(0);
     JSValue arg1 = args.at(1);
 
     JSValue arg0 = args.at(0);
     JSValue arg1 = args.at(1);
 
-    if (arg0.inherits(&RegExpObject::s_info)) {
+    if (arg0.inherits(RegExpObject::info())) {
         if (!arg1.isUndefined())
         if (!arg1.isUndefined())
-            return throwError(exec, createTypeError(exec, ASCIILiteral("Cannot supply flags when constructing one RegExp from another.")));
+            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) {
             RegExp* regExp = static_cast<RegExpObject*>(asObject(arg0))->regExp();
         // If called as a function, this just returns the first argument (see 15.10.3.1).
         if (callAsConstructor) {
             RegExp* regExp = static_cast<RegExpObject*>(asObject(arg0))->regExp();
-            return RegExpObject::create(exec, globalObject, globalObject->regExpStructure(), regExp);
+            return RegExpObject::create(exec->vm(), globalObject->regExpStructure(), regExp);
         }
         return asObject(arg0);
     }
 
         }
         return asObject(arg0);
     }
 
-    String pattern = arg0.isUndefined() ? String("") : arg0.toString(exec)->value(exec);
+    String pattern = arg0.isUndefined() ? emptyString() : arg0.toString(exec)->value(exec);
     if (exec->hadException())
         return 0;
 
     if (exec->hadException())
         return 0;
 
@@ -284,13 +269,14 @@ JSObject* constructRegExp(ExecState* exec, JSGlobalObject* globalObject, const A
         if (exec->hadException())
             return 0;
         if (flags == InvalidFlags)
         if (exec->hadException())
             return 0;
         if (flags == InvalidFlags)
-            return throwError(exec, createSyntaxError(exec, ASCIILiteral("Invalid flags supplied to RegExp constructor.")));
+            return exec->vm().throwException(exec, createSyntaxError(exec, ASCIILiteral("Invalid flags supplied to RegExp constructor.")));
     }
 
     }
 
-    RegExp* regExp = RegExp::create(exec->vm(), pattern, flags);
+    VM& vm = exec->vm();
+    RegExp* regExp = RegExp::create(vm, pattern, flags);
     if (!regExp->isValid())
     if (!regExp->isValid())
-        return throwError(exec, createSyntaxError(exec, regExp->errorMessage()));
-    return RegExpObject::create(exec, exec->lexicalGlobalObject(), globalObject->regExpStructure(), regExp);
+        return vm.throwException(exec, createSyntaxError(exec, regExp->errorMessage()));
+    return RegExpObject::create(vm, globalObject->regExpStructure(), regExp);
 }
 
 static EncodedJSValue JSC_HOST_CALL constructWithRegExpConstructor(ExecState* exec)
 }
 
 static EncodedJSValue JSC_HOST_CALL constructWithRegExpConstructor(ExecState* exec)