X-Git-Url: https://git.saurik.com/apple/javascriptcore.git/blobdiff_plain/6fe7ccc865dc7d7541b93c5bcaf6368d2c98a174..ed1e77d3adeb83d26fd1dfb16dd84cabdcefd250:/testRegExp.cpp?ds=inline diff --git a/testRegExp.cpp b/testRegExp.cpp index 61c21c3..d194159 100644 --- a/testRegExp.cpp +++ b/testRegExp.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2011 Apple Inc. All rights reserved. + * Copyright (C) 2011, 2015 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 @@ -23,12 +23,13 @@ #include #include "InitializeThreading.h" +#include "JSCInlines.h" #include "JSGlobalObject.h" -#include "UStringBuilder.h" #include #include #include #include +#include #if !OS(WINDOWS) #include @@ -38,16 +39,15 @@ #include #endif -#if COMPILER(MSVC) && !OS(WINCE) +#if COMPILER(MSVC) #include #include #include #endif -#if PLATFORM(QT) -#include -#include -#endif +namespace JSC { +WTF_IMPORT extern const struct HashTable globalObjectTable; +} const int MaxLineLength = 100 * 1024; @@ -63,8 +63,8 @@ struct CommandLine { bool interactive; bool verbose; - Vector arguments; - Vector files; + Vector arguments; + Vector files; }; class StopWatch { @@ -80,12 +80,12 @@ private: void StopWatch::start() { - m_startTime = currentTime(); + m_startTime = monotonicallyIncreasingTime(); } void StopWatch::stop() { - m_stopTime = currentTime(); + m_stopTime = monotonicallyIncreasingTime(); } long StopWatch::getElapsedMS() @@ -100,7 +100,7 @@ struct RegExpTest { { } - UString subject; + String subject; int offset; int result; Vector expectVector; @@ -108,40 +108,41 @@ struct RegExpTest { class GlobalObject : public JSGlobalObject { private: - GlobalObject(JSGlobalData&, Structure*, const Vector& arguments); + GlobalObject(VM&, Structure*, const Vector& arguments); public: typedef JSGlobalObject Base; - static GlobalObject* create(JSGlobalData& globalData, Structure* structure, const Vector& arguments) + static GlobalObject* create(VM& vm, Structure* structure, const Vector& arguments) { - return new (NotNull, allocateCell(globalData.heap)) GlobalObject(globalData, structure, arguments); + GlobalObject* globalObject = new (NotNull, allocateCell(vm.heap)) GlobalObject(vm, structure, arguments); + vm.heap.addFinalizer(globalObject, destroy); + return globalObject; } - static const ClassInfo s_info; + DECLARE_INFO; - static Structure* createStructure(JSGlobalData& globalData, JSValue prototype) + static const bool needsDestructor = false; + + static Structure* createStructure(VM& vm, JSValue prototype) { - return Structure::create(globalData, 0, prototype, TypeInfo(GlobalObjectType, StructureFlags), &s_info); + return Structure::create(vm, 0, prototype, TypeInfo(GlobalObjectType, StructureFlags), info()); } protected: - void finishCreation(JSGlobalData& globalData, const Vector& arguments) + void finishCreation(VM& vm, const Vector& arguments) { - Base::finishCreation(globalData); + Base::finishCreation(vm); UNUSED_PARAM(arguments); } }; -COMPILE_ASSERT(!IsInteger::value, WTF_IsInteger_GlobalObject_false); -ASSERT_CLASS_FITS_IN_CELL(GlobalObject); - -const ClassInfo GlobalObject::s_info = { "global", &JSGlobalObject::s_info, 0, ExecState::globalObjectTable, CREATE_METHOD_TABLE(GlobalObject) }; +const ClassInfo GlobalObject::s_info = { "global", &JSGlobalObject::s_info, &globalObjectTable, CREATE_METHOD_TABLE(GlobalObject) }; -GlobalObject::GlobalObject(JSGlobalData& globalData, Structure* structure, const Vector& arguments) - : JSGlobalObject(globalData, structure) +GlobalObject::GlobalObject(VM& vm, Structure* structure, const Vector& arguments) + : JSGlobalObject(vm, structure) { - finishCreation(globalData, arguments); + finishCreation(vm, arguments); } // Use SEH for Release builds only to get rid of the crash report dialog @@ -149,7 +150,7 @@ GlobalObject::GlobalObject(JSGlobalData& globalData, Structure* structure, const // be in a separate main function because the realMain function requires object // unwinding. -#if COMPILER(MSVC) && !COMPILER(INTEL) && !defined(_DEBUG) && !OS(WINCE) +#if COMPILER(MSVC) && !defined(_DEBUG) #define TRY __try { #define EXCEPT(x) } __except (EXCEPTION_EXECUTE_HANDLER) { x; } #else @@ -162,12 +163,19 @@ int realMain(int argc, char** argv); int main(int argc, char** argv) { #if OS(WINDOWS) -#if !OS(WINCE) +#if defined(_M_X64) || defined(__x86_64__) + // The VS2013 runtime has a bug where it mis-detects AVX-capable processors + // if the feature has been disabled in firmware. This causes us to crash + // in some of the math functions. For now, we disable those optimizations + // because Microsoft is not going to fix the problem in VS2013. + // FIXME: http://webkit.org/b/141449: Remove this workaround when we switch to VS2015+. + _set_FMA3_enable(0); +#endif + // Cygwin calls ::SetErrorMode(SEM_FAILCRITICALERRORS), which we will inherit. This is bad for // testing/debugging, as it causes the post-mortem debugger not to be invoked. We reset the // error mode here to work around Cygwin's behavior. See . ::SetErrorMode(0); -#endif #if defined(_DEBUG) _CrtSetReportFile(_CRT_WARN, _CRTDBG_FILE_STDERR); @@ -181,11 +189,7 @@ int main(int argc, char** argv) timeBeginPeriod(1); #endif -#if PLATFORM(QT) - QCoreApplication app(argc, argv); -#endif - - // Initialize JSC before getting JSGlobalData. + // Initialize JSC before getting VM. JSC::initializeThreading(); // We can't use destructors in the following code because it uses Windows @@ -197,12 +201,12 @@ int main(int argc, char** argv) return res; } -static bool testOneRegExp(JSGlobalData& globalData, RegExp* regexp, RegExpTest* regExpTest, bool verbose, unsigned int lineNumber) +static bool testOneRegExp(VM& vm, RegExp* regexp, RegExpTest* regExpTest, bool verbose, unsigned int lineNumber) { bool result = true; Vector outVector; outVector.resize(regExpTest->expectVector.size()); - int matchResult = regexp->match(globalData, regExpTest->subject, regExpTest->offset, outVector); + int matchResult = regexp->match(vm, regExpTest->subject, regExpTest->offset, outVector); if (matchResult != regExpTest->result) { result = false; @@ -211,12 +215,22 @@ static bool testOneRegExp(JSGlobalData& globalData, RegExp* regexp, RegExpTest* } else if (matchResult != -1) { if (outVector.size() != regExpTest->expectVector.size()) { result = false; - if (verbose) - printf("Line %d: output vector size mismatch - expected %lu got %lu\n", lineNumber, regExpTest->expectVector.size(), outVector.size()); + if (verbose) { +#if OS(WINDOWS) + printf("Line %d: output vector size mismatch - expected %Iu got %Iu\n", lineNumber, regExpTest->expectVector.size(), outVector.size()); +#else + printf("Line %d: output vector size mismatch - expected %zu got %zu\n", lineNumber, regExpTest->expectVector.size(), outVector.size()); +#endif + } } else if (outVector.size() % 2) { result = false; - if (verbose) - printf("Line %d: output vector size is odd (%lu), should be even\n", lineNumber, outVector.size()); + if (verbose) { +#if OS(WINDOWS) + printf("Line %d: output vector size is odd (%Iu), should be even\n", lineNumber, outVector.size()); +#else + printf("Line %d: output vector size is odd (%zu), should be even\n", lineNumber, outVector.size()); +#endif + } } else { // Check in pairs since the first value of the pair could be -1 in which case the second doesn't matter. size_t pairCount = outVector.size() / 2; @@ -224,13 +238,23 @@ static bool testOneRegExp(JSGlobalData& globalData, RegExp* regexp, RegExpTest* size_t startIndex = i*2; if (outVector[startIndex] != regExpTest->expectVector[startIndex]) { result = false; - if (verbose) - printf("Line %d: output vector mismatch at index %lu - expected %d got %d\n", lineNumber, startIndex, regExpTest->expectVector[startIndex], outVector[startIndex]); + if (verbose) { +#if OS(WINDOWS) + printf("Line %d: output vector mismatch at index %Iu - expected %d got %d\n", lineNumber, startIndex, regExpTest->expectVector[startIndex], outVector[startIndex]); +#else + printf("Line %d: output vector mismatch at index %zu - expected %d got %d\n", lineNumber, startIndex, regExpTest->expectVector[startIndex], outVector[startIndex]); +#endif + } } if ((i > 0) && (regExpTest->expectVector[startIndex] != -1) && (outVector[startIndex+1] != regExpTest->expectVector[startIndex+1])) { result = false; - if (verbose) - printf("Line %d: output vector mismatch at index %lu - expected %d got %d\n", lineNumber, startIndex+1, regExpTest->expectVector[startIndex+1], outVector[startIndex+1]); + if (verbose) { +#if OS(WINDOWS) + printf("Line %d: output vector mismatch at index %Iu - expected %d got %d\n", lineNumber, startIndex + 1, regExpTest->expectVector[startIndex + 1], outVector[startIndex + 1]); +#else + printf("Line %d: output vector mismatch at index %zu - expected %d got %d\n", lineNumber, startIndex + 1, regExpTest->expectVector[startIndex + 1], outVector[startIndex + 1]); +#endif + } } } } @@ -239,7 +263,7 @@ static bool testOneRegExp(JSGlobalData& globalData, RegExp* regexp, RegExpTest* return result; } -static int scanString(char* buffer, int bufferLength, UStringBuilder& builder, char termChar) +static int scanString(char* buffer, int bufferLength, StringBuilder& builder, char termChar) { bool escape = false; @@ -305,9 +329,9 @@ static int scanString(char* buffer, int bufferLength, UStringBuilder& builder, c return -1; } -static RegExp* parseRegExpLine(JSGlobalData& globalData, char* line, int lineLength) +static RegExp* parseRegExpLine(VM& vm, char* line, int lineLength) { - UStringBuilder pattern; + StringBuilder pattern; if (line[0] != '/') return 0; @@ -319,12 +343,12 @@ static RegExp* parseRegExpLine(JSGlobalData& globalData, char* line, int lineLen ++i; - return RegExp::create(globalData, pattern.toUString(), regExpFlags(line + i)); + return RegExp::create(vm, pattern.toString(), regExpFlags(line + i)); } static RegExpTest* parseTestLine(char* line, int lineLength) { - UStringBuilder subjectString; + StringBuilder subjectString; if ((line[0] != ' ') || (line[1] != '"')) return 0; @@ -363,7 +387,7 @@ static RegExpTest* parseTestLine(char* line, int lineLength) RegExpTest* result = new RegExpTest(); - result->subject = subjectString.toUString(); + result->subject = subjectString.toString(); result->offset = offset; result->result = matchResult; @@ -394,16 +418,16 @@ static RegExpTest* parseTestLine(char* line, int lineLength) return result; } -static bool runFromFiles(GlobalObject* globalObject, const Vector& files, bool verbose) +static bool runFromFiles(GlobalObject* globalObject, const Vector& files, bool verbose) { - UString script; - UString fileName; + String script; + String fileName; Vector scriptBuffer; unsigned tests = 0; unsigned failures = 0; char* lineBuffer = new char[MaxLineLength + 1]; - JSGlobalData& globalData = globalObject->globalData(); + VM& vm = globalObject->vm(); bool success = true; for (size_t i = 0; i < files.size(); i++) { @@ -431,13 +455,13 @@ static bool runFromFiles(GlobalObject* globalObject, const Vector& file continue; if (linePtr[0] == '/') { - regexp = parseRegExpLine(globalData, linePtr, lineLength); + regexp = parseRegExpLine(vm, linePtr, lineLength); } else if (linePtr[0] == ' ') { RegExpTest* regExpTest = parseTestLine(linePtr, lineLength); if (regexp && regExpTest) { ++tests; - if (!testOneRegExp(globalData, regexp, regExpTest, verbose, lineNumber)) { + if (!testOneRegExp(vm, regexp, regExpTest, verbose, lineNumber)) { failures++; printf("Failure on line %u\n", lineNumber); } @@ -458,9 +482,9 @@ static bool runFromFiles(GlobalObject* globalObject, const Vector& file delete[] lineBuffer; - globalData.dumpSampleData(globalObject->globalExec()); + vm.dumpSampleData(globalObject->globalExec()); #if ENABLE(REGEXP_TRACING) - globalData.dumpRegExpTrace(); + vm.dumpRegExpTrace(); #endif return success; } @@ -495,14 +519,21 @@ static void parseArguments(int argc, char** argv, CommandLine& options) int realMain(int argc, char** argv) { - RefPtr globalData = JSGlobalData::create(ThreadStackTypeLarge, LargeHeap); - JSLockHolder lock(globalData.get()); + VM* vm = &VM::create(LargeHeap).leakRef(); + JSLockHolder locker(vm); CommandLine options; parseArguments(argc, argv, options); - GlobalObject* globalObject = GlobalObject::create(*globalData, GlobalObject::createStructure(*globalData, jsNull()), options.arguments); + GlobalObject* globalObject = GlobalObject::create(*vm, GlobalObject::createStructure(*vm, jsNull()), options.arguments); bool success = runFromFiles(globalObject, options.files, options.verbose); return success ? 0 : 3; } + +#if OS(WINDOWS) +extern "C" __declspec(dllexport) int WINAPI dllLauncherEntryPoint(int argc, const char* argv[]) +{ + return main(argc, const_cast(argv)); +} +#endif