// A LocalContext holds a reference to a v8::Context.
class LocalContext {
public:
- LocalContext(v8::Isolate* isolate,
- v8::ExtensionConfiguration* extensions = 0,
- v8::Handle<v8::ObjectTemplate> global_template =
- v8::Handle<v8::ObjectTemplate>(),
- v8::Handle<v8::Value> global_object = v8::Handle<v8::Value>()) {
+ LocalContext(v8::Isolate* isolate, v8::ExtensionConfiguration* extensions = 0,
+ v8::Local<v8::ObjectTemplate> global_template =
+ v8::Local<v8::ObjectTemplate>(),
+ v8::Local<v8::Value> global_object = v8::Local<v8::Value>()) {
Initialize(isolate, extensions, global_template, global_object);
}
LocalContext(v8::ExtensionConfiguration* extensions = 0,
- v8::Handle<v8::ObjectTemplate> global_template =
- v8::Handle<v8::ObjectTemplate>(),
- v8::Handle<v8::Value> global_object = v8::Handle<v8::Value>()) {
+ v8::Local<v8::ObjectTemplate> global_template =
+ v8::Local<v8::ObjectTemplate>(),
+ v8::Local<v8::Value> global_object = v8::Local<v8::Value>()) {
Initialize(CcTest::isolate(), extensions, global_template, global_object);
}
}
private:
- void Initialize(v8::Isolate* isolate,
- v8::ExtensionConfiguration* extensions,
- v8::Handle<v8::ObjectTemplate> global_template,
- v8::Handle<v8::Value> global_object) {
+ void Initialize(v8::Isolate* isolate, v8::ExtensionConfiguration* extensions,
+ v8::Local<v8::ObjectTemplate> global_template,
+ v8::Local<v8::Value> global_object) {
v8::HandleScope scope(isolate);
v8::Local<v8::Context> context = v8::Context::New(isolate,
extensions,
static inline v8::Local<v8::String> v8_str(const char* x) {
- return v8::String::NewFromUtf8(v8::Isolate::GetCurrent(), x);
+ return v8::String::NewFromUtf8(v8::Isolate::GetCurrent(), x,
+ v8::NewStringType::kNormal)
+ .ToLocalChecked();
}
}
-static inline v8::Local<v8::Script> v8_compile(const char* x) {
- return v8::Script::Compile(v8_str(x));
+static inline v8::Local<v8::Script> v8_compile(v8::Local<v8::String> x) {
+ v8::Local<v8::Script> result;
+ if (v8::Script::Compile(v8::Isolate::GetCurrent()->GetCurrentContext(), x)
+ .ToLocal(&result)) {
+ return result;
+ }
+ return v8::Local<v8::Script>();
}
-static inline v8::Local<v8::Script> v8_compile(v8::Local<v8::String> x) {
- return v8::Script::Compile(x);
+static inline v8::Local<v8::Script> v8_compile(const char* x) {
+ return v8_compile(v8_str(x));
}
v8::ScriptOrigin origin(origin_url);
v8::ScriptCompiler::Source script_source(source, origin);
return v8::ScriptCompiler::Compile(
- v8::Isolate::GetCurrent(), &script_source);
+ v8::Isolate::GetCurrent()->GetCurrentContext(), &script_source)
+ .ToLocalChecked();
}
// Helper functions that compile and run the source.
-static inline v8::Local<v8::Value> CompileRun(const char* source) {
- return v8::Script::Compile(v8_str(source))->Run();
+static inline v8::MaybeLocal<v8::Value> CompileRun(
+ v8::Local<v8::Context> context, const char* source) {
+ return v8::Script::Compile(context, v8_str(source))
+ .ToLocalChecked()
+ ->Run(context);
+}
+
+
+static inline v8::Local<v8::Value> CompileRun(v8::Local<v8::String> source) {
+ v8::Local<v8::Value> result;
+ if (v8_compile(source)
+ ->Run(v8::Isolate::GetCurrent()->GetCurrentContext())
+ .ToLocal(&result)) {
+ return result;
+ }
+ return v8::Local<v8::Value>();
}
// Helper functions that compile and run the source.
-static inline v8::MaybeLocal<v8::Value> CompileRun(
- v8::Local<v8::Context> context, const char* source) {
- return v8::Script::Compile(v8_str(source))->Run(context);
+static inline v8::Local<v8::Value> CompileRun(const char* source) {
+ return CompileRun(v8_str(source));
}
-static inline v8::Local<v8::Value> CompileRun(v8::Local<v8::String> source) {
- return v8::Script::Compile(source)->Run();
+static inline v8::Local<v8::Value> CompileRun(
+ v8::Local<v8::Context> context, v8::ScriptCompiler::Source* script_source,
+ v8::ScriptCompiler::CompileOptions options) {
+ v8::Local<v8::Value> result;
+ if (v8::ScriptCompiler::Compile(context, script_source, options)
+ .ToLocalChecked()
+ ->Run(context)
+ .ToLocal(&result)) {
+ return result;
+ }
+ return v8::Local<v8::Value>();
}
// Compile once just to get the preparse data, then compile the second time
// using the data.
v8::Isolate* isolate = v8::Isolate::GetCurrent();
+ v8::Local<v8::Context> context = isolate->GetCurrentContext();
v8::ScriptCompiler::Source script_source(v8_str(source));
- v8::ScriptCompiler::Compile(isolate, &script_source,
- v8::ScriptCompiler::kProduceParserCache);
+ v8::ScriptCompiler::Compile(context, &script_source,
+ v8::ScriptCompiler::kProduceParserCache)
+ .ToLocalChecked();
// Check whether we received cached data, and if so use it.
v8::ScriptCompiler::CompileOptions options =
script_source.GetCachedData() ? v8::ScriptCompiler::kConsumeParserCache
: v8::ScriptCompiler::kNoCompileOptions;
- return v8::ScriptCompiler::Compile(isolate, &script_source, options)->Run();
+ return CompileRun(context, &script_source, options);
}
int line_number,
int column_number) {
v8::Isolate* isolate = v8::Isolate::GetCurrent();
+ v8::Local<v8::Context> context = isolate->GetCurrentContext();
v8::ScriptOrigin origin(v8_str(origin_url),
v8::Integer::New(isolate, line_number),
v8::Integer::New(isolate, column_number));
v8::ScriptCompiler::Source script_source(v8_str(source), origin);
- return v8::ScriptCompiler::Compile(isolate, &script_source)->Run();
+ return CompileRun(context, &script_source,
+ v8::ScriptCompiler::CompileOptions());
}
static inline v8::Local<v8::Value> CompileRunWithOrigin(
v8::Local<v8::String> source, const char* origin_url) {
+ v8::Isolate* isolate = v8::Isolate::GetCurrent();
+ v8::Local<v8::Context> context = isolate->GetCurrentContext();
v8::ScriptCompiler::Source script_source(
source, v8::ScriptOrigin(v8_str(origin_url)));
- return v8::ScriptCompiler::Compile(v8::Isolate::GetCurrent(), &script_source)
- ->Run();
+ return CompileRun(context, &script_source,
+ v8::ScriptCompiler::CompileOptions());
}
static inline void ExpectInt32(const char* code, int expected) {
v8::Local<v8::Value> result = CompileRun(code);
CHECK(result->IsInt32());
- CHECK_EQ(expected, result->Int32Value());
+ CHECK_EQ(expected,
+ result->Int32Value(v8::Isolate::GetCurrent()->GetCurrentContext())
+ .FromJust());
}
static inline void ExpectBoolean(const char* code, bool expected) {
v8::Local<v8::Value> result = CompileRun(code);
CHECK(result->IsBoolean());
- CHECK_EQ(expected, result->BooleanValue());
+ CHECK_EQ(expected,
+ result->BooleanValue(v8::Isolate::GetCurrent()->GetCurrentContext())
+ .FromJust());
}
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+// TODO(jochen): Remove this after the setting is turned on globally.
+#define V8_IMMINENT_DEPRECATION_WARNINGS
+
#include "src/v8.h"
#include "src/global-handles.h"
v8::Isolate* isolate = CcTest::isolate();
v8::Isolate::Scope isolate_scope(isolate);
v8::HandleScope scope(isolate);
- v8::Handle<v8::Context> context = v8::Context::New(isolate);
+ v8::Local<v8::Context> context = v8::Context::New(isolate);
v8::Context::Scope context_scope(context);
- v8::Handle<v8::Array> date_cache_version =
- v8::Handle<v8::Array>::Cast(CompileRun("%DateCacheVersion()"));
+ v8::Local<v8::Array> date_cache_version =
+ v8::Local<v8::Array>::Cast(CompileRun("%DateCacheVersion()"));
CHECK_EQ(1, static_cast<int32_t>(date_cache_version->Length()));
- CHECK(date_cache_version->Get(0)->IsNumber());
- CHECK_EQ(0.0, date_cache_version->Get(0)->NumberValue());
+ CHECK(date_cache_version->Get(context, 0).ToLocalChecked()->IsNumber());
+ CHECK_EQ(0.0, date_cache_version->Get(context, 0)
+ .ToLocalChecked()
+ ->NumberValue(context)
+ .FromJust());
v8::Date::DateTimeConfigurationChangeNotification(isolate);
CHECK_EQ(1, static_cast<int32_t>(date_cache_version->Length()));
- CHECK(date_cache_version->Get(0)->IsNumber());
- CHECK_EQ(1.0, date_cache_version->Get(0)->NumberValue());
+ CHECK(date_cache_version->Get(context, 0).ToLocalChecked()->IsNumber());
+ CHECK_EQ(1.0, date_cache_version->Get(context, 0)
+ .ToLocalChecked()
+ ->NumberValue(context)
+ .FromJust());
}