Ignore:
Timestamp:
Mar 16, 2015, 9:02:52 PM (10 years ago)
Author:
[email protected]
Message:

Source/JavaScriptCore:
Add support for default constructor
https://bugs.webkit.org/show_bug.cgi?id=142388

Reviewed by Filip Pizlo.

Added the support for default constructors. They're generated by ClassExprNode::emitBytecode
via BuiltinExecutables::createDefaultConstructor.

UnlinkedFunctionExecutable now has the ability to override SourceCode provided by the owner
executable. We can't make store SourceCode in UnlinkedFunctionExecutable since CodeCache can use
the same UnlinkedFunctionExecutable to generate code blocks for multiple functions.

Parser now has the ability to treat any function expression as a constructor of the kind specified
by m_defaultConstructorKind member variable.

  • builtins/BuiltinExecutables.cpp:

(JSC::BuiltinExecutables::createDefaultConstructor): Added.
(JSC::BuiltinExecutables::createExecutableInternal): Generalized from createBuiltinExecutable.
Parse default constructors as normal non-builtin functions. Override SourceCode in the unlinked
function executable since the Miranda function's code is definitely not in the owner executable's
source code. That's the whole point.

  • builtins/BuiltinExecutables.h:

(UnlinkedFunctionExecutable::createBuiltinExecutable): Added. Wraps createExecutableInternal.

  • bytecode/UnlinkedCodeBlock.cpp:

(JSC::UnlinkedFunctionExecutable::UnlinkedFunctionExecutable):
(JSC::UnlinkedFunctionExecutable::linkInsideExecutable):
(JSC::UnlinkedFunctionExecutable::linkGlobalCode):

  • bytecode/UnlinkedCodeBlock.h:

(JSC::UnlinkedFunctionExecutable::create):
(JSC::UnlinkedFunctionExecutable::symbolTable): Deleted.

  • bytecompiler/BytecodeGenerator.cpp:

(JSC::BytecodeGenerator::emitNewDefaultConstructor): Added.

  • bytecompiler/BytecodeGenerator.h:
  • bytecompiler/NodesCodegen.cpp:

(JSC::ClassExprNode::emitBytecode): Generate the default constructor if needed.

  • parser/Parser.cpp:

(JSC::Parser<LexerType>::Parser):
(JSC::Parser<LexerType>::parseFunctionInfo): Override ownerClassKind and assume the function as
a constructor if we're parsing a default constructor.
(JSC::Parser<LexerType>::parseClass): Allow omission of the class constructor.

  • parser/Parser.h:

(JSC::parse):

LayoutTests:
Implement default constructor

Add support for default constructor
https://bugs.webkit.org/show_bug.cgi?id=142388

Reviewed by Filip Pizlo.

Added tests for default constructors.

  • TestExpectations: Skipped the test since ES6 class syntax isn't enabled by default.
  • js/class-syntax-default-constructor-expected.txt: Added.
  • js/class-syntax-default-constructor.html: Added.
  • js/script-tests/class-syntax-default-constructor.js: Added.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/JavaScriptCore/builtins/BuiltinExecutables.h

    r181248 r181611  
    2828
    2929#include "JSCBuiltins.h"
     30#include "ParserModes.h"
    3031#include "SourceCode.h"
    3132#include "Weak.h"
     
    4950    JSC_FOREACH_BUILTIN(EXPOSE_BUILTIN_EXECUTABLES)
    5051#undef EXPOSE_BUILTIN_SOURCES
    51    
     52
     53    UnlinkedFunctionExecutable* createDefaultConstructor(ConstructorKind, const Identifier& name);
     54
    5255private:
    5356    void finalize(Handle<Unknown>, void* context) override;
    5457
    5558    VM& m_vm;
    56     UnlinkedFunctionExecutable* createBuiltinExecutable(const SourceCode&, const Identifier&);
     59
     60    UnlinkedFunctionExecutable* createBuiltinExecutable(const SourceCode& code, const Identifier& name)
     61    {
     62        return createExecutableInternal(code, name, ConstructorKind::None);
     63    }
     64    UnlinkedFunctionExecutable* createExecutableInternal(const SourceCode&, const Identifier&, ConstructorKind);
     65
    5766#define DECLARE_BUILTIN_SOURCE_MEMBERS(name, functionName, length)\
    5867    SourceCode m_##name##Source; \
Note: See TracChangeset for help on using the changeset viewer.