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

Side by Side Diff: src/d8.cc

Issue 669373002: pass isolate to Value::To* functions (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: rebase Created 6 years, 1 month 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « src/api.cc ('k') | src/d8-debug.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 5
6 // Defined when linking against shared lib on Windows. 6 // Defined when linking against shared lib on Windows.
7 #if defined(USING_V8_SHARED) && !defined(V8_SHARED) 7 #if defined(USING_V8_SHARED) && !defined(V8_SHARED)
8 #define V8_SHARED 8 #define V8_SHARED
9 #endif 9 #endif
10 10
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after
179 179
180 ScriptCompiler::CachedData* CompileForCachedData( 180 ScriptCompiler::CachedData* CompileForCachedData(
181 Local<String> source, Local<Value> name, 181 Local<String> source, Local<Value> name,
182 ScriptCompiler::CompileOptions compile_options) { 182 ScriptCompiler::CompileOptions compile_options) {
183 int source_length = source->Length(); 183 int source_length = source->Length();
184 uint16_t* source_buffer = new uint16_t[source_length]; 184 uint16_t* source_buffer = new uint16_t[source_length];
185 source->Write(source_buffer, 0, source_length); 185 source->Write(source_buffer, 0, source_length);
186 int name_length = 0; 186 int name_length = 0;
187 uint16_t* name_buffer = NULL; 187 uint16_t* name_buffer = NULL;
188 if (name->IsString()) { 188 if (name->IsString()) {
189 Local<String> name_string = name->ToString(); 189 Local<String> name_string = Local<String>::Cast(name);
190 name_length = name_string->Length(); 190 name_length = name_string->Length();
191 name_buffer = new uint16_t[name_length]; 191 name_buffer = new uint16_t[name_length];
192 name_string->Write(name_buffer, 0, name_length); 192 name_string->Write(name_buffer, 0, name_length);
193 } 193 }
194 Isolate* temp_isolate = Isolate::New(); 194 Isolate* temp_isolate = Isolate::New();
195 ScriptCompiler::CachedData* result = NULL; 195 ScriptCompiler::CachedData* result = NULL;
196 { 196 {
197 Isolate::Scope isolate_scope(temp_isolate); 197 Isolate::Scope isolate_scope(temp_isolate);
198 HandleScope handle_scope(temp_isolate); 198 HandleScope handle_scope(temp_isolate);
199 Context::Scope context_scope(Context::New(temp_isolate)); 199 Context::Scope context_scope(Context::New(temp_isolate));
(...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after
403 403
404 404
405 // Realm.owner(o) returns the index of the realm that created o. 405 // Realm.owner(o) returns the index of the realm that created o.
406 void Shell::RealmOwner(const v8::FunctionCallbackInfo<v8::Value>& args) { 406 void Shell::RealmOwner(const v8::FunctionCallbackInfo<v8::Value>& args) {
407 Isolate* isolate = args.GetIsolate(); 407 Isolate* isolate = args.GetIsolate();
408 PerIsolateData* data = PerIsolateData::Get(isolate); 408 PerIsolateData* data = PerIsolateData::Get(isolate);
409 if (args.Length() < 1 || !args[0]->IsObject()) { 409 if (args.Length() < 1 || !args[0]->IsObject()) {
410 Throw(args.GetIsolate(), "Invalid argument"); 410 Throw(args.GetIsolate(), "Invalid argument");
411 return; 411 return;
412 } 412 }
413 int index = data->RealmFind(args[0]->ToObject()->CreationContext()); 413 int index = data->RealmFind(args[0]->ToObject(isolate)->CreationContext());
414 if (index == -1) return; 414 if (index == -1) return;
415 args.GetReturnValue().Set(index); 415 args.GetReturnValue().Set(index);
416 } 416 }
417 417
418 418
419 // Realm.global(i) returns the global object of realm i. 419 // Realm.global(i) returns the global object of realm i.
420 // (Note that properties of global objects cannot be read/written cross-realm.) 420 // (Note that properties of global objects cannot be read/written cross-realm.)
421 void Shell::RealmGlobal(const v8::FunctionCallbackInfo<v8::Value>& args) { 421 void Shell::RealmGlobal(const v8::FunctionCallbackInfo<v8::Value>& args) {
422 PerIsolateData* data = PerIsolateData::Get(args.GetIsolate()); 422 PerIsolateData* data = PerIsolateData::Get(args.GetIsolate());
423 int index = data->RealmIndexOrThrow(args, 0); 423 int index = data->RealmIndexOrThrow(args, 0);
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
473 // Realm.eval(i, s) evaluates s in realm i and returns the result. 473 // Realm.eval(i, s) evaluates s in realm i and returns the result.
474 void Shell::RealmEval(const v8::FunctionCallbackInfo<v8::Value>& args) { 474 void Shell::RealmEval(const v8::FunctionCallbackInfo<v8::Value>& args) {
475 Isolate* isolate = args.GetIsolate(); 475 Isolate* isolate = args.GetIsolate();
476 PerIsolateData* data = PerIsolateData::Get(isolate); 476 PerIsolateData* data = PerIsolateData::Get(isolate);
477 int index = data->RealmIndexOrThrow(args, 0); 477 int index = data->RealmIndexOrThrow(args, 0);
478 if (index == -1) return; 478 if (index == -1) return;
479 if (args.Length() < 2 || !args[1]->IsString()) { 479 if (args.Length() < 2 || !args[1]->IsString()) {
480 Throw(args.GetIsolate(), "Invalid argument"); 480 Throw(args.GetIsolate(), "Invalid argument");
481 return; 481 return;
482 } 482 }
483 ScriptCompiler::Source script_source(args[1]->ToString()); 483 ScriptCompiler::Source script_source(args[1]->ToString(isolate));
484 Handle<UnboundScript> script = ScriptCompiler::CompileUnbound( 484 Handle<UnboundScript> script = ScriptCompiler::CompileUnbound(
485 isolate, &script_source); 485 isolate, &script_source);
486 if (script.IsEmpty()) return; 486 if (script.IsEmpty()) return;
487 Local<Context> realm = Local<Context>::New(isolate, data->realms_[index]); 487 Local<Context> realm = Local<Context>::New(isolate, data->realms_[index]);
488 realm->Enter(); 488 realm->Enter();
489 Handle<Value> result = script->BindToCurrentContext()->Run(); 489 Handle<Value> result = script->BindToCurrentContext()->Run();
490 realm->Exit(); 490 realm->Exit();
491 args.GetReturnValue().Set(result); 491 args.GetReturnValue().Set(result);
492 } 492 }
493 493
(...skipping 25 matching lines...) Expand all
519 519
520 void Shell::Write(const v8::FunctionCallbackInfo<v8::Value>& args) { 520 void Shell::Write(const v8::FunctionCallbackInfo<v8::Value>& args) {
521 for (int i = 0; i < args.Length(); i++) { 521 for (int i = 0; i < args.Length(); i++) {
522 HandleScope handle_scope(args.GetIsolate()); 522 HandleScope handle_scope(args.GetIsolate());
523 if (i != 0) { 523 if (i != 0) {
524 printf(" "); 524 printf(" ");
525 } 525 }
526 526
527 // Explicitly catch potential exceptions in toString(). 527 // Explicitly catch potential exceptions in toString().
528 v8::TryCatch try_catch; 528 v8::TryCatch try_catch;
529 Handle<String> str_obj = args[i]->ToString(); 529 Handle<String> str_obj = args[i]->ToString(args.GetIsolate());
530 if (try_catch.HasCaught()) { 530 if (try_catch.HasCaught()) {
531 try_catch.ReThrow(); 531 try_catch.ReThrow();
532 return; 532 return;
533 } 533 }
534 534
535 v8::String::Utf8Value str(str_obj); 535 v8::String::Utf8Value str(str_obj);
536 int n = static_cast<int>(fwrite(*str, sizeof(**str), str.length(), stdout)); 536 int n = static_cast<int>(fwrite(*str, sizeof(**str), str.length(), stdout));
537 if (n != str.length()) { 537 if (n != str.length()) {
538 printf("Error in fwrite\n"); 538 printf("Error in fwrite\n");
539 Exit(1); 539 Exit(1);
(...skipping 1225 matching lines...) Expand 10 before | Expand all | Expand 10 after
1765 } 1765 }
1766 1766
1767 } // namespace v8 1767 } // namespace v8
1768 1768
1769 1769
1770 #ifndef GOOGLE3 1770 #ifndef GOOGLE3
1771 int main(int argc, char* argv[]) { 1771 int main(int argc, char* argv[]) {
1772 return v8::Shell::Main(argc, argv); 1772 return v8::Shell::Main(argc, argv);
1773 } 1773 }
1774 #endif 1774 #endif
OLDNEW
« no previous file with comments | « src/api.cc ('k') | src/d8-debug.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698