summaryrefslogtreecommitdiff
path: root/Source/JavaScriptCore/API/JSScriptRef.cpp
diff options
context:
space:
mode:
authorKonstantin Tokarev <annulen@yandex.ru>2016-08-25 19:20:41 +0300
committerKonstantin Tokarev <annulen@yandex.ru>2017-02-02 12:30:55 +0000
commit6882a04fb36642862b11efe514251d32070c3d65 (patch)
treeb7959826000b061fd5ccc7512035c7478742f7b0 /Source/JavaScriptCore/API/JSScriptRef.cpp
parentab6df191029eeeb0b0f16f127d553265659f739e (diff)
downloadqtwebkit-6882a04fb36642862b11efe514251d32070c3d65.tar.gz
Imported QtWebKit TP3 (git b57bc6801f1876c3220d5a4bfea33d620d477443)
Change-Id: I3b1d8a2808782c9f34d50240000e20cb38d3680f Reviewed-by: Konstantin Tokarev <annulen@yandex.ru>
Diffstat (limited to 'Source/JavaScriptCore/API/JSScriptRef.cpp')
-rw-r--r--Source/JavaScriptCore/API/JSScriptRef.cpp64
1 files changed, 38 insertions, 26 deletions
diff --git a/Source/JavaScriptCore/API/JSScriptRef.cpp b/Source/JavaScriptCore/API/JSScriptRef.cpp
index 8a5f3caf3..60bde604e 100644
--- a/Source/JavaScriptCore/API/JSScriptRef.cpp
+++ b/Source/JavaScriptCore/API/JSScriptRef.cpp
@@ -26,13 +26,13 @@
#include "config.h"
#include "APICast.h"
-#include "APIShims.h"
#include "Completion.h"
+#include "Exception.h"
#include "JSBasePrivate.h"
#include "VM.h"
#include "JSScriptRefPrivate.h"
#include "OpaqueJSString.h"
-#include "Operations.h"
+#include "JSCInlines.h"
#include "Parser.h"
#include "SourceCode.h"
#include "SourceProvider.h"
@@ -41,14 +41,19 @@ using namespace JSC;
struct OpaqueJSScript : public SourceProvider {
public:
- static WTF::PassRefPtr<OpaqueJSScript> create(VM* vm, const String& url, int startingLineNumber, const String& source)
+ static WTF::RefPtr<OpaqueJSScript> create(VM* vm, const String& url, int startingLineNumber, const String& source)
{
- return WTF::adoptRef(new OpaqueJSScript(vm, url, startingLineNumber, source));
+ return WTF::adoptRef(*new OpaqueJSScript(vm, url, startingLineNumber, source));
}
- const String& source() const OVERRIDE
+ unsigned hash() const override
{
- return m_source;
+ return m_source.get().hash();
+ }
+
+ StringView source() const override
+ {
+ return m_source.get();
}
VM* vm() const { return m_vm; }
@@ -57,19 +62,22 @@ private:
OpaqueJSScript(VM* vm, const String& url, int startingLineNumber, const String& source)
: SourceProvider(url, TextPosition(OrdinalNumber::fromOneBasedInt(startingLineNumber), OrdinalNumber::first()))
, m_vm(vm)
- , m_source(source)
+ , m_source(source.isNull() ? *StringImpl::empty() : *source.impl())
{
}
- ~OpaqueJSScript() { }
+ virtual ~OpaqueJSScript() { }
VM* m_vm;
- String m_source;
+ Ref<StringImpl> m_source;
};
static bool parseScript(VM* vm, const SourceCode& source, ParserError& error)
{
- return JSC::parse<JSC::ProgramNode>(vm, source, 0, Identifier(), JSParseNormal, JSParseProgramCode, error);
+ return !!JSC::parse<JSC::ProgramNode>(
+ vm, source, Identifier(), JSParserBuiltinMode::NotBuiltin,
+ JSParserStrictMode::NotStrict, SourceParseMode::ProgramMode, SuperBinding::NotNeeded,
+ error);
}
extern "C" {
@@ -77,21 +85,23 @@ extern "C" {
JSScriptRef JSScriptCreateReferencingImmortalASCIIText(JSContextGroupRef contextGroup, JSStringRef url, int startingLineNumber, const char* source, size_t length, JSStringRef* errorMessage, int* errorLine)
{
VM* vm = toJS(contextGroup);
- APIEntryShim entryShim(vm);
+ JSLockHolder locker(vm);
for (size_t i = 0; i < length; i++) {
if (!isASCII(source[i]))
return 0;
}
- RefPtr<OpaqueJSScript> result = OpaqueJSScript::create(vm, url->string(), startingLineNumber, String(StringImpl::createFromLiteral(source, length)));
+ startingLineNumber = std::max(1, startingLineNumber);
+
+ RefPtr<OpaqueJSScript> result = OpaqueJSScript::create(vm, url ? url->string() : String(), startingLineNumber, String(StringImpl::createFromLiteral(source, length)));
ParserError error;
if (!parseScript(vm, SourceCode(result), error)) {
if (errorMessage)
- *errorMessage = OpaqueJSString::create(error.m_message).leakRef();
+ *errorMessage = OpaqueJSString::create(error.message()).leakRef();
if (errorLine)
- *errorLine = error.m_line;
- return 0;
+ *errorLine = error.line();
+ return nullptr;
}
return result.release().leakRef();
@@ -100,17 +110,19 @@ JSScriptRef JSScriptCreateReferencingImmortalASCIIText(JSContextGroupRef context
JSScriptRef JSScriptCreateFromString(JSContextGroupRef contextGroup, JSStringRef url, int startingLineNumber, JSStringRef source, JSStringRef* errorMessage, int* errorLine)
{
VM* vm = toJS(contextGroup);
- APIEntryShim entryShim(vm);
+ JSLockHolder locker(vm);
+
+ startingLineNumber = std::max(1, startingLineNumber);
- RefPtr<OpaqueJSScript> result = OpaqueJSScript::create(vm, url->string(), startingLineNumber, source->string());
+ RefPtr<OpaqueJSScript> result = OpaqueJSScript::create(vm, url ? url->string() : String(), startingLineNumber, source->string());
ParserError error;
if (!parseScript(vm, SourceCode(result), error)) {
if (errorMessage)
- *errorMessage = OpaqueJSString::create(error.m_message).leakRef();
+ *errorMessage = OpaqueJSString::create(error.message()).leakRef();
if (errorLine)
- *errorLine = error.m_line;
- return 0;
+ *errorLine = error.line();
+ return nullptr;
}
return result.release().leakRef();
@@ -118,30 +130,30 @@ JSScriptRef JSScriptCreateFromString(JSContextGroupRef contextGroup, JSStringRef
void JSScriptRetain(JSScriptRef script)
{
- APIEntryShim entryShim(script->vm());
+ JSLockHolder locker(script->vm());
script->ref();
}
void JSScriptRelease(JSScriptRef script)
{
- APIEntryShim entryShim(script->vm());
+ JSLockHolder locker(script->vm());
script->deref();
}
JSValueRef JSScriptEvaluate(JSContextRef context, JSScriptRef script, JSValueRef thisValueRef, JSValueRef* exception)
{
ExecState* exec = toJS(context);
- APIEntryShim entryShim(exec);
+ JSLockHolder locker(exec);
if (script->vm() != &exec->vm()) {
RELEASE_ASSERT_NOT_REACHED();
return 0;
}
- JSValue internalException;
+ NakedPtr<Exception> internalException;
JSValue thisValue = thisValueRef ? toJS(exec, thisValueRef) : jsUndefined();
- JSValue result = evaluate(exec, SourceCode(script), thisValue, &internalException);
+ JSValue result = evaluate(exec, SourceCode(script), thisValue, internalException);
if (internalException) {
if (exception)
- *exception = toRef(exec, internalException);
+ *exception = toRef(exec, internalException->value());
return 0;
}
ASSERT(result);