Reviewers: vogelheim,
Description:
Check in hello world example so it stays up to date
BUG=none
[email protected]
LOG=n
Please review this at https://codereview.chromium.org/1148063003/
Base URL: https://chromium.googlesource.com/v8/v8.git@master
Affected files (+75, -0 lines):
A samples/hello-world.cc
M samples/samples.gyp
Index: samples/hello-world.cc
diff --git a/samples/hello-world.cc b/samples/hello-world.cc
new file mode 100644
index
0000000000000000000000000000000000000000..c38c76022cd67ece2c2937bcf938a1a5a3f20441
--- /dev/null
+++ b/samples/hello-world.cc
@@ -0,0 +1,69 @@
+// Copyright 2015 the V8 project authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "include/libplatform/libplatform.h"
+#include "include/v8.h"
+
+using namespace v8;
+
+class ArrayBufferAllocator : public v8::ArrayBuffer::Allocator {
+ public:
+ virtual void* Allocate(size_t length) {
+ void* data = AllocateUninitialized(length);
+ return data == NULL ? data : memset(data, 0, length);
+ }
+ virtual void* AllocateUninitialized(size_t length) { return
malloc(length); }
+ virtual void Free(void* data, size_t) { free(data); }
+};
+
+
+int main(int argc, char* argv[]) {
+ // Initialize V8.
+ V8::InitializeICU();
+ Platform* platform = platform::CreateDefaultPlatform();
+ V8::InitializePlatform(platform);
+ V8::Initialize();
+
+ // Create a new Isolate and make it the current one.
+ ArrayBufferAllocator allocator;
+ Isolate::CreateParams create_params;
+ create_params.array_buffer_allocator = &allocator;
+ Isolate* isolate = Isolate::New(create_params);
+ {
+ Isolate::Scope isolate_scope(isolate);
+
+ // Create a stack-allocated handle scope.
+ HandleScope handle_scope(isolate);
+
+ // Create a new context.
+ Local<Context> context = Context::New(isolate);
+
+ // Enter the context for compiling and running the hello world script.
+ Context::Scope context_scope(context);
+
+ // Create a string containing the JavaScript source code.
+ Local<String> source = String::NewFromUtf8(isolate, "'Hello' + ',
World!'");
+
+ // Compile the source code.
+ Local<Script> script = Script::Compile(source);
+
+ // Run the script to get the result.
+ Local<Value> result = script->Run();
+
+ // Convert the result to an UTF8 string and print it.
+ String::Utf8Value utf8(result);
+ printf("%s\n", *utf8);
+ }
+
+ // Dispose the isolate and tear down V8.
+ isolate->Dispose();
+ V8::Dispose();
+ V8::ShutdownPlatform();
+ delete platform;
+ return 0;
+}
Index: samples/samples.gyp
diff --git a/samples/samples.gyp b/samples/samples.gyp
index
31e96f4ccbbdeb3ee217eb41abaab9c3d0701687..7e0608b2130c04fb8428c131a911750b67a13d6e
100644
--- a/samples/samples.gyp
+++ b/samples/samples.gyp
@@ -62,6 +62,12 @@
],
},
{
+ 'target_name': 'hello-world',
+ 'sources': [
+ 'hello-world.cc',
+ ],
+ },
+ {
'target_name': 'process',
'sources': [
'process.cc',
--
--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev
---
You received this message because you are subscribed to the Google Groups "v8-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.