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

Side by Side Diff: src/d8.cc

Issue 15817014: remove most uses of raw handle constructors (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: stupid cast needed Created 7 years, 6 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/arguments.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 // 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 1058 matching lines...) Expand 10 before | Expand all | Expand 10 after
1069 for (int i = 0; i < size;) { 1069 for (int i = 0; i < size;) {
1070 int read = static_cast<int>(fread(&chars[i], 1, size - i, file)); 1070 int read = static_cast<int>(fread(&chars[i], 1, size - i, file));
1071 i += read; 1071 i += read;
1072 } 1072 }
1073 fclose(file); 1073 fclose(file);
1074 *size_out = size; 1074 *size_out = size;
1075 return chars; 1075 return chars;
1076 } 1076 }
1077 1077
1078 static void ReadBufferWeakCallback(v8::Isolate* isolate, 1078 static void ReadBufferWeakCallback(v8::Isolate* isolate,
1079 Persistent<Value>* object, 1079 Persistent<ArrayBuffer>* array_buffer,
1080 uint8_t* data) { 1080 uint8_t* data) {
1081 size_t byte_length = ArrayBuffer::Cast(**object)->ByteLength(); 1081 size_t byte_length =
1082 Local<ArrayBuffer>::New(isolate, *array_buffer)->ByteLength();
1082 isolate->AdjustAmountOfExternalAllocatedMemory( 1083 isolate->AdjustAmountOfExternalAllocatedMemory(
1083 -static_cast<intptr_t>(byte_length)); 1084 -static_cast<intptr_t>(byte_length));
1084 1085
1085 delete[] data; 1086 delete[] data;
1086 object->Dispose(isolate); 1087 array_buffer->Dispose();
1087 } 1088 }
1088 1089
1089 void Shell::ReadBuffer(const v8::FunctionCallbackInfo<v8::Value>& args) { 1090 void Shell::ReadBuffer(const v8::FunctionCallbackInfo<v8::Value>& args) {
1090 ASSERT(sizeof(char) == sizeof(uint8_t)); // NOLINT 1091 ASSERT(sizeof(char) == sizeof(uint8_t)); // NOLINT
1091 String::Utf8Value filename(args[0]); 1092 String::Utf8Value filename(args[0]);
1092 int length; 1093 int length;
1093 if (*filename == NULL) { 1094 if (*filename == NULL) {
1094 Throw("Error loading file"); 1095 Throw("Error loading file");
1095 return; 1096 return;
1096 } 1097 }
1097 1098
1098 Isolate* isolate = args.GetIsolate(); 1099 Isolate* isolate = args.GetIsolate();
1099 uint8_t* data = reinterpret_cast<uint8_t*>( 1100 uint8_t* data = reinterpret_cast<uint8_t*>(
1100 ReadChars(args.GetIsolate(), *filename, &length)); 1101 ReadChars(args.GetIsolate(), *filename, &length));
1101 if (data == NULL) { 1102 if (data == NULL) {
1102 Throw("Error reading file"); 1103 Throw("Error reading file");
1103 return; 1104 return;
1104 } 1105 }
1105 Handle<v8::ArrayBuffer> buffer = ArrayBuffer::New(data, length); 1106 Handle<v8::ArrayBuffer> buffer = ArrayBuffer::New(data, length);
1106 v8::Persistent<v8::Value> weak_handle(isolate, buffer); 1107 v8::Persistent<v8::ArrayBuffer> weak_handle(isolate, buffer);
1107 weak_handle.MakeWeak(isolate, data, ReadBufferWeakCallback); 1108 weak_handle.MakeWeak(isolate, data, ReadBufferWeakCallback);
1108 weak_handle.MarkIndependent(); 1109 weak_handle.MarkIndependent();
1109 isolate->AdjustAmountOfExternalAllocatedMemory(length); 1110 isolate->AdjustAmountOfExternalAllocatedMemory(length);
1110 1111
1111 args.GetReturnValue().Set(buffer); 1112 args.GetReturnValue().Set(buffer);
1112 } 1113 }
1113 1114
1114 1115
1115 #ifndef V8_SHARED 1116 #ifndef V8_SHARED
1116 static char* ReadToken(char* data, char token) { 1117 static char* ReadToken(char* data, char token) {
(...skipping 539 matching lines...) Expand 10 before | Expand all | Expand 10 after
1656 } 1657 }
1657 1658
1658 } // namespace v8 1659 } // namespace v8
1659 1660
1660 1661
1661 #ifndef GOOGLE3 1662 #ifndef GOOGLE3
1662 int main(int argc, char* argv[]) { 1663 int main(int argc, char* argv[]) {
1663 return v8::Shell::Main(argc, argv); 1664 return v8::Shell::Main(argc, argv);
1664 } 1665 }
1665 #endif 1666 #endif
OLDNEW
« no previous file with comments | « src/arguments.cc ('k') | src/d8-debug.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698