/*
- * 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
#include <wtf/CurrentTime.h>
#include "InitializeThreading.h"
+#include "JSCInlines.h"
#include "JSGlobalObject.h"
-#include "UStringBuilder.h"
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
+#include <wtf/text/StringBuilder.h>
#if !OS(WINDOWS)
#include <unistd.h>
#include <sys/time.h>
#endif
-#if COMPILER(MSVC) && !OS(WINCE)
+#if COMPILER(MSVC)
#include <crtdbg.h>
#include <mmsystem.h>
#include <windows.h>
#endif
-#if PLATFORM(QT)
-#include <QCoreApplication>
-#include <QDateTime>
-#endif
+namespace JSC {
+WTF_IMPORT extern const struct HashTable globalObjectTable;
+}
const int MaxLineLength = 100 * 1024;
bool interactive;
bool verbose;
- Vector<UString> arguments;
- Vector<UString> files;
+ Vector<String> arguments;
+ Vector<String> files;
};
class StopWatch {
void StopWatch::start()
{
- m_startTime = currentTime();
+ m_startTime = monotonicallyIncreasingTime();
}
void StopWatch::stop()
{
- m_stopTime = currentTime();
+ m_stopTime = monotonicallyIncreasingTime();
}
long StopWatch::getElapsedMS()
{
}
- UString subject;
+ String subject;
int offset;
int result;
Vector<int, 32> expectVector;
class GlobalObject : public JSGlobalObject {
private:
- GlobalObject(JSGlobalData&, Structure*, const Vector<UString>& arguments);
+ GlobalObject(VM&, Structure*, const Vector<String>& arguments);
public:
typedef JSGlobalObject Base;
- static GlobalObject* create(JSGlobalData& globalData, Structure* structure, const Vector<UString>& arguments)
+ static GlobalObject* create(VM& vm, Structure* structure, const Vector<String>& arguments)
{
- return new (NotNull, allocateCell<GlobalObject>(globalData.heap)) GlobalObject(globalData, structure, arguments);
+ GlobalObject* globalObject = new (NotNull, allocateCell<GlobalObject>(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<UString>& arguments)
+ void finishCreation(VM& vm, const Vector<String>& arguments)
{
- Base::finishCreation(globalData);
+ Base::finishCreation(vm);
UNUSED_PARAM(arguments);
}
};
-COMPILE_ASSERT(!IsInteger<GlobalObject>::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<UString>& arguments)
- : JSGlobalObject(globalData, structure)
+GlobalObject::GlobalObject(VM& vm, Structure* structure, const Vector<String>& arguments)
+ : JSGlobalObject(vm, structure)
{
- finishCreation(globalData, arguments);
+ finishCreation(vm, arguments);
}
// Use SEH for Release builds only to get rid of the crash report dialog
// 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
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 <http://webkit.org/b/55222>.
::SetErrorMode(0);
-#endif
#if defined(_DEBUG)
_CrtSetReportFile(_CRT_WARN, _CRTDBG_FILE_STDERR);
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
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<int, 32> 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;
} 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;
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
+ }
}
}
}
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;
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;
++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;
RegExpTest* result = new RegExpTest();
- result->subject = subjectString.toUString();
+ result->subject = subjectString.toString();
result->offset = offset;
result->result = matchResult;
return result;
}
-static bool runFromFiles(GlobalObject* globalObject, const Vector<UString>& files, bool verbose)
+static bool runFromFiles(GlobalObject* globalObject, const Vector<String>& files, bool verbose)
{
- UString script;
- UString fileName;
+ String script;
+ String fileName;
Vector<char> 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++) {
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);
}
delete[] lineBuffer;
- globalData.dumpSampleData(globalObject->globalExec());
+ vm.dumpSampleData(globalObject->globalExec());
#if ENABLE(REGEXP_TRACING)
- globalData.dumpRegExpTrace();
+ vm.dumpRegExpTrace();
#endif
return success;
}
int realMain(int argc, char** argv)
{
- RefPtr<JSGlobalData> 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<char**>(argv));
+}
+#endif