| OLD | NEW |
| 1 // Copyright 2011 the V8 project authors. All rights reserved. | 1 // Copyright 2011 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 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 192 } | 192 } |
| 193 | 193 |
| 194 | 194 |
| 195 Handle<Value> Shell::Write(const Arguments& args) { | 195 Handle<Value> Shell::Write(const Arguments& args) { |
| 196 for (int i = 0; i < args.Length(); i++) { | 196 for (int i = 0; i < args.Length(); i++) { |
| 197 HandleScope handle_scope; | 197 HandleScope handle_scope; |
| 198 if (i != 0) { | 198 if (i != 0) { |
| 199 printf(" "); | 199 printf(" "); |
| 200 } | 200 } |
| 201 v8::String::Utf8Value str(args[i]); | 201 v8::String::Utf8Value str(args[i]); |
| 202 int n = fwrite(*str, sizeof(**str), str.length(), stdout); | 202 int n = static_cast<int>(fwrite(*str, sizeof(**str), str.length(), stdout)); |
| 203 if (n != str.length()) { | 203 if (n != str.length()) { |
| 204 printf("Error in fwrite\n"); | 204 printf("Error in fwrite\n"); |
| 205 exit(1); | 205 exit(1); |
| 206 } | 206 } |
| 207 } | 207 } |
| 208 return Undefined(); | 208 return Undefined(); |
| 209 } | 209 } |
| 210 | 210 |
| 211 | 211 |
| 212 Handle<Value> Shell::Read(const Arguments& args) { | 212 Handle<Value> Shell::Read(const Arguments& args) { |
| (...skipping 11 matching lines...) Expand all Loading... |
| 224 | 224 |
| 225 Handle<Value> Shell::ReadLine(const Arguments& args) { | 225 Handle<Value> Shell::ReadLine(const Arguments& args) { |
| 226 static const int kBufferSize = 256; | 226 static const int kBufferSize = 256; |
| 227 char buffer[kBufferSize]; | 227 char buffer[kBufferSize]; |
| 228 Handle<String> accumulator = String::New(""); | 228 Handle<String> accumulator = String::New(""); |
| 229 bool linebreak; | 229 bool linebreak; |
| 230 int length; | 230 int length; |
| 231 do { // Repeat if the line ends with an escape '\'. | 231 do { // Repeat if the line ends with an escape '\'. |
| 232 // fgets got an error. Just give up. | 232 // fgets got an error. Just give up. |
| 233 if (fgets(buffer, kBufferSize, stdin) == NULL) return Null(); | 233 if (fgets(buffer, kBufferSize, stdin) == NULL) return Null(); |
| 234 length = strlen(buffer); | 234 length = static_cast<int>(strlen(buffer)); |
| 235 linebreak = (length > 1 && buffer[length-2] == '\\'); | 235 linebreak = (length > 1 && buffer[length-2] == '\\'); |
| 236 if (linebreak) buffer[length-2] = '\n'; | 236 if (linebreak) buffer[length-2] = '\n'; |
| 237 accumulator = String::Concat(accumulator, String::New(buffer, length-1)); | 237 accumulator = String::Concat(accumulator, String::New(buffer, length-1)); |
| 238 } while (linebreak); | 238 } while (linebreak); |
| 239 return accumulator; | 239 return accumulator; |
| 240 } | 240 } |
| 241 | 241 |
| 242 | 242 |
| 243 Handle<Value> Shell::Load(const Arguments& args) { | 243 Handle<Value> Shell::Load(const Arguments& args) { |
| 244 for (int i = 0; i < args.Length(); i++) { | 244 for (int i = 0; i < args.Length(); i++) { |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 292 return ThrowException(String::New("Array length exceeds maximum length.")); | 292 return ThrowException(String::New("Array length exceeds maximum length.")); |
| 293 } | 293 } |
| 294 void* data = calloc(length, element_size); | 294 void* data = calloc(length, element_size); |
| 295 if (data == NULL) { | 295 if (data == NULL) { |
| 296 return ThrowException(String::New("Memory allocation failed.")); | 296 return ThrowException(String::New("Memory allocation failed.")); |
| 297 } | 297 } |
| 298 Handle<Object> array = Object::New(); | 298 Handle<Object> array = Object::New(); |
| 299 Persistent<Object> persistent_array = Persistent<Object>::New(array); | 299 Persistent<Object> persistent_array = Persistent<Object>::New(array); |
| 300 persistent_array.MakeWeak(data, ExternalArrayWeakCallback); | 300 persistent_array.MakeWeak(data, ExternalArrayWeakCallback); |
| 301 persistent_array.MarkIndependent(); | 301 persistent_array.MarkIndependent(); |
| 302 array->SetIndexedPropertiesToExternalArrayData(data, type, length); | 302 array->SetIndexedPropertiesToExternalArrayData(data, type, |
| 303 array->Set(String::New("length"), Int32::New(length), ReadOnly); | 303 static_cast<int>(length)); |
| 304 array->Set(String::New("BYTES_PER_ELEMENT"), Int32::New(element_size)); | 304 array->Set(String::New("length"), |
| 305 Int32::New(static_cast<int32_t>(length)), ReadOnly); |
| 306 array->Set(String::New("BYTES_PER_ELEMENT"), |
| 307 Int32::New(static_cast<int32_t>(element_size))); |
| 305 return array; | 308 return array; |
| 306 } | 309 } |
| 307 | 310 |
| 308 | 311 |
| 309 void Shell::ExternalArrayWeakCallback(Persistent<Value> object, void* data) { | 312 void Shell::ExternalArrayWeakCallback(Persistent<Value> object, void* data) { |
| 310 free(data); | 313 free(data); |
| 311 object.Dispose(); | 314 object.Dispose(); |
| 312 } | 315 } |
| 313 | 316 |
| 314 | 317 |
| (...skipping 468 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 783 #endif // USING_V8_SHARED | 786 #endif // USING_V8_SHARED |
| 784 if (file == NULL) return NULL; | 787 if (file == NULL) return NULL; |
| 785 | 788 |
| 786 fseek(file, 0, SEEK_END); | 789 fseek(file, 0, SEEK_END); |
| 787 int size = ftell(file); | 790 int size = ftell(file); |
| 788 rewind(file); | 791 rewind(file); |
| 789 | 792 |
| 790 char* chars = new char[size + 1]; | 793 char* chars = new char[size + 1]; |
| 791 chars[size] = '\0'; | 794 chars[size] = '\0'; |
| 792 for (int i = 0; i < size;) { | 795 for (int i = 0; i < size;) { |
| 793 int read = fread(&chars[i], 1, size - i, file); | 796 int read = static_cast<int>(fread(&chars[i], 1, size - i, file)); |
| 794 i += read; | 797 i += read; |
| 795 } | 798 } |
| 796 fclose(file); | 799 fclose(file); |
| 797 *size_out = size; | 800 *size_out = size; |
| 798 return chars; | 801 return chars; |
| 799 } | 802 } |
| 800 | 803 |
| 801 | 804 |
| 802 #ifndef USING_V8_SHARED | 805 #ifndef USING_V8_SHARED |
| 803 static char* ReadToken(char* data, char token) { | 806 static char* ReadToken(char* data, char token) { |
| (...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 974 #endif // USING_V8_SHARED | 977 #endif // USING_V8_SHARED |
| 975 if (file == NULL) return Handle<String>(); | 978 if (file == NULL) return Handle<String>(); |
| 976 | 979 |
| 977 fseek(file, 0, SEEK_END); | 980 fseek(file, 0, SEEK_END); |
| 978 int size = ftell(file); | 981 int size = ftell(file); |
| 979 rewind(file); | 982 rewind(file); |
| 980 | 983 |
| 981 char* chars = new char[size + 1]; | 984 char* chars = new char[size + 1]; |
| 982 chars[size] = '\0'; | 985 chars[size] = '\0'; |
| 983 for (int i = 0; i < size;) { | 986 for (int i = 0; i < size;) { |
| 984 int read = fread(&chars[i], 1, size - i, file); | 987 int read = static_cast<int>(fread(&chars[i], 1, size - i, file)); |
| 985 i += read; | 988 i += read; |
| 986 } | 989 } |
| 987 fclose(file); | 990 fclose(file); |
| 988 Handle<String> result = String::New(chars, size); | 991 Handle<String> result = String::New(chars, size); |
| 989 delete[] chars; | 992 delete[] chars; |
| 990 return result; | 993 return result; |
| 991 } | 994 } |
| 992 | 995 |
| 993 | 996 |
| 994 #ifndef USING_V8_SHARED | 997 #ifndef USING_V8_SHARED |
| (...skipping 286 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1281 } | 1284 } |
| 1282 | 1285 |
| 1283 } // namespace v8 | 1286 } // namespace v8 |
| 1284 | 1287 |
| 1285 | 1288 |
| 1286 #ifndef GOOGLE3 | 1289 #ifndef GOOGLE3 |
| 1287 int main(int argc, char* argv[]) { | 1290 int main(int argc, char* argv[]) { |
| 1288 return v8::Shell::Main(argc, argv); | 1291 return v8::Shell::Main(argc, argv); |
| 1289 } | 1292 } |
| 1290 #endif | 1293 #endif |
| OLD | NEW |