Create proper template objects

Create the proper template object for a tagged template.
This fixes quite a few use cases (esp. String.raw), but is not
yet 100% spec compliant.

Change-Id: I69eaee22c384c0d1bd2c6c56ad711d29521b0b86
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
This commit is contained in:
Lars Knoll 2018-10-12 16:17:20 +02:00
parent 4241ce2cfc
commit 9755cf48cb
2 changed files with 40 additions and 30 deletions

View File

@ -2260,8 +2260,6 @@ int Codegen::createTemplateArray(TemplateLiteral *t)
{
int arrayTemp = bytecodeGenerator->newRegister();
RegisterScope scope(this);
int argc = 0;
int args = -1;
auto push = [this, &argc, &args](const QStringRef &arg) {
@ -2278,22 +2276,50 @@ int Codegen::createTemplateArray(TemplateLiteral *t)
++argc;
};
for (TemplateLiteral *it = t; it; it = it->next)
push(it->value);
{
RegisterScope scope(this);
if (args == -1) {
Q_ASSERT(argc == 0);
args = 0;
for (TemplateLiteral *it = t; it; it = it->next)
push(it->value);
if (args == -1) {
Q_ASSERT(argc == 0);
args = 0;
}
Instruction::DefineArray call;
call.argc = argc;
call.args = Moth::StackSlot::createRegister(args);
bytecodeGenerator->addInstruction(call);
Instruction::StoreReg store;
store.reg = arrayTemp;
bytecodeGenerator->addInstruction(store);
}
Instruction::DefineArray call;
call.argc = argc;
call.args = Moth::StackSlot::createRegister(args);
bytecodeGenerator->addInstruction(call);
{
RegisterScope scope(this);
Instruction::StoreReg store;
store.reg = arrayTemp;
bytecodeGenerator->addInstruction(store);
argc = 0;
args = -1;
for (TemplateLiteral *it = t; it; it = it->next)
push(it->rawValue);
if (args == -1) {
Q_ASSERT(argc == 0);
args = 0;
}
Instruction::DefineArray call;
call.argc = argc;
call.args = Moth::StackSlot::createRegister(args);
bytecodeGenerator->addInstruction(call);
Reference a = Reference::fromStackSlot(this, arrayTemp);
Reference m = Reference::fromMember(a, QStringLiteral("raw"));
m.storeConsumeAccumulator();
}
return arrayTemp;
}

View File

@ -224,10 +224,6 @@ built-ins/String/prototype/toLocaleLowerCase/Final_Sigma_U180E.js fails
built-ins/String/prototype/toLocaleLowerCase/special_casing_conditional.js fails
built-ins/String/prototype/toLowerCase/Final_Sigma_U180E.js fails
built-ins/String/prototype/toLowerCase/special_casing_conditional.js fails
built-ins/String/raw/return-the-string-value-from-template.js fails
built-ins/String/raw/special-characters.js fails
built-ins/String/raw/template-substitutions-are-appended-on-same-index.js fails
built-ins/String/raw/zero-literal-segments.js fails
built-ins/TypedArray/from/arylk-get-length-error.js fails
built-ins/TypedArray/from/arylk-to-length-error.js fails
built-ins/TypedArray/from/iter-access-error.js fails
@ -580,19 +576,7 @@ language/expressions/tagged-template/tco-member.js strictFails
language/expressions/tagged-template/template-object-frozen-non-strict.js sloppyFails
language/expressions/tagged-template/template-object-frozen-strict.js strictFails
language/expressions/tagged-template/template-object.js fails
language/expressions/template-literal/tv-character-escape-sequence.js fails
language/expressions/template-literal/tv-hex-escape-sequence.js fails
language/expressions/template-literal/tv-line-continuation.js fails
language/expressions/template-literal/tv-line-terminator-sequence.js fails
language/expressions/template-literal/tv-no-substitution.js fails
language/expressions/template-literal/tv-null-character-escape-sequence.js fails
language/expressions/template-literal/tv-template-character.js fails
language/expressions/template-literal/tv-template-characters.js fails
language/expressions/template-literal/tv-template-head.js fails
language/expressions/template-literal/tv-template-middle.js fails
language/expressions/template-literal/tv-template-tail.js fails
language/expressions/template-literal/tv-utf16-escape-sequence.js fails
language/expressions/template-literal/tv-zwnbsp.js fails
language/function-code/each-param-has-own-non-shared-eval-scope.js sloppyFails
language/function-code/each-param-has-own-scope.js sloppyFails
language/function-code/eval-param-env-with-computed-key.js sloppyFails