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

Side by Side Diff: src/d8.cc

Issue 136643008: A64: Synchronize with r18256. (Closed) Base URL: https://v8.googlecode.com/svn/branches/experimental/a64
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/compiler.cc ('k') | src/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 // 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 592 matching lines...) Expand 10 before | Expand all | Expand 10 after
603 #if !defined(V8_SHARED) && defined(ENABLE_DEBUGGER_SUPPORT) 603 #if !defined(V8_SHARED) && defined(ENABLE_DEBUGGER_SUPPORT)
604 if (enter_context) utility_context->Exit(); 604 if (enter_context) utility_context->Exit();
605 #endif // !V8_SHARED && ENABLE_DEBUGGER_SUPPORT 605 #endif // !V8_SHARED && ENABLE_DEBUGGER_SUPPORT
606 } 606 }
607 607
608 608
609 #ifndef V8_SHARED 609 #ifndef V8_SHARED
610 Handle<Array> Shell::GetCompletions(Isolate* isolate, 610 Handle<Array> Shell::GetCompletions(Isolate* isolate,
611 Handle<String> text, 611 Handle<String> text,
612 Handle<String> full) { 612 Handle<String> full) {
613 HandleScope handle_scope(isolate); 613 EscapableHandleScope handle_scope(isolate);
614 v8::Local<v8::Context> utility_context = 614 v8::Local<v8::Context> utility_context =
615 v8::Local<v8::Context>::New(isolate, utility_context_); 615 v8::Local<v8::Context>::New(isolate, utility_context_);
616 v8::Context::Scope context_scope(utility_context); 616 v8::Context::Scope context_scope(utility_context);
617 Handle<Object> global = utility_context->Global(); 617 Handle<Object> global = utility_context->Global();
618 Handle<Value> fun = 618 Local<Value> fun =
619 global->Get(String::NewFromUtf8(isolate, "GetCompletions")); 619 global->Get(String::NewFromUtf8(isolate, "GetCompletions"));
620 static const int kArgc = 3; 620 static const int kArgc = 3;
621 v8::Local<v8::Context> evaluation_context = 621 v8::Local<v8::Context> evaluation_context =
622 v8::Local<v8::Context>::New(isolate, evaluation_context_); 622 v8::Local<v8::Context>::New(isolate, evaluation_context_);
623 Handle<Value> argv[kArgc] = { evaluation_context->Global(), text, full }; 623 Handle<Value> argv[kArgc] = { evaluation_context->Global(), text, full };
624 Handle<Value> val = Handle<Function>::Cast(fun)->Call(global, kArgc, argv); 624 Local<Value> val = Local<Function>::Cast(fun)->Call(global, kArgc, argv);
625 return handle_scope.Close(Handle<Array>::Cast(val)); 625 return handle_scope.Escape(Local<Array>::Cast(val));
626 } 626 }
627 627
628 628
629 #ifdef ENABLE_DEBUGGER_SUPPORT 629 #ifdef ENABLE_DEBUGGER_SUPPORT
630 Handle<Object> Shell::DebugMessageDetails(Isolate* isolate, 630 Handle<Object> Shell::DebugMessageDetails(Isolate* isolate,
631 Handle<String> message) { 631 Handle<String> message) {
632 HandleScope handle_scope(isolate); 632 HandleScope handle_scope(isolate);
633 v8::Local<v8::Context> context = 633 v8::Local<v8::Context> context =
634 v8::Local<v8::Context>::New(isolate, utility_context_); 634 v8::Local<v8::Context>::New(isolate, utility_context_);
635 v8::Context::Scope context_scope(context); 635 v8::Context::Scope context_scope(context);
(...skipping 323 matching lines...) Expand 10 before | Expand all | Expand 10 after
959 } 959 }
960 960
961 961
962 Local<Context> Shell::CreateEvaluationContext(Isolate* isolate) { 962 Local<Context> Shell::CreateEvaluationContext(Isolate* isolate) {
963 #ifndef V8_SHARED 963 #ifndef V8_SHARED
964 // This needs to be a critical section since this is not thread-safe 964 // This needs to be a critical section since this is not thread-safe
965 i::LockGuard<i::Mutex> lock_guard(&context_mutex_); 965 i::LockGuard<i::Mutex> lock_guard(&context_mutex_);
966 #endif // V8_SHARED 966 #endif // V8_SHARED
967 // Initialize the global objects 967 // Initialize the global objects
968 Handle<ObjectTemplate> global_template = CreateGlobalTemplate(isolate); 968 Handle<ObjectTemplate> global_template = CreateGlobalTemplate(isolate);
969 HandleScope handle_scope(isolate); 969 EscapableHandleScope handle_scope(isolate);
970 Local<Context> context = Context::New(isolate, NULL, global_template); 970 Local<Context> context = Context::New(isolate, NULL, global_template);
971 ASSERT(!context.IsEmpty()); 971 ASSERT(!context.IsEmpty());
972 Context::Scope scope(context); 972 Context::Scope scope(context);
973 973
974 #ifndef V8_SHARED 974 #ifndef V8_SHARED
975 i::Factory* factory = reinterpret_cast<i::Isolate*>(isolate)->factory(); 975 i::Factory* factory = reinterpret_cast<i::Isolate*>(isolate)->factory();
976 i::JSArguments js_args = i::FLAG_js_arguments; 976 i::JSArguments js_args = i::FLAG_js_arguments;
977 i::Handle<i::FixedArray> arguments_array = 977 i::Handle<i::FixedArray> arguments_array =
978 factory->NewFixedArray(js_args.argc); 978 factory->NewFixedArray(js_args.argc);
979 for (int j = 0; j < js_args.argc; j++) { 979 for (int j = 0; j < js_args.argc; j++) {
980 i::Handle<i::String> arg = 980 i::Handle<i::String> arg =
981 factory->NewStringFromUtf8(i::CStrVector(js_args[j])); 981 factory->NewStringFromUtf8(i::CStrVector(js_args[j]));
982 arguments_array->set(j, *arg); 982 arguments_array->set(j, *arg);
983 } 983 }
984 i::Handle<i::JSArray> arguments_jsarray = 984 i::Handle<i::JSArray> arguments_jsarray =
985 factory->NewJSArrayWithElements(arguments_array); 985 factory->NewJSArrayWithElements(arguments_array);
986 context->Global()->Set(String::NewFromUtf8(isolate, "arguments"), 986 context->Global()->Set(String::NewFromUtf8(isolate, "arguments"),
987 Utils::ToLocal(arguments_jsarray)); 987 Utils::ToLocal(arguments_jsarray));
988 #endif // V8_SHARED 988 #endif // V8_SHARED
989 return handle_scope.Close(context); 989 return handle_scope.Escape(context);
990 } 990 }
991 991
992 992
993 void Shell::Exit(int exit_code) { 993 void Shell::Exit(int exit_code) {
994 // Use _exit instead of exit to avoid races between isolate 994 // Use _exit instead of exit to avoid races between isolate
995 // threads and static destructors. 995 // threads and static destructors.
996 fflush(stdout); 996 fflush(stdout);
997 fflush(stderr); 997 fflush(stderr);
998 _exit(exit_code); 998 _exit(exit_code);
999 } 999 }
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
1090 chars[size] = '\0'; 1090 chars[size] = '\0';
1091 for (int i = 0; i < size;) { 1091 for (int i = 0; i < size;) {
1092 int read = static_cast<int>(fread(&chars[i], 1, size - i, file)); 1092 int read = static_cast<int>(fread(&chars[i], 1, size - i, file));
1093 i += read; 1093 i += read;
1094 } 1094 }
1095 fclose(file); 1095 fclose(file);
1096 *size_out = size; 1096 *size_out = size;
1097 return chars; 1097 return chars;
1098 } 1098 }
1099 1099
1100 static void ReadBufferWeakCallback(v8::Isolate* isolate, 1100
1101 Persistent<ArrayBuffer>* array_buffer, 1101 struct DataAndPersistent {
1102 uint8_t* data) { 1102 uint8_t* data;
1103 size_t byte_length = 1103 Persistent<ArrayBuffer> handle;
1104 Local<ArrayBuffer>::New(isolate, *array_buffer)->ByteLength(); 1104 };
1105 isolate->AdjustAmountOfExternalAllocatedMemory( 1105
1106
1107 static void ReadBufferWeakCallback(
1108 const v8::WeakCallbackData<ArrayBuffer, DataAndPersistent>& data) {
1109 size_t byte_length = data.GetValue()->ByteLength();
1110 data.GetIsolate()->AdjustAmountOfExternalAllocatedMemory(
1106 -static_cast<intptr_t>(byte_length)); 1111 -static_cast<intptr_t>(byte_length));
1107 1112
1108 delete[] data; 1113 delete[] data.GetParameter()->data;
1109 array_buffer->Reset(); 1114 data.GetParameter()->handle.Reset();
1115 delete data.GetParameter();
1110 } 1116 }
1111 1117
1112 1118
1113 void Shell::ReadBuffer(const v8::FunctionCallbackInfo<v8::Value>& args) { 1119 void Shell::ReadBuffer(const v8::FunctionCallbackInfo<v8::Value>& args) {
1114 ASSERT(sizeof(char) == sizeof(uint8_t)); // NOLINT 1120 ASSERT(sizeof(char) == sizeof(uint8_t)); // NOLINT
1115 String::Utf8Value filename(args[0]); 1121 String::Utf8Value filename(args[0]);
1116 int length; 1122 int length;
1117 if (*filename == NULL) { 1123 if (*filename == NULL) {
1118 Throw(args.GetIsolate(), "Error loading file"); 1124 Throw(args.GetIsolate(), "Error loading file");
1119 return; 1125 return;
1120 } 1126 }
1121 1127
1122 Isolate* isolate = args.GetIsolate(); 1128 Isolate* isolate = args.GetIsolate();
1123 uint8_t* data = reinterpret_cast<uint8_t*>( 1129 DataAndPersistent* data = new DataAndPersistent;
1130 data->data = reinterpret_cast<uint8_t*>(
1124 ReadChars(args.GetIsolate(), *filename, &length)); 1131 ReadChars(args.GetIsolate(), *filename, &length));
1125 if (data == NULL) { 1132 if (data->data == NULL) {
1133 delete data;
1126 Throw(args.GetIsolate(), "Error reading file"); 1134 Throw(args.GetIsolate(), "Error reading file");
1127 return; 1135 return;
1128 } 1136 }
1129 Handle<v8::ArrayBuffer> buffer = ArrayBuffer::New(isolate, data, length); 1137 Handle<v8::ArrayBuffer> buffer = ArrayBuffer::New(isolate, data, length);
1130 v8::Persistent<v8::ArrayBuffer> weak_handle(isolate, buffer); 1138 data->handle.Reset(isolate, buffer);
1131 weak_handle.MakeWeak(data, ReadBufferWeakCallback); 1139 data->handle.SetWeak(data, ReadBufferWeakCallback);
1132 weak_handle.MarkIndependent(); 1140 data->handle.MarkIndependent();
1133 isolate->AdjustAmountOfExternalAllocatedMemory(length); 1141 isolate->AdjustAmountOfExternalAllocatedMemory(length);
1134 1142
1135 args.GetReturnValue().Set(buffer); 1143 args.GetReturnValue().Set(buffer);
1136 } 1144 }
1137 1145
1138 1146
1139 #ifndef V8_SHARED 1147 #ifndef V8_SHARED
1140 static char* ReadToken(char* data, char token) { 1148 static char* ReadToken(char* data, char token) {
1141 char* next = i::OS::StrChr(data, token); 1149 char* next = i::OS::StrChr(data, token);
1142 if (next != NULL) { 1150 if (next != NULL) {
(...skipping 612 matching lines...) Expand 10 before | Expand all | Expand 10 after
1755 } 1763 }
1756 1764
1757 } // namespace v8 1765 } // namespace v8
1758 1766
1759 1767
1760 #ifndef GOOGLE3 1768 #ifndef GOOGLE3
1761 int main(int argc, char* argv[]) { 1769 int main(int argc, char* argv[]) {
1762 return v8::Shell::Main(argc, argv); 1770 return v8::Shell::Main(argc, argv);
1763 } 1771 }
1764 #endif 1772 #endif
OLDNEW
« no previous file with comments | « src/compiler.cc ('k') | src/debug.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698