diff options
author | Aaron Kennedy <aaron.kennedy@nokia.com> | 2011-10-27 13:34:16 +0100 |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2013-01-09 13:06:01 +0100 |
commit | 194da71eed49e4d5e904e8c28cb510fb85b95912 (patch) | |
tree | 4bb40c02292e8fe51c1e975b09727b710748668c /src/3rdparty/v8/src/parser.cc | |
parent | 504ef4cafdbc0c927d9f86ef21d9e7db757fd110 (diff) | |
download | qtjsbackend-194da71eed49e4d5e904e8c28cb510fb85b95912.tar.gz |
[V8] Introduce a QML compilation mode
In QML mode, there is a second global object - known as the QML
global object. During property resolution, if a property is not
present on the JS global object, it is resolved on the QML global
object.
This global object behavior is only enabled if a script is being
compiled in QML mode. The object to use as the QML global object
is passed as a parameter to the Script::Run() method. Any function
closures etc. created during the run will retain a reference to this
object, so different objects can be passed in different script
runs.
Change-Id: I75d6f8173260e0d4933fd33ad16a277542048f09
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
Diffstat (limited to 'src/3rdparty/v8/src/parser.cc')
-rw-r--r-- | src/3rdparty/v8/src/parser.cc | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/src/3rdparty/v8/src/parser.cc b/src/3rdparty/v8/src/parser.cc index 129bd95..da4685f 100644 --- a/src/3rdparty/v8/src/parser.cc +++ b/src/3rdparty/v8/src/parser.cc @@ -639,6 +639,9 @@ FunctionLiteral* Parser::DoParseProgram(CompilationInfo* info, FunctionState function_state(this, scope, isolate()); // Enters 'scope'. top_scope_->SetLanguageMode(info->language_mode()); + if (info->is_qml_mode()) { + scope->EnableQmlModeFlag(); + } ZoneList<Statement*>* body = new(zone()) ZoneList<Statement*>(16, zone()); bool ok = true; int beg_loc = scanner().location().beg_pos; @@ -745,6 +748,9 @@ FunctionLiteral* Parser::ParseLazy(Utf16CharacterStream* source, info()->is_extended_mode()); ASSERT(info()->language_mode() == shared_info->language_mode()); scope->SetLanguageMode(shared_info->language_mode()); + if (shared_info->qml_mode()) { + top_scope_->EnableQmlModeFlag(); + } FunctionLiteral::Type type = shared_info->is_expression() ? (shared_info->is_anonymous() ? FunctionLiteral::ANONYMOUS_EXPRESSION @@ -1782,6 +1788,25 @@ void Parser::Declare(Declaration* declaration, bool resolve, bool* ok) { // both access to the static and the dynamic context chain; the // runtime needs to provide both. if (resolve && var != NULL) { + if (declaration_scope->is_qml_mode()) { + Handle<GlobalObject> global = isolate_->global_object(); + +#ifdef ENABLE_DEBUGGER_SUPPORT + if (isolate_->debug()->IsLoaded() && isolate_->debug()->InDebugger()) { + // Get the context before the debugger was entered. + SaveContext *save = isolate_->save_context(); + while (save != NULL && *save->context() == *isolate_->debug()->debug_context()) + save = save->prev(); + + global = Handle<GlobalObject>(save->context()->global_object()); + } +#endif + + if (!global->HasProperty(*(proxy->name()))) { + var->set_is_qml_global(true); + } + } + proxy->BindTo(var); if (FLAG_harmony_modules) { @@ -2219,6 +2244,12 @@ Block* Parser::ParseVariableDeclarations( arguments->Add(value, zone()); value = NULL; // zap the value to avoid the unnecessary assignment + int qml_mode = 0; + if (top_scope_->is_qml_mode() + && !Isolate::Current()->global_object()->HasProperty(*name)) + qml_mode = 1; + arguments->Add(factory()->NewNumberLiteral(qml_mode), zone()); + // Construct the call to Runtime_InitializeConstGlobal // and add it to the initialization statement block. // Note that the function does different things depending on @@ -2233,6 +2264,12 @@ Block* Parser::ParseVariableDeclarations( LanguageMode language_mode = initialization_scope->language_mode(); arguments->Add(factory()->NewNumberLiteral(language_mode), zone()); + int qml_mode = 0; + if (top_scope_->is_qml_mode() + && !Isolate::Current()->global_object()->HasProperty(*name)) + qml_mode = 1; + arguments->Add(factory()->NewNumberLiteral(qml_mode), zone()); + // Be careful not to assign a value to the global variable if // we're in a with. The initialization value should not // necessarily be stored in the global object in that case, |