Browse Source

Javascript class refactor

master
Odilitime 2 years ago
parent
commit
3bb37573ee
1 changed files with 8 additions and 5 deletions
  1. 8
    5
      src/interfaces/elements/SCRIPTElement.cpp

+ 8
- 5
src/interfaces/elements/SCRIPTElement.cpp View File

@@ -46,18 +46,21 @@ std::unique_ptr<Component> SCRIPTElement::renderer(const ElementRenderRequest &r
}
// parse JS
//std::cout << "SCRIPTElement::renderer - source: " << source << std::endl;
JSParser parser;
std::shared_ptr<JavaScript> newScript = std::make_shared<JavaScript>();
// import current state (scope)
newScript = parser.append(newScript, request.docComponent->mainScript);
newScript->applyScope(request.docComponent->mainScript);
// parse it
const std::clock_t begin = clock();
newScript->tokens = parser.getTokens(source);
parser.parseTokens(newScript->tokens, &newScript->rootScope);
newScript->parse(source);
//newScript->tokens = parser.getTokens(source);
//parser.parseTokens(newScript->tokens, &newScript->rootScope);
newScript->execute();
const std::clock_t end = clock();
logDebug() << "SCRIPTElement::renderer - Parsed javascript in: " << std::fixed << ((static_cast<double>(end - begin)) / CLOCKS_PER_SEC) << std::scientific << " seconds" << std::endl;
// and flush our state back into mainScript
request.docComponent->mainScript = parser.append(request.docComponent->mainScript, newScript);
//request.docComponent->mainScript = parser.append(request.docComponent->mainScript, newScript);
request.docComponent->mainScript->applyScope(newScript);
request.docComponent->mainScript->append(newScript);
}
return nullptr;
}

Loading…
Cancel
Save