source: gaycko/trunk/src/js/glue.cpp @ 4727

Last change on this file since 4727 was 4727, checked in by Jean-Yves Lamoureux, 9 years ago
  • Added V8 test
  • command line test and usage display
File size: 826 bytes
Line 
1#include <string.h>
2#include <v8.h>
3#include "js/glue.h"
4
5using namespace v8;
6
7char* testV8(void) {
8        // Create a stack-allocated handle scope.
9        HandleScope handle_scope;
10
11        // Create a new context.
12        Persistent<Context> context = Context::New();
13
14        // Enter the created context for compiling and
15        // running the hello world script.
16        Context::Scope context_scope(context);
17
18        // Create a string containing the JavaScript source code.
19        Handle<String> source = String::New("'Hello' + ', World!'");
20
21        // Compile the source code.
22        Handle<Script> script = Script::Compile(source);
23
24        // Run the script to get the result.
25        Handle<Value> result = script->Run();
26
27        // Dispose the persistent context.
28        context.Dispose();
29
30        // Convert the result to an ASCII string and print it.
31        String::AsciiValue ascii(result);
32        return strdup(*ascii);
33}
34
Note: See TracBrowser for help on using the repository browser.