Split out FunctionNode from FunctionBodyNode
https://bugs.webkit.org/show_bug.cgi?id=139273

Reviewed by Andreas Kling.

This is step toward a parser speedup.

We used to use FunctionBodyNode for two different purposes:

(1) "I am the root function you are currently parsing";

(2) "I am a lazy record of a nested function, which you will parse later".

This made for awkward lifetime semantics and interfaces.

Now, case (1) is handled by FunctionBodyNode, and case (2) is handled by
a new node named FunctionNode.

Since case (1) no longer needs to handle being the root of the parse
tree, FunctionBodyNode can be a normal arena-allocated node.

* bytecode/UnlinkedCodeBlock.cpp:
(JSC::generateFunctionCodeBlock): Use FunctionNode instead of
FunctionBodyNode, since we are producing the root of the function parse
tree.

(JSC::UnlinkedFunctionExecutable::UnlinkedFunctionExecutable): Removed
some unused data, and default-initialized other data, which isn't filled
in meaningfully until recordParse() is called. (The previous values were
incorrect / meaningless, since the FunctionBodyNode didn't have
meaningful values in this case.)

* bytecode/UnlinkedCodeBlock.h: Ditto.

(JSC::UnlinkedFunctionExecutable::forceUsesArguments): Deleted.

* bytecompiler/BytecodeGenerator.cpp:
(JSC::BytecodeGenerator::BytecodeGenerator): Use FunctionNode instead of
FunctionBodyNode, since we are generating code starting at the root of
the parse tree.

(JSC::BytecodeGenerator::resolveCallee):
(JSC::BytecodeGenerator::addCallee):
* bytecompiler/BytecodeGenerator.h: Ditto.

* bytecompiler/NodesCodegen.cpp:
(JSC::FunctionBodyNode::emitBytecode):
(JSC::FunctionNode::emitBytecode): Moved the emitBytecode implementation
to FunctionNode, since we never generate code for FunctionBodyNode,
since it's just a placeholder in the AST.

* parser/ASTBuilder.h:
(JSC::ASTBuilder::createFunctionBody):
(JSC::ASTBuilder::setUsesArguments): Deleted. Updated for interface
changes.

* parser/Nodes.cpp:
(JSC::FunctionBodyNode::FunctionBodyNode):
(JSC::FunctionBodyNode::finishParsing):
(JSC::FunctionBodyNode::setEndPosition):
(JSC::FunctionNode::FunctionNode):
(JSC::FunctionNode::create):
(JSC::FunctionNode::finishParsing):
(JSC::FunctionBodyNode::create): Deleted.

* parser/Nodes.h:
(JSC::FunctionBodyNode::parameters):
(JSC::FunctionBodyNode::source):
(JSC::FunctionBodyNode::startStartOffset):
(JSC::FunctionBodyNode::isInStrictContext):
(JSC::FunctionNode::parameters):
(JSC::FunctionNode::ident):
(JSC::FunctionNode::functionMode):
(JSC::FunctionNode::startColumn):
(JSC::FunctionNode::endColumn):
(JSC::ScopeNode::setSource): Deleted.
(JSC::FunctionBodyNode::parameterCount): Deleted. Split out the differences
between FunctionNode and FunctionBodyNode.

* parser/SyntaxChecker.h:
(JSC::SyntaxChecker::createClauseList):
(JSC::SyntaxChecker::setUsesArguments): Deleted. Removed setUsesArguments
since it wasn't used.

* runtime/Executable.cpp:
(JSC::ProgramExecutable::checkSyntax): Removed a branch that was always
false.


git-svn-id: http://svn.webkit.org/repository/webkit/trunk@176822 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2014-12-04  Geoffrey Garen  <ggaren@apple.com>

        Marked some final things final.

        Reviewed by Andreas Kling.

        * parser/Nodes.h:



git-svn-id: http://svn.webkit.org/repository/webkit/trunk@176823 268f45cc-cd09-0410-ab3c-d52691b4dbfc
REGRESSION(r173188): Text inserted when trying to delete a word from the Twitter message box.
<https://webkit.org/b/139076>

Reviewed by Geoffrey Garen.

The StringImpl* -> Weak<JSString> cache used by the DOM bindings
had a bug where the key could become a stale pointer if the cached
JSString had its internal StringImpl atomicized.

If a new StringImpl was then later constructed at the exact same
address as the stale key, before the Weak<JSString> got booted out
of the string cache, we'd now have a situation where asking the
string cache for that key would return the old JSString.

Solve this by not allowing JSString::toExistingAtomicString() to
change the JSString's internal StringImpl unless it's resolving a
rope string. (The StringImpl nullity determines rope state.)

This means that calling toExistingAtomicString() may now have to
query the AtomicString table on each call rather than just once.
All clients of this API would be forced to do this regardless,
since they return value will be used to key into containers with
AtomicStringImpl* keys.

No test because this relies on malloc putting two StringImpls
at the same address at different points in time and we have no
mechanism to reliably test that.

* runtime/JSString.h:
(JSC::JSString::toExistingAtomicString):


git-svn-id: http://svn.webkit.org/repository/webkit/trunk@176824 268f45cc-cd09-0410-ab3c-d52691b4dbfc
Removed the concept of ParserArenaRefCounted
https://bugs.webkit.org/show_bug.cgi?id=139277

Reviewed by Oliver Hunt.

This is a step toward a parser speedup.

Now that we have a clear root node type for each parse tree, there's no
need to have a concept for "I might be refcounted or arena allocated".
Instead, we can just use unique_ptr to manage the tree as a whole.

* API/JSScriptRef.cpp:
(parseScript):
* builtins/BuiltinExecutables.cpp:
(JSC::BuiltinExecutables::createBuiltinExecutable): Updated for type change.

* bytecode/UnlinkedCodeBlock.cpp:
(JSC::generateFunctionCodeBlock): Use unique_ptr. No need to call
destroyData() explicitly: the unique_ptr destructor will do everything
we need, as Bjarne intended.

* parser/NodeConstructors.h:
(JSC::ParserArenaRoot::ParserArenaRoot):
(JSC::ParserArenaRefCounted::ParserArenaRefCounted): Deleted.

* parser/Nodes.cpp:
(JSC::ScopeNode::ScopeNode):
(JSC::ProgramNode::ProgramNode):
(JSC::EvalNode::EvalNode):
(JSC::FunctionNode::FunctionNode):
(JSC::ProgramNode::create): Deleted.
(JSC::EvalNode::create): Deleted.
(JSC::FunctionNode::create): Deleted. All special create semantics can
just go away now that we play by C++ constructor / destructor rules.

* parser/Nodes.h:
(JSC::ParserArenaRoot::parserArena):
(JSC::ParserArenaRoot::~ParserArenaRoot): Just a normal class now, which
holds onto the whole parse tree by virtue of owning the arena in which
all the parsed nodes (except for itself) were allocated.

(JSC::ProgramNode::closedVariables):
(JSC::ParserArenaRefCounted::~ParserArenaRefCounted): Deleted.

(JSC::ScopeNode::destroyData): Deleted. No need to destroy anything
explicitly anymore -- we can just rely on destructors.

(JSC::ScopeNode::parserArena): Deleted.

* parser/Parser.h:
(JSC::Parser<LexerType>::parse):
(JSC::parse): unique_ptr all the things.

* parser/ParserArena.cpp:
(JSC::ParserArena::reset):
(JSC::ParserArena::isEmpty):
(JSC::ParserArena::contains): Deleted.
(JSC::ParserArena::last): Deleted.
(JSC::ParserArena::removeLast): Deleted.
(JSC::ParserArena::derefWithArena): Deleted.
* parser/ParserArena.h:
(JSC::ParserArena::swap): Much delete. Such wow.

* runtime/CodeCache.cpp:
(JSC::CodeCache::getGlobalCodeBlock):
(JSC::CodeCache::getFunctionExecutableFromGlobalCode):
* runtime/Completion.cpp:
(JSC::checkSyntax):
* runtime/Executable.cpp:
(JSC::ProgramExecutable::checkSyntax): unique_ptr all the things.


git-svn-id: http://svn.webkit.org/repository/webkit/trunk@176825 268f45cc-cd09-0410-ab3c-d52691b4dbfc
Make API::String copy the underlying strings if needed, for thread safety
https://bugs.webkit.org/show_bug.cgi?id=139261

