Skip to content

Commit

Permalink
Error quickly if the embedder tries to load after Dart_Precompile.
Browse files Browse the repository at this point in the history
R=srdjan@google.com

Review URL: https://codereview.chromium.org/1377733007 .
  • Loading branch information
rmacnak-google committed Oct 6, 2015
1 parent 150e8d2 commit 26c187d
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
6 changes: 6 additions & 0 deletions runtime/vm/dart_api_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5075,6 +5075,7 @@ DART_EXPORT Dart_Handle Dart_LoadScript(Dart_Handle url,
CURRENT_FUNC);
}
CHECK_CALLBACK_STATE(I);
CHECK_COMPILATION_ALLOWED(I);

NoHeapGrowthControlScope no_growth_control;

Expand Down Expand Up @@ -5118,6 +5119,7 @@ DART_EXPORT Dart_Handle Dart_LoadScriptFromSnapshot(const uint8_t* buffer,
CURRENT_FUNC, library_url.ToCString());
}
CHECK_CALLBACK_STATE(I);
CHECK_COMPILATION_ALLOWED(I);

ASSERT(snapshot->kind() == Snapshot::kScript);
ScriptSnapshotReader reader(snapshot->content(), snapshot->length(), T);
Expand Down Expand Up @@ -5311,6 +5313,7 @@ DART_EXPORT Dart_Handle Dart_LoadLibrary(Dart_Handle url,
CURRENT_FUNC);
}
CHECK_CALLBACK_STATE(I);
CHECK_COMPILATION_ALLOWED(I);

NoHeapGrowthControlScope no_growth_control;

Expand Down Expand Up @@ -5368,6 +5371,7 @@ DART_EXPORT Dart_Handle Dart_LibraryImportLibrary(Dart_Handle library,
RETURN_TYPE_ERROR(I, prefix, String);
}
CHECK_CALLBACK_STATE(I);
CHECK_COMPILATION_ALLOWED(I);

const String& prefix_symbol = String::Handle(Z, Symbols::New(prefix_vm));
const Namespace& import_ns = Namespace::Handle(Z,
Expand Down Expand Up @@ -5416,6 +5420,7 @@ DART_EXPORT Dart_Handle Dart_LoadSource(Dart_Handle library,
CURRENT_FUNC);
}
CHECK_CALLBACK_STATE(I);
CHECK_COMPILATION_ALLOWED(I);

NoHeapGrowthControlScope no_growth_control;

Expand Down Expand Up @@ -5445,6 +5450,7 @@ DART_EXPORT Dart_Handle Dart_LibraryLoadPatch(Dart_Handle library,
RETURN_TYPE_ERROR(I, patch_source, String);
}
CHECK_CALLBACK_STATE(I);
CHECK_COMPILATION_ALLOWED(I);

NoHeapGrowthControlScope no_growth_control;

Expand Down
6 changes: 6 additions & 0 deletions runtime/vm/dart_api_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,12 @@ class IsolateSaver {
return reinterpret_cast<Dart_Handle>(Api::AcquiredError(isolate)); \
} \

#define CHECK_COMPILATION_ALLOWED(isolate) \
if (!isolate->compilation_allowed()) { \
return Api::NewError("%s: Cannot load after Dart_Precompile", \
CURRENT_FUNC); \
} \

#define ASSERT_CALLBACK_STATE(isolate) \
ASSERT(isolate->no_callback_scope_depth() == 0)

Expand Down

0 comments on commit 26c187d

Please sign in to comment.