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

Side by Side Diff: src/d8.cc

Issue 181453002: Reset trunk to 3.24.35.4 (Closed) Base URL: https://v8.googlecode.com/svn/trunk
Patch Set: Created 6 years, 10 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « src/conversions-inl.h ('k') | src/dateparser.h » ('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 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
112 private: 112 private:
113 friend class Shell; 113 friend class Shell;
114 friend class RealmScope; 114 friend class RealmScope;
115 Isolate* isolate_; 115 Isolate* isolate_;
116 int realm_count_; 116 int realm_count_;
117 int realm_current_; 117 int realm_current_;
118 int realm_switch_; 118 int realm_switch_;
119 Persistent<Context>* realms_; 119 Persistent<Context>* realms_;
120 Persistent<Value> realm_shared_; 120 Persistent<Value> realm_shared_;
121 121
122 int RealmIndexOrThrow(const v8::FunctionCallbackInfo<v8::Value>& args,
123 int arg_offset);
124 int RealmFind(Handle<Context> context); 122 int RealmFind(Handle<Context> context);
125 }; 123 };
126 124
127 125
128 LineEditor *LineEditor::current_ = NULL; 126 LineEditor *LineEditor::current_ = NULL;
129 127
130 128
131 LineEditor::LineEditor(Type type, const char* name) 129 LineEditor::LineEditor(Type type, const char* name)
132 : type_(type), name_(name) { 130 : type_(type), name_(name) {
133 if (current_ == NULL || current_->type_ < type) current_ = this; 131 if (current_ == NULL || current_->type_ < type) current_ = this;
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after
283 281
284 282
285 int PerIsolateData::RealmFind(Handle<Context> context) { 283 int PerIsolateData::RealmFind(Handle<Context> context) {
286 for (int i = 0; i < realm_count_; ++i) { 284 for (int i = 0; i < realm_count_; ++i) {
287 if (realms_[i] == context) return i; 285 if (realms_[i] == context) return i;
288 } 286 }
289 return -1; 287 return -1;
290 } 288 }
291 289
292 290
293 int PerIsolateData::RealmIndexOrThrow(
294 const v8::FunctionCallbackInfo<v8::Value>& args,
295 int arg_offset) {
296 if (args.Length() < arg_offset || !args[arg_offset]->IsNumber()) {
297 Throw(args.GetIsolate(), "Invalid argument");
298 return -1;
299 }
300 int index = args[arg_offset]->Int32Value();
301 if (index < 0 ||
302 index >= realm_count_ ||
303 realms_[index].IsEmpty()) {
304 Throw(args.GetIsolate(), "Invalid realm index");
305 return -1;
306 }
307 return index;
308 }
309
310
311 #ifndef V8_SHARED 291 #ifndef V8_SHARED
312 // performance.now() returns a time stamp as double, measured in milliseconds. 292 // performance.now() returns a time stamp as double, measured in milliseconds.
313 void Shell::PerformanceNow(const v8::FunctionCallbackInfo<v8::Value>& args) { 293 void Shell::PerformanceNow(const v8::FunctionCallbackInfo<v8::Value>& args) {
314 i::TimeDelta delta = i::TimeTicks::HighResolutionNow() - kInitialTicks; 294 i::TimeDelta delta = i::TimeTicks::HighResolutionNow() - kInitialTicks;
315 args.GetReturnValue().Set(delta.InMillisecondsF()); 295 args.GetReturnValue().Set(delta.InMillisecondsF());
316 } 296 }
317 #endif // V8_SHARED 297 #endif // V8_SHARED
318 298
319 299
320 // Realm.current() returns the index of the currently active realm. 300 // Realm.current() returns the index of the currently active realm.
(...skipping 17 matching lines...) Expand all
338 int index = data->RealmFind(args[0]->ToObject()->CreationContext()); 318 int index = data->RealmFind(args[0]->ToObject()->CreationContext());
339 if (index == -1) return; 319 if (index == -1) return;
340 args.GetReturnValue().Set(index); 320 args.GetReturnValue().Set(index);
341 } 321 }
342 322
343 323
344 // Realm.global(i) returns the global object of realm i. 324 // Realm.global(i) returns the global object of realm i.
345 // (Note that properties of global objects cannot be read/written cross-realm.) 325 // (Note that properties of global objects cannot be read/written cross-realm.)
346 void Shell::RealmGlobal(const v8::FunctionCallbackInfo<v8::Value>& args) { 326 void Shell::RealmGlobal(const v8::FunctionCallbackInfo<v8::Value>& args) {
347 PerIsolateData* data = PerIsolateData::Get(args.GetIsolate()); 327 PerIsolateData* data = PerIsolateData::Get(args.GetIsolate());
348 int index = data->RealmIndexOrThrow(args, 0); 328 if (args.Length() < 1 || !args[0]->IsNumber()) {
349 if (index == -1) return; 329 Throw(args.GetIsolate(), "Invalid argument");
330 return;
331 }
332 int index = args[0]->Uint32Value();
333 if (index >= data->realm_count_ || data->realms_[index].IsEmpty()) {
334 Throw(args.GetIsolate(), "Invalid realm index");
335 return;
336 }
350 args.GetReturnValue().Set( 337 args.GetReturnValue().Set(
351 Local<Context>::New(args.GetIsolate(), data->realms_[index])->Global()); 338 Local<Context>::New(args.GetIsolate(), data->realms_[index])->Global());
352 } 339 }
353 340
354 341
355 // Realm.create() creates a new realm and returns its index. 342 // Realm.create() creates a new realm and returns its index.
356 void Shell::RealmCreate(const v8::FunctionCallbackInfo<v8::Value>& args) { 343 void Shell::RealmCreate(const v8::FunctionCallbackInfo<v8::Value>& args) {
357 Isolate* isolate = args.GetIsolate(); 344 Isolate* isolate = args.GetIsolate();
358 PerIsolateData* data = PerIsolateData::Get(isolate); 345 PerIsolateData* data = PerIsolateData::Get(isolate);
359 Persistent<Context>* old_realms = data->realms_; 346 Persistent<Context>* old_realms = data->realms_;
360 int index = data->realm_count_; 347 int index = data->realm_count_;
361 data->realms_ = new Persistent<Context>[++data->realm_count_]; 348 data->realms_ = new Persistent<Context>[++data->realm_count_];
362 for (int i = 0; i < index; ++i) { 349 for (int i = 0; i < index; ++i) {
363 data->realms_[i].Reset(isolate, old_realms[i]); 350 data->realms_[i].Reset(isolate, old_realms[i]);
364 } 351 }
365 delete[] old_realms; 352 delete[] old_realms;
366 Handle<ObjectTemplate> global_template = CreateGlobalTemplate(isolate); 353 Handle<ObjectTemplate> global_template = CreateGlobalTemplate(isolate);
367 data->realms_[index].Reset( 354 data->realms_[index].Reset(
368 isolate, Context::New(isolate, NULL, global_template)); 355 isolate, Context::New(isolate, NULL, global_template));
369 args.GetReturnValue().Set(index); 356 args.GetReturnValue().Set(index);
370 } 357 }
371 358
372 359
373 // Realm.dispose(i) disposes the reference to the realm i. 360 // Realm.dispose(i) disposes the reference to the realm i.
374 void Shell::RealmDispose(const v8::FunctionCallbackInfo<v8::Value>& args) { 361 void Shell::RealmDispose(const v8::FunctionCallbackInfo<v8::Value>& args) {
375 Isolate* isolate = args.GetIsolate(); 362 Isolate* isolate = args.GetIsolate();
376 PerIsolateData* data = PerIsolateData::Get(isolate); 363 PerIsolateData* data = PerIsolateData::Get(isolate);
377 int index = data->RealmIndexOrThrow(args, 0); 364 if (args.Length() < 1 || !args[0]->IsNumber()) {
378 if (index == -1) return; 365 Throw(args.GetIsolate(), "Invalid argument");
379 if (index == 0 || 366 return;
367 }
368 int index = args[0]->Uint32Value();
369 if (index >= data->realm_count_ || data->realms_[index].IsEmpty() ||
370 index == 0 ||
380 index == data->realm_current_ || index == data->realm_switch_) { 371 index == data->realm_current_ || index == data->realm_switch_) {
381 Throw(args.GetIsolate(), "Invalid realm index"); 372 Throw(args.GetIsolate(), "Invalid realm index");
382 return; 373 return;
383 } 374 }
384 data->realms_[index].Reset(); 375 data->realms_[index].Reset();
385 } 376 }
386 377
387 378
388 // Realm.switch(i) switches to the realm i for consecutive interactive inputs. 379 // Realm.switch(i) switches to the realm i for consecutive interactive inputs.
389 void Shell::RealmSwitch(const v8::FunctionCallbackInfo<v8::Value>& args) { 380 void Shell::RealmSwitch(const v8::FunctionCallbackInfo<v8::Value>& args) {
390 Isolate* isolate = args.GetIsolate(); 381 Isolate* isolate = args.GetIsolate();
391 PerIsolateData* data = PerIsolateData::Get(isolate); 382 PerIsolateData* data = PerIsolateData::Get(isolate);
392 int index = data->RealmIndexOrThrow(args, 0); 383 if (args.Length() < 1 || !args[0]->IsNumber()) {
393 if (index == -1) return; 384 Throw(args.GetIsolate(), "Invalid argument");
385 return;
386 }
387 int index = args[0]->Uint32Value();
388 if (index >= data->realm_count_ || data->realms_[index].IsEmpty()) {
389 Throw(args.GetIsolate(), "Invalid realm index");
390 return;
391 }
394 data->realm_switch_ = index; 392 data->realm_switch_ = index;
395 } 393 }
396 394
397 395
398 // Realm.eval(i, s) evaluates s in realm i and returns the result. 396 // Realm.eval(i, s) evaluates s in realm i and returns the result.
399 void Shell::RealmEval(const v8::FunctionCallbackInfo<v8::Value>& args) { 397 void Shell::RealmEval(const v8::FunctionCallbackInfo<v8::Value>& args) {
400 Isolate* isolate = args.GetIsolate(); 398 Isolate* isolate = args.GetIsolate();
401 PerIsolateData* data = PerIsolateData::Get(isolate); 399 PerIsolateData* data = PerIsolateData::Get(isolate);
402 int index = data->RealmIndexOrThrow(args, 0); 400 if (args.Length() < 2 || !args[0]->IsNumber() || !args[1]->IsString()) {
403 if (index == -1) return;
404 if (args.Length() < 2 || !args[1]->IsString()) {
405 Throw(args.GetIsolate(), "Invalid argument"); 401 Throw(args.GetIsolate(), "Invalid argument");
406 return; 402 return;
407 } 403 }
404 int index = args[0]->Uint32Value();
405 if (index >= data->realm_count_ || data->realms_[index].IsEmpty()) {
406 Throw(args.GetIsolate(), "Invalid realm index");
407 return;
408 }
408 Handle<Script> script = Script::New(args[1]->ToString()); 409 Handle<Script> script = Script::New(args[1]->ToString());
409 if (script.IsEmpty()) return; 410 if (script.IsEmpty()) return;
410 Local<Context> realm = Local<Context>::New(isolate, data->realms_[index]); 411 Local<Context> realm = Local<Context>::New(isolate, data->realms_[index]);
411 realm->Enter(); 412 realm->Enter();
412 Handle<Value> result = script->Run(); 413 Handle<Value> result = script->Run();
413 realm->Exit(); 414 realm->Exit();
414 args.GetReturnValue().Set(result); 415 args.GetReturnValue().Set(result);
415 } 416 }
416 417
417 418
(...skipping 1345 matching lines...) Expand 10 before | Expand all | Expand 10 after
1763 } 1764 }
1764 1765
1765 } // namespace v8 1766 } // namespace v8
1766 1767
1767 1768
1768 #ifndef GOOGLE3 1769 #ifndef GOOGLE3
1769 int main(int argc, char* argv[]) { 1770 int main(int argc, char* argv[]) {
1770 return v8::Shell::Main(argc, argv); 1771 return v8::Shell::Main(argc, argv);
1771 } 1772 }
1772 #endif 1773 #endif
OLDNEW
« no previous file with comments | « src/conversions-inl.h ('k') | src/dateparser.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698