Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(112)

Unified Diff: test/unittests/compiler-dispatcher/compiler-dispatcher-job-unittest.cc

Issue 2198043002: Add a mode to completely deserialize scope chains (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: gcmole Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: test/unittests/compiler-dispatcher/compiler-dispatcher-job-unittest.cc
diff --git a/test/unittests/compiler-dispatcher/compiler-dispatcher-job-unittest.cc b/test/unittests/compiler-dispatcher/compiler-dispatcher-job-unittest.cc
index 480c3abe68181bbc67f647aa55d62706ee6ca8e0..83311c5096224bcb79ffd7839eb6307940714ead 100644
--- a/test/unittests/compiler-dispatcher/compiler-dispatcher-job-unittest.cc
+++ b/test/unittests/compiler-dispatcher/compiler-dispatcher-job-unittest.cc
@@ -4,9 +4,12 @@
#include <memory>
+#include "src/ast/scopes.h"
#include "src/compiler-dispatcher/compiler-dispatcher-job.h"
+#include "src/compiler.h"
#include "src/flags.h"
#include "src/isolate-inl.h"
+#include "src/parsing/parser.h"
#include "test/unittests/test-utils.h"
#include "testing/gtest/include/gtest/gtest.h"
@@ -17,6 +20,8 @@ typedef TestWithContext CompilerDispatcherJobTest;
namespace {
+const char test_script[] = "x*x";
+
class ScriptResource : public v8::String::ExternalOneByteStringResource {
public:
ScriptResource(const char* data, size_t length)
@@ -42,20 +47,30 @@ Handle<JSFunction> CreateFunction(
->NewExternalStringFromOneByte(maybe_resource)
.ToHandleChecked();
} else {
- source = isolate->factory()->NewStringFromStaticChars("source");
+ source = isolate->factory()->NewStringFromAsciiChecked(test_script);
}
Handle<Script> script = isolate->factory()->NewScript(source);
Handle<SharedFunctionInfo> shared = isolate->factory()->NewSharedFunctionInfo(
- isolate->factory()->NewStringFromStaticChars("f"), MaybeHandle<Code>(),
+ isolate->factory()->NewStringFromAsciiChecked("f"), MaybeHandle<Code>(),
false);
SharedFunctionInfo::SetScript(shared, script);
- shared->set_end_position(source->length() - 1);
+ shared->set_end_position(source->length());
Handle<JSFunction> function =
isolate->factory()->NewFunctionFromSharedFunctionInfo(
shared, handle(isolate->context(), isolate));
return scope.CloseAndEscape(function);
}
+Handle<Context> GetScopeWithVariable(Isolate* isolate, const char* var) {
marja 2016/08/03 08:07:48 This function name is surprising given that it doe
jochen (gone - plz use gerrit) 2016/08/03 09:14:49 done
+ HandleScope handle_scope(isolate);
+ Handle<JSFunction> closure(isolate->native_context()->closure());
+ Handle<Context> context = isolate->factory()->NewCatchContext(
+ closure, handle(isolate->context()),
+ isolate->factory()->NewStringFromAsciiChecked(var),
+ isolate->factory()->undefined_value());
+ return handle_scope.CloseAndEscape(context);
+}
+
} // namespace
TEST_F(CompilerDispatcherJobTest, Construct) {
@@ -70,7 +85,7 @@ TEST_F(CompilerDispatcherJobTest, CanParseOnBackgroundThread) {
ASSERT_FALSE(job->can_parse_on_background_thread());
}
{
- ScriptResource script("script", strlen("script"));
+ ScriptResource script(test_script, strlen(test_script));
std::unique_ptr<CompilerDispatcherJob> job(new CompilerDispatcherJob(
i_isolate(), CreateFunction(i_isolate(), &script), FLAG_stack_size));
ASSERT_TRUE(job->can_parse_on_background_thread());
@@ -108,5 +123,30 @@ TEST_F(CompilerDispatcherJobTest, SyntaxError) {
ASSERT_TRUE(i_isolate()->has_pending_exception());
}
+TEST_F(CompilerDispatcherJobTest, ScopeChain) {
+ Handle<Context> outter_scope = GetScopeWithVariable(i_isolate(), "g");
marja 2016/08/03 08:07:48 Typo: outter
jochen (gone - plz use gerrit) 2016/08/03 09:14:49 done
+ const char source[] = "g = 1;";
+ ScriptResource script(source, strlen(source));
+ Handle<JSFunction> fun = CreateFunction(i_isolate(), &script);
+ fun->set_context(*outter_scope);
+
+ std::unique_ptr<CompilerDispatcherJob> job(
+ new CompilerDispatcherJob(i_isolate(), fun, FLAG_stack_size));
+ job->PrepareToParseOnMainThread();
+ job->Parse();
+ job->FinalizeParsingOnMainThread();
+ ASSERT_TRUE(job->status() == CompileJobStatus::kReadyToCompile);
+
+ Scope* scope = job->parse_info_->literal()->scope();
+ Scope* inner_scope = scope->inner_scope();
+ const AstRawString* var_name =
+ job->parse_info_->ast_value_factory()->GetOneByteString("g");
+ Variable* var = inner_scope->Lookup(var_name);
+ ASSERT_TRUE(var);
+ ASSERT_TRUE(var->IsContextSlot());
marja 2016/08/03 08:07:48 Hmm, this test is not clear to me... Is g a functi
jochen (gone - plz use gerrit) 2016/08/03 09:14:49 well, without the parsing step, there is no litera
+
+ job->ResetOnMainThread();
+}
+
} // namespace internal
} // namespace v8

Powered by Google App Engine
This is Rietveld 408576698