OLD | NEW |
1 // Copyright 2015 the V8 project authors. All rights reserved. | 1 // Copyright 2015 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include <stdio.h> | 5 #include <stdio.h> |
6 #include <stdlib.h> | 6 #include <stdlib.h> |
7 #include <string.h> | 7 #include <string.h> |
8 | 8 |
9 #include "include/libplatform/libplatform.h" | 9 #include "include/libplatform/libplatform.h" |
10 #include "include/v8.h" | 10 #include "include/v8.h" |
(...skipping 29 matching lines...) Expand all Loading... |
40 // Create a stack-allocated handle scope. | 40 // Create a stack-allocated handle scope. |
41 HandleScope handle_scope(isolate); | 41 HandleScope handle_scope(isolate); |
42 | 42 |
43 // Create a new context. | 43 // Create a new context. |
44 Local<Context> context = Context::New(isolate); | 44 Local<Context> context = Context::New(isolate); |
45 | 45 |
46 // Enter the context for compiling and running the hello world script. | 46 // Enter the context for compiling and running the hello world script. |
47 Context::Scope context_scope(context); | 47 Context::Scope context_scope(context); |
48 | 48 |
49 // Create a string containing the JavaScript source code. | 49 // Create a string containing the JavaScript source code. |
50 Local<String> source = String::NewFromUtf8(isolate, "'Hello' + ', World!'"); | 50 Local<String> source = |
| 51 String::NewFromUtf8(isolate, "'Hello' + ', World!'", |
| 52 NewStringType::kNormal).ToLocalChecked(); |
51 | 53 |
52 // Compile the source code. | 54 // Compile the source code. |
53 Local<Script> script = Script::Compile(source); | 55 Local<Script> script = Script::Compile(context, source).ToLocalChecked(); |
54 | 56 |
55 // Run the script to get the result. | 57 // Run the script to get the result. |
56 Local<Value> result = script->Run(); | 58 Local<Value> result = script->Run(context).ToLocalChecked(); |
57 | 59 |
58 // Convert the result to an UTF8 string and print it. | 60 // Convert the result to an UTF8 string and print it. |
59 String::Utf8Value utf8(result); | 61 String::Utf8Value utf8(result); |
60 printf("%s\n", *utf8); | 62 printf("%s\n", *utf8); |
61 } | 63 } |
62 | 64 |
63 // Dispose the isolate and tear down V8. | 65 // Dispose the isolate and tear down V8. |
64 isolate->Dispose(); | 66 isolate->Dispose(); |
65 V8::Dispose(); | 67 V8::Dispose(); |
66 V8::ShutdownPlatform(); | 68 V8::ShutdownPlatform(); |
67 delete platform; | 69 delete platform; |
68 return 0; | 70 return 0; |
69 } | 71 } |
OLD | NEW |