Optmize escargot (#454)

* Don't allocate new StringView on parser if possible
* Store esprima::Context::firstCoverInitializedNameError as pointer. it can reduce copy cost on esprima::*CoverGrammar
* Make Script as reexcutable if possible
* Don't save parsed source codes
  - Remove SourceStringView
  - When create AtomicString from StringView, we should make new string data instead of reference StringView
* Reduce size of StringBufferAccessData
* Fix crash in toString of FunctionObject.

Signed-off-by: seonghyun kim <sh8281.kim@samsung.com>
This commit is contained in:
Patrick Kim 2019-10-11 15:32:04 +09:00 committed by Hyukwoo Park
commit 03ac100d7f
17 changed files with 163 additions and 255 deletions

View file

@ -19,6 +19,7 @@
#include <string.h>
#include <vector>
#include "api/EscargotPublic.h"
#if defined(ESCARGOT_ENABLE_TEST)
@ -230,6 +231,12 @@ static ValueRef* builtinRun(ExecutionStateRef* state, ValueRef* thisValue, size_
}
}
static ValueRef* builtinGc(ExecutionStateRef* state, ValueRef* thisValue, size_t argc, ValueRef** argv, bool isConstructCall)
{
Memory::gc();
return ValueRef::createUndefined();
}
#if defined(ESCARGOT_ENABLE_TEST)
static ValueRef* builtinUneval(ExecutionStateRef* state, ValueRef* thisValue, size_t argc, ValueRef** argv, bool isConstructCall)
{
@ -301,6 +308,12 @@ PersistentRefHolder<ContextRef> createEscargotContext(VMInstanceRef* instance)
context->globalObject()->defineDataProperty(state, StringRef::createFromASCII("run"), buildFunctionObjectRef, true, true, true);
}
{
FunctionObjectRef::NativeFunctionInfo nativeFunctionInfo(AtomicStringRef::create(context, "gc"), builtinGc, 0, true, false);
FunctionObjectRef* buildFunctionObjectRef = FunctionObjectRef::create(state, nativeFunctionInfo);
context->globalObject()->defineDataProperty(state, StringRef::createFromASCII("gc"), buildFunctionObjectRef, true, true, true);
}
#if defined(ESCARGOT_ENABLE_TEST)
{
FunctionObjectRef::NativeFunctionInfo nativeFunctionInfo(AtomicStringRef::create(context, "uneval"), builtinUneval, 1, true, false);
@ -435,6 +448,7 @@ static bool evalScript(ContextRef* context, StringRef* str, StringRef* fileName,
if (stringEndsWith(fileName->toStdUTF8String(), "mjs")) {
isModule = isModule || true;
}
auto scriptInitializeResult = context->scriptParser()->initializeScript(str, fileName, isModule);
if (!scriptInitializeResult.script) {
printf("Script parsing error: ");