Reviewed by Sam Weinig.

Source/WebKit2:

* Shared/API/c/WKString.cpp:
(WKStringCreateWithUTF8CString):
(WKStringCreateWithJSString):
(WKStringCopyJSString):
Move the implementations from API::String and directly into the API functions.

* Shared/APIString.h:
Add a create overload that takes an rvalue reference. Call it from the create overload
that takes an lvalue reference, but explicitly copy the string.
We call isolatedCopy() again on the string in the rvalue reference overload, but that is a no-op
if the string can be sent to another thread. Add assertions in the String constructor that we can
send the string to another thread.

Source/WTF:

* wtf/RefPtr.h:
(WTF::RefPtr<T>::leakRef):
Add a leakRef() to RefPtr so we don't have to go through PassRefPtr.

* wtf/text/WTFString.cpp:
(WTF::String::isSafeToSendToAnotherThread):
Check if the string is empty before checking whether it's in an atomic string table.
It's safe to send empty strings to other threads even if they're in the atomic string table
since they will never be deallocated.

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@176826 268f45cc-cd09-0410-ab3c-d52691b4dbfc
Don't use NeverDestroyed with a RefCounted object.

* WebCoreSupport/WebVisitedLinkStore.cpp:
(WebVisitedLinkStore::shared):

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@176827 268f45cc-cd09-0410-ab3c-d52691b4dbfc
printInternal(PrintStream& out, JSC::JITCode::JITType type) ends up dumping a literal %s
https://bugs.webkit.org/show_bug.cgi?id=139274

Reviewed by Geoffrey Garen.

* jit/JITCode.cpp:
(WTF::printInternal):


git-svn-id: http://svn.webkit.org/repository/webkit/trunk@176828 268f45cc-cd09-0410-ab3c-d52691b4dbfc
Add missing includes in preparation for making toAPI require that it's passed an API::Object
https://bugs.webkit.org/show_bug.cgi?id=139278

Reviewed by Tim Horton.

* UIProcess/API/C/WKAuthenticationChallenge.cpp:
* UIProcess/API/C/WKAuthenticationDecisionListener.cpp:
* UIProcess/API/C/WKContext.cpp:
* UIProcess/API/C/WKDownload.cpp:
* UIProcess/API/C/WKFrame.cpp:
* UIProcess/API/C/WKGeolocationManager.cpp:
* UIProcess/API/C/WKInspector.cpp:
* UIProcess/API/C/WKPage.cpp:
* UIProcess/GenericCallback.h:
* UIProcess/Notifications/WebNotificationProvider.cpp:
* UIProcess/WebContextConnectionClient.cpp:
* UIProcess/WebContextInjectedBundleClient.cpp:
* UIProcess/WebCookieManagerProxyClient.cpp:
* UIProcess/WebDatabaseManagerProxyClient.cpp:
* UIProcess/WebFindClient.cpp:
* UIProcess/WebFormClient.cpp:
* UIProcess/WebIconDatabaseClient.cpp:
* UIProcess/WebPageContextMenuClient.cpp:
* WebProcess/InjectedBundle/API/c/WKBundle.cpp:
* WebProcess/InjectedBundle/API/c/WKBundleDOMWindowExtension.cpp:
* WebProcess/InjectedBundle/API/c/WKBundleFrame.cpp:
* WebProcess/InjectedBundle/API/c/WKBundleHitTestResult.cpp:
* WebProcess/InjectedBundle/API/c/WKBundlePage.cpp:
* WebProcess/InjectedBundle/InjectedBundleClient.cpp:
* WebProcess/InjectedBundle/InjectedBundlePageFormClient.cpp:
* WebProcess/InjectedBundle/InjectedBundlePageLoaderClient.cpp:
* WebProcess/InjectedBundle/InjectedBundlePagePolicyClient.cpp:
* WebProcess/InjectedBundle/InjectedBundlePageResourceLoadClient.cpp:
* WebProcess/InjectedBundle/InjectedBundlePageUIClient.cpp:

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@176829 268f45cc-cd09-0410-ab3c-d52691b4dbfc