Commit 686616e4 authored by jochen@chromium.org's avatar jochen@chromium.org

Remove usage of deprecated APIs from samples

Also turn on deprecation warnings for samples

BUG=v8:3023
R=dcarney@chromium.org, svenpanne@chromium.org
LOG=n

Review URL: https://codereview.chromium.org/83313002

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@18007 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent de432db1
......@@ -99,7 +99,7 @@ enum MainCycleType {
const char* ToCString(const v8::String::Utf8Value& value);
void ReportException(v8::Isolate* isolate, v8::TryCatch* handler);
v8::Handle<v8::String> ReadFile(const char* name);
v8::Handle<v8::String> ReadFile(v8::Isolate* isolate, const char* name);
v8::Handle<v8::String> ReadLine();
void Print(const v8::FunctionCallbackInfo<v8::Value>& args);
......@@ -174,14 +174,14 @@ int RunMain(int argc, char* argv[]) {
} else if (strncmp(str, "--", 2) == 0) {
printf("Warning: unknown flag %s.\nTry --help for options\n", str);
} else if (strcmp(str, "-e") == 0 && i + 1 < argc) {
script_source = v8::String::New(argv[i + 1]);
script_name = v8::String::New("unnamed");
script_source = v8::String::NewFromUtf8(isolate, argv[i + 1]);
script_name = v8::String::NewFromUtf8(isolate, "unnamed");
i++;
script_param_counter++;
} else {
// Use argument as a name of file to load.
script_source = ReadFile(str);
script_name = v8::String::New(str);
script_source = ReadFile(isolate, str);
script_name = v8::String::NewFromUtf8(isolate, str);
if (script_source.IsEmpty()) {
printf("Error reading '%s'\n", str);
return 1;
......@@ -203,11 +203,12 @@ int RunMain(int argc, char* argv[]) {
v8::Handle<v8::ObjectTemplate> global = v8::ObjectTemplate::New();
// Bind the global 'print' function to the C++ Print callback.
global->Set(v8::String::New("print"), v8::FunctionTemplate::New(Print));
global->Set(v8::String::NewFromUtf8(isolate, "print"),
v8::FunctionTemplate::New(Print));
if (cycle_type == CycleInJs) {
// Bind the global 'read_line' function to the C++ Print callback.
global->Set(v8::String::New("read_line"),
global->Set(v8::String::NewFromUtf8(isolate, "read_line"),
v8::FunctionTemplate::New(ReadLine));
}
......@@ -277,7 +278,8 @@ bool RunCppCycle(v8::Handle<v8::Script> script,
v8::Locker lock(isolate);
#endif // ENABLE_DEBUGGER_SUPPORT
v8::Handle<v8::String> fun_name = v8::String::New("ProcessLine");
v8::Handle<v8::String> fun_name =
v8::String::NewFromUtf8(isolate, "ProcessLine");
v8::Handle<v8::Value> process_val = context->Global()->Get(fun_name);
// If there is no Process function, or if it is not a function,
......@@ -338,7 +340,7 @@ const char* ToCString(const v8::String::Utf8Value& value) {
// Reads a file into a v8 string.
v8::Handle<v8::String> ReadFile(const char* name) {
v8::Handle<v8::String> ReadFile(v8::Isolate* isolate, const char* name) {
FILE* file = fopen(name, "rb");
if (file == NULL) return v8::Handle<v8::String>();
......@@ -353,7 +355,8 @@ v8::Handle<v8::String> ReadFile(const char* name) {
i += read;
}
fclose(file);
v8::Handle<v8::String> result = v8::String::New(chars, size);
v8::Handle<v8::String> result =
v8::String::NewFromUtf8(isolate, chars, v8::String::kNormalString, size);
delete[] chars;
return result;
}
......@@ -417,7 +420,8 @@ void Print(const v8::FunctionCallbackInfo<v8::Value>& args) {
// function is called. Reads a string from standard input and returns.
void ReadLine(const v8::FunctionCallbackInfo<v8::Value>& args) {
if (args.Length() > 0) {
args.GetIsolate()->ThrowException(v8::String::New("Unexpected arguments"));
args.GetIsolate()->ThrowException(
v8::String::NewFromUtf8(args.GetIsolate(), "Unexpected arguments"));
return;
}
args.GetReturnValue().Set(ReadLine());
......@@ -435,8 +439,9 @@ v8::Handle<v8::String> ReadLine() {
#endif // ENABLE_DEBUGGER_SUPPORT
res = fgets(buffer, kBufferSize, stdin);
}
v8::Isolate* isolate = v8::Isolate::GetCurrent();
if (res == NULL) {
v8::Handle<v8::Primitive> t = v8::Undefined(v8::Isolate::GetCurrent());
v8::Handle<v8::Primitive> t = v8::Undefined(isolate);
return v8::Handle<v8::String>::Cast(t);
}
// Remove newline char
......@@ -446,5 +451,5 @@ v8::Handle<v8::String> ReadLine() {
break;
}
}
return v8::String::New(buffer);
return v8::String::NewFromUtf8(isolate, buffer);
}
......@@ -161,7 +161,8 @@ bool JsHttpRequestProcessor::Initialize(map<string, string>* opts,
// Create a template for the global object where we set the
// built-in global functions.
Handle<ObjectTemplate> global = ObjectTemplate::New();
global->Set(String::New("log"), FunctionTemplate::New(LogCallback));
global->Set(String::NewFromUtf8(GetIsolate(), "log"),
FunctionTemplate::New(LogCallback));
// Each processor gets its own context so different processors don't
// affect each other. Context::New returns a persistent handle which
......@@ -185,7 +186,7 @@ bool JsHttpRequestProcessor::Initialize(map<string, string>* opts,
// The script compiled and ran correctly. Now we fetch out the
// Process function from the global object.
Handle<String> process_name = String::New("Process");
Handle<String> process_name = String::NewFromUtf8(GetIsolate(), "Process");
Handle<Value> process_val = context->Global()->Get(process_name);
// If there is no Process function, or if it is not a function,
......@@ -244,10 +245,12 @@ bool JsHttpRequestProcessor::InstallMaps(map<string, string>* opts,
v8::Local<v8::Context>::New(GetIsolate(), context_);
// Set the options object as a property on the global object.
context->Global()->Set(String::New("options"), opts_obj);
context->Global()->Set(String::NewFromUtf8(GetIsolate(), "options"),
opts_obj);
Handle<Object> output_obj = WrapMap(output);
context->Global()->Set(String::New("output"), output_obj);
context->Global()->Set(String::NewFromUtf8(GetIsolate(), "output"),
output_obj);
return true;
}
......@@ -291,8 +294,8 @@ JsHttpRequestProcessor::~JsHttpRequestProcessor() {
// Dispose the persistent handles. When noone else has any
// references to the objects stored in the handles they will be
// automatically reclaimed.
context_.Dispose();
process_.Dispose();
context_.Reset();
process_.Reset();
}
......@@ -370,8 +373,9 @@ void JsHttpRequestProcessor::MapGet(Local<String> name,
// Otherwise fetch the value and wrap it in a JavaScript string
const string& value = (*iter).second;
info.GetReturnValue().Set(
String::New(value.c_str(), static_cast<int>(value.length())));
info.GetReturnValue().Set(String::NewFromUtf8(
info.GetIsolate(), value.c_str(), String::kNormalString,
static_cast<int>(value.length())));
}
......@@ -465,8 +469,9 @@ void JsHttpRequestProcessor::GetPath(Local<String> name,
const string& path = request->Path();
// Wrap the result in a JavaScript string and return it.
info.GetReturnValue().Set(
String::New(path.c_str(), static_cast<int>(path.length())));
info.GetReturnValue().Set(String::NewFromUtf8(
info.GetIsolate(), path.c_str(), String::kNormalString,
static_cast<int>(path.length())));
}
......@@ -475,8 +480,9 @@ void JsHttpRequestProcessor::GetReferrer(
const PropertyCallbackInfo<Value>& info) {
HttpRequest* request = UnwrapRequest(info.Holder());
const string& path = request->Referrer();
info.GetReturnValue().Set(
String::New(path.c_str(), static_cast<int>(path.length())));
info.GetReturnValue().Set(String::NewFromUtf8(
info.GetIsolate(), path.c_str(), String::kNormalString,
static_cast<int>(path.length())));
}
......@@ -484,8 +490,9 @@ void JsHttpRequestProcessor::GetHost(Local<String> name,
const PropertyCallbackInfo<Value>& info) {
HttpRequest* request = UnwrapRequest(info.Holder());
const string& path = request->Host();
info.GetReturnValue().Set(
String::New(path.c_str(), static_cast<int>(path.length())));
info.GetReturnValue().Set(String::NewFromUtf8(
info.GetIsolate(), path.c_str(), String::kNormalString,
static_cast<int>(path.length())));
}
......@@ -494,8 +501,9 @@ void JsHttpRequestProcessor::GetUserAgent(
const PropertyCallbackInfo<Value>& info) {
HttpRequest* request = UnwrapRequest(info.Holder());
const string& path = request->UserAgent();
info.GetReturnValue().Set(
String::New(path.c_str(), static_cast<int>(path.length())));
info.GetReturnValue().Set(String::NewFromUtf8(
info.GetIsolate(), path.c_str(), String::kNormalString,
static_cast<int>(path.length())));
}
......@@ -507,10 +515,18 @@ Handle<ObjectTemplate> JsHttpRequestProcessor::MakeRequestTemplate(
result->SetInternalFieldCount(1);
// Add accessors for each of the fields of the request.
result->SetAccessor(String::NewSymbol("path"), GetPath);
result->SetAccessor(String::NewSymbol("referrer"), GetReferrer);
result->SetAccessor(String::NewSymbol("host"), GetHost);
result->SetAccessor(String::NewSymbol("userAgent"), GetUserAgent);
result->SetAccessor(
String::NewFromUtf8(isolate, "path", String::kInternalizedString),
GetPath);
result->SetAccessor(
String::NewFromUtf8(isolate, "referrer", String::kInternalizedString),
GetReferrer);
result->SetAccessor(
String::NewFromUtf8(isolate, "host", String::kInternalizedString),
GetHost);
result->SetAccessor(
String::NewFromUtf8(isolate, "userAgent", String::kInternalizedString),
GetUserAgent);
// Again, return the result through the current handle scope.
return handle_scope.Close(result);
......@@ -575,7 +591,7 @@ void ParseOptions(int argc,
// Reads a file into a v8 string.
Handle<String> ReadFile(const string& name) {
Handle<String> ReadFile(Isolate* isolate, const string& name) {
FILE* file = fopen(name.c_str(), "rb");
if (file == NULL) return Handle<String>();
......@@ -590,7 +606,8 @@ Handle<String> ReadFile(const string& name) {
i += read;
}
fclose(file);
Handle<String> result = String::New(chars, size);
Handle<String> result =
String::NewFromUtf8(isolate, chars, String::kNormalString, size);
delete[] chars;
return result;
}
......@@ -636,7 +653,7 @@ int main(int argc, char* argv[]) {
}
Isolate* isolate = Isolate::GetCurrent();
HandleScope scope(isolate);
Handle<String> source = ReadFile(file);
Handle<String> source = ReadFile(isolate, file);
if (source.IsEmpty()) {
fprintf(stderr, "Error reading '%s'.\n", file.c_str());
return 1;
......
......@@ -39,10 +39,6 @@
'include_dirs': [
'../include',
],
'variables': {
# TODO(jochen): enable warnings.
'v8_deprecation_warnings': 0,
},
'conditions': [
['v8_enable_i18n_support==1', {
'dependencies': [
......
......@@ -58,7 +58,7 @@ void Read(const v8::FunctionCallbackInfo<v8::Value>& args);
void Load(const v8::FunctionCallbackInfo<v8::Value>& args);
void Quit(const v8::FunctionCallbackInfo<v8::Value>& args);
void Version(const v8::FunctionCallbackInfo<v8::Value>& args);
v8::Handle<v8::String> ReadFile(const char* name);
v8::Handle<v8::String> ReadFile(v8::Isolate* isolate, const char* name);
void ReportException(v8::Isolate* isolate, v8::TryCatch* handler);
......@@ -100,15 +100,20 @@ v8::Handle<v8::Context> CreateShellContext(v8::Isolate* isolate) {
// Create a template for the global object.
v8::Handle<v8::ObjectTemplate> global = v8::ObjectTemplate::New();
// Bind the global 'print' function to the C++ Print callback.
global->Set(v8::String::New("print"), v8::FunctionTemplate::New(Print));
global->Set(v8::String::NewFromUtf8(isolate, "print"),
v8::FunctionTemplate::New(Print));
// Bind the global 'read' function to the C++ Read callback.
global->Set(v8::String::New("read"), v8::FunctionTemplate::New(Read));
global->Set(v8::String::NewFromUtf8(isolate, "read"),
v8::FunctionTemplate::New(Read));
// Bind the global 'load' function to the C++ Load callback.
global->Set(v8::String::New("load"), v8::FunctionTemplate::New(Load));
global->Set(v8::String::NewFromUtf8(isolate, "load"),
v8::FunctionTemplate::New(Load));
// Bind the 'quit' function
global->Set(v8::String::New("quit"), v8::FunctionTemplate::New(Quit));
global->Set(v8::String::NewFromUtf8(isolate, "quit"),
v8::FunctionTemplate::New(Quit));
// Bind the 'version' function
global->Set(v8::String::New("version"), v8::FunctionTemplate::New(Version));
global->Set(v8::String::NewFromUtf8(isolate, "version"),
v8::FunctionTemplate::New(Version));
return v8::Context::New(isolate, NULL, global);
}
......@@ -141,19 +146,19 @@ void Print(const v8::FunctionCallbackInfo<v8::Value>& args) {
void Read(const v8::FunctionCallbackInfo<v8::Value>& args) {
if (args.Length() != 1) {
args.GetIsolate()->ThrowException(
v8::String::New("Bad parameters"));
v8::String::NewFromUtf8(args.GetIsolate(), "Bad parameters"));
return;
}
v8::String::Utf8Value file(args[0]);
if (*file == NULL) {
args.GetIsolate()->ThrowException(
v8::String::New("Error loading file"));
v8::String::NewFromUtf8(args.GetIsolate(), "Error loading file"));
return;
}
v8::Handle<v8::String> source = ReadFile(*file);
v8::Handle<v8::String> source = ReadFile(args.GetIsolate(), *file);
if (source.IsEmpty()) {
args.GetIsolate()->ThrowException(
v8::String::New("Error loading file"));
v8::String::NewFromUtf8(args.GetIsolate(), "Error loading file"));
return;
}
args.GetReturnValue().Set(source);
......@@ -169,22 +174,22 @@ void Load(const v8::FunctionCallbackInfo<v8::Value>& args) {
v8::String::Utf8Value file(args[i]);
if (*file == NULL) {
args.GetIsolate()->ThrowException(
v8::String::New("Error loading file"));
v8::String::NewFromUtf8(args.GetIsolate(), "Error loading file"));
return;
}
v8::Handle<v8::String> source = ReadFile(*file);
v8::Handle<v8::String> source = ReadFile(args.GetIsolate(), *file);
if (source.IsEmpty()) {
args.GetIsolate()->ThrowException(
v8::String::New("Error loading file"));
v8::String::NewFromUtf8(args.GetIsolate(), "Error loading file"));
return;
}
if (!ExecuteString(args.GetIsolate(),
source,
v8::String::New(*file),
v8::String::NewFromUtf8(args.GetIsolate(), *file),
false,
false)) {
args.GetIsolate()->ThrowException(
v8::String::New("Error executing file"));
v8::String::NewFromUtf8(args.GetIsolate(), "Error executing file"));
return;
}
}
......@@ -204,12 +209,13 @@ void Quit(const v8::FunctionCallbackInfo<v8::Value>& args) {
void Version(const v8::FunctionCallbackInfo<v8::Value>& args) {
args.GetReturnValue().Set(v8::String::New(v8::V8::GetVersion()));
args.GetReturnValue().Set(
v8::String::NewFromUtf8(args.GetIsolate(), v8::V8::GetVersion()));
}
// Reads a file into a v8 string.
v8::Handle<v8::String> ReadFile(const char* name) {
v8::Handle<v8::String> ReadFile(v8::Isolate* isolate, const char* name) {
FILE* file = fopen(name, "rb");
if (file == NULL) return v8::Handle<v8::String>();
......@@ -224,7 +230,8 @@ v8::Handle<v8::String> ReadFile(const char* name) {
i += read;
}
fclose(file);
v8::Handle<v8::String> result = v8::String::New(chars, size);
v8::Handle<v8::String> result =
v8::String::NewFromUtf8(isolate, chars, v8::String::kNormalString, size);
delete[] chars;
return result;
}
......@@ -245,13 +252,15 @@ int RunMain(v8::Isolate* isolate, int argc, char* argv[]) {
"Warning: unknown flag %s.\nTry --help for options\n", str);
} else if (strcmp(str, "-e") == 0 && i + 1 < argc) {
// Execute argument given to -e option directly.
v8::Handle<v8::String> file_name = v8::String::New("unnamed");
v8::Handle<v8::String> source = v8::String::New(argv[++i]);
v8::Handle<v8::String> file_name =
v8::String::NewFromUtf8(isolate, "unnamed");
v8::Handle<v8::String> source =
v8::String::NewFromUtf8(isolate, argv[++i]);
if (!ExecuteString(isolate, source, file_name, false, true)) return 1;
} else {
// Use all other arguments as names of files to load and run.
v8::Handle<v8::String> file_name = v8::String::New(str);
v8::Handle<v8::String> source = ReadFile(str);
v8::Handle<v8::String> file_name = v8::String::NewFromUtf8(isolate, str);
v8::Handle<v8::String> source = ReadFile(isolate, str);
if (source.IsEmpty()) {
fprintf(stderr, "Error reading '%s'\n", str);
continue;
......@@ -269,7 +278,8 @@ void RunShell(v8::Handle<v8::Context> context) {
static const int kBufferSize = 256;
// Enter the execution environment before evaluating any code.
v8::Context::Scope context_scope(context);
v8::Local<v8::String> name(v8::String::New("(shell)"));
v8::Local<v8::String> name(
v8::String::NewFromUtf8(context->GetIsolate(), "(shell)"));
while (true) {
char buffer[kBufferSize];
fprintf(stderr, "> ");
......@@ -277,7 +287,7 @@ void RunShell(v8::Handle<v8::Context> context) {
if (str == NULL) break;
v8::HandleScope handle_scope(context->GetIsolate());
ExecuteString(context->GetIsolate(),
v8::String::New(str),
v8::String::NewFromUtf8(context->GetIsolate(), str),
name,
true,
true);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment