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

Unified Diff: samples/shell.cc

Issue 7348008: Merge up to 8597 to experimental/gc from the bleeding edge. (Closed) Base URL: http://v8.googlecode.com/svn/branches/experimental/gc/
Patch Set: '' Created 9 years, 5 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « samples/process.cc ('k') | src/SConscript » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: samples/shell.cc
===================================================================
--- samples/shell.cc (revision 8618)
+++ samples/shell.cc (working copy)
@@ -41,7 +41,7 @@
// #ifndef USING_V8_SHARED/#endif is a hack until we can resolve whether to
// still use the shell sample for testing or change to use the developer
// shell d8 TODO(1272).
-#ifndef USING_V8_SHARED
+#if !(defined(USING_V8_SHARED) || defined(V8_SHARED))
#include "../src/v8.h"
#endif // USING_V8_SHARED
@@ -86,7 +86,7 @@
class SourceGroup {
public:
SourceGroup() :
-#ifndef USING_V8_SHARED
+#if !(defined(USING_V8_SHARED) || defined(V8_SHARED))
next_semaphore_(v8::internal::OS::CreateSemaphore(0)),
done_semaphore_(v8::internal::OS::CreateSemaphore(0)),
thread_(NULL),
@@ -134,7 +134,7 @@
}
}
-#ifndef USING_V8_SHARED
+#if !(defined(USING_V8_SHARED) || defined(V8_SHARED))
void StartExecuteInThread() {
if (thread_ == NULL) {
thread_ = new IsolateThread(this);
@@ -155,7 +155,7 @@
#endif // USING_V8_SHARED
private:
-#ifndef USING_V8_SHARED
+#if !(defined(USING_V8_SHARED) || defined(V8_SHARED))
static v8::internal::Thread::Options GetThreadOptions() {
v8::internal::Thread::Options options;
options.name = "IsolateThread";
@@ -170,7 +170,7 @@
class IsolateThread : public v8::internal::Thread {
public:
explicit IsolateThread(SourceGroup* group)
- : v8::internal::Thread(NULL, GetThreadOptions()), group_(group) {}
+ : v8::internal::Thread(GetThreadOptions()), group_(group) {}
virtual void Run() {
group_->ExecuteInThread();
@@ -213,6 +213,34 @@
static SourceGroup* isolate_sources = NULL;
+#ifdef COMPRESS_STARTUP_DATA_BZ2
+class BZip2Decompressor : public v8::StartupDataDecompressor {
+ public:
+ virtual ~BZip2Decompressor() { }
+
+ protected:
+ virtual int DecompressData(char* raw_data,
+ int* raw_data_size,
+ const char* compressed_data,
+ int compressed_data_size) {
+ ASSERT_EQ(v8::StartupData::kBZip2,
+ v8::V8::GetCompressedStartupDataAlgorithm());
+ unsigned int decompressed_size = *raw_data_size;
+ int result =
+ BZ2_bzBuffToBuffDecompress(raw_data,
+ &decompressed_size,
+ const_cast<char*>(compressed_data),
+ compressed_data_size,
+ 0, 1);
+ if (result == BZ_OK) {
+ *raw_data_size = decompressed_size;
+ }
+ return result;
+ }
+};
+#endif
+
+
int RunMain(int argc, char* argv[]) {
v8::V8::SetFlagsFromCommandLine(&argc, argv, true);
v8::HandleScope handle_scope;
@@ -228,7 +256,7 @@
int num_isolates = 1;
for (int i = 1; i < argc; i++) {
if (strcmp(argv[i], "--isolate") == 0) {
-#ifndef USING_V8_SHARED
+#if !(defined(USING_V8_SHARED) || defined(V8_SHARED))
++num_isolates;
#else // USING_V8_SHARED
printf("Error: --isolate not supported when linked with shared "
@@ -259,14 +287,14 @@
}
current->End(argc);
}
-#ifndef USING_V8_SHARED
+#if !(defined(USING_V8_SHARED) || defined(V8_SHARED))
for (int i = 1; i < num_isolates; ++i) {
isolate_sources[i].StartExecuteInThread();
}
#endif // USING_V8_SHARED
isolate_sources[0].Execute();
if (run_shell) RunShell(context);
-#ifndef USING_V8_SHARED
+#if !(defined(USING_V8_SHARED) || defined(V8_SHARED))
for (int i = 1; i < num_isolates; ++i) {
isolate_sources[i].WaitForThread();
}
@@ -303,29 +331,13 @@
}
#ifdef COMPRESS_STARTUP_DATA_BZ2
- ASSERT_EQ(v8::StartupData::kBZip2,
- v8::V8::GetCompressedStartupDataAlgorithm());
- int compressed_data_count = v8::V8::GetCompressedStartupDataCount();
- v8::StartupData* compressed_data = new v8::StartupData[compressed_data_count];
- v8::V8::GetCompressedStartupData(compressed_data);
- for (int i = 0; i < compressed_data_count; ++i) {
- char* decompressed = new char[compressed_data[i].raw_size];
- unsigned int decompressed_size = compressed_data[i].raw_size;
- int result =
- BZ2_bzBuffToBuffDecompress(decompressed,
- &decompressed_size,
- const_cast<char*>(compressed_data[i].data),
- compressed_data[i].compressed_size,
- 0, 1);
- if (result != BZ_OK) {
- fprintf(stderr, "bzip error code: %d\n", result);
- exit(1);
- }
- compressed_data[i].data = decompressed;
- compressed_data[i].raw_size = decompressed_size;
+ BZip2Decompressor startup_data_decompressor;
+ int bz2_result = startup_data_decompressor.Decompress();
+ if (bz2_result != BZ_OK) {
+ fprintf(stderr, "bzip error code: %d\n", bz2_result);
+ exit(1);
}
- v8::V8::SetDecompressedStartupData(compressed_data);
-#endif // COMPRESS_STARTUP_DATA_BZ2
+#endif
v8::V8::SetFlagsFromCommandLine(&argc, argv, true);
int result = 0;
@@ -348,13 +360,6 @@
}
v8::V8::Dispose();
-#ifdef COMPRESS_STARTUP_DATA_BZ2
- for (int i = 0; i < compressed_data_count; ++i) {
- delete[] compressed_data[i].data;
- }
- delete[] compressed_data;
-#endif // COMPRESS_STARTUP_DATA_BZ2
-
return result;
}
@@ -492,14 +497,42 @@
v8::Handle<v8::Value> CreateExternalArray(const v8::Arguments& args,
v8::ExternalArrayType type,
- int element_size) {
+ size_t element_size) {
+ assert(element_size == 1 ||
+ element_size == 2 ||
+ element_size == 4 ||
+ element_size == 8);
if (args.Length() != 1) {
return v8::ThrowException(
v8::String::New("Array constructor needs one parameter."));
}
- int length = args[0]->Int32Value();
- void* data = malloc(length * element_size);
- memset(data, 0, length * element_size);
+ static const int kMaxLength = 0x3fffffff;
+ size_t length = 0;
+ if (args[0]->IsUint32()) {
+ length = args[0]->Uint32Value();
+ } else if (args[0]->IsNumber()) {
+ double raw_length = args[0]->NumberValue();
+ if (raw_length < 0) {
+ return v8::ThrowException(
+ v8::String::New("Array length must not be negative."));
+ }
+ if (raw_length > kMaxLength) {
+ return v8::ThrowException(
+ v8::String::New("Array length exceeds maximum length."));
+ }
+ length = static_cast<size_t>(raw_length);
+ } else {
+ return v8::ThrowException(
+ v8::String::New("Array length must be a number."));
+ }
+ if (length > static_cast<size_t>(kMaxLength)) {
+ return v8::ThrowException(
+ v8::String::New("Array length exceeds maximum length."));
+ }
+ void* data = calloc(length, element_size);
+ if (data == NULL) {
+ return v8::ThrowException(v8::String::New("Memory allocation failed."));
+ }
v8::Handle<v8::Object> array = v8::Object::New();
v8::Persistent<v8::Object> persistent_array =
v8::Persistent<v8::Object>::New(array);
« no previous file with comments | « samples/process.cc ('k') | src/SConscript » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698