44 using ::v8::Extension;
46 using ::v8::FunctionTemplate;
48 using ::v8::HandleScope;
53 using ::v8::ObjectTemplate;
54 using ::v8::Persistent;
56 using ::v8::StackTrace;
63 static void ExpectBoolean(
bool expected, Local<Value> result) {
64 CHECK(result->IsBoolean());
65 CHECK_EQ(expected, result->BooleanValue());
69 static void ExpectInt32(
int32_t expected, Local<Value> result) {
70 CHECK(result->IsInt32());
71 CHECK_EQ(expected, result->Int32Value());
75 static void ExpectNumber(
double expected, Local<Value> result) {
76 CHECK(result->IsNumber());
77 CHECK_EQ(expected, result->NumberValue());
81 static void ExpectUndefined(Local<Value> result) {
82 CHECK(result->IsUndefined());
91 Local<Value> result = CompileRun(
"0x271828;");
92 ExpectInt32(0x271828, result);
99 Local<Value> result = CompileRun(
"var my_global_var = 0x123; my_global_var;");
100 ExpectInt32(0x123, result);
107 Local<Value> result = CompileRun(
108 "function foo() { return 0x314; }"
110 ExpectInt32(0x314, result);
117 Local<Value> result = CompileRun(
121 " return 2 * (a + b - 1);"
124 ExpectInt32(0x2468, result);
127 static void if_comparison_testcontext_helper(
133 snprintf(buffer,
sizeof(buffer),
136 "if ( lhs %s rhs ) { 1; }"
139 Local<Value> result = CompileRun(buffer);
140 ExpectInt32(expect, result);
143 static void if_comparison_effectcontext_helper(
149 snprintf(buffer,
sizeof(buffer),
152 "var test = lhs %s rhs;"
156 Local<Value> result = CompileRun(buffer);
157 ExpectInt32(expect, result);
160 static void if_comparison_helper(
164 int expect_when_gt) {
167 if_comparison_testcontext_helper(op,
"1",
"3", expect_when_lt);
168 if_comparison_testcontext_helper(op,
"5",
"5", expect_when_eq);
169 if_comparison_testcontext_helper(op,
"9",
"7", expect_when_gt);
171 if_comparison_effectcontext_helper(op,
"1",
"3", expect_when_lt);
172 if_comparison_effectcontext_helper(op,
"5",
"5", expect_when_eq);
173 if_comparison_effectcontext_helper(op,
"9",
"7", expect_when_gt);
181 if_comparison_helper(
"<", 1, 0, 0);
182 if_comparison_helper(
"<=", 1, 1, 0);
183 if_comparison_helper(
"==", 0, 1, 0);
184 if_comparison_helper(
"===", 0, 1, 0);
185 if_comparison_helper(
">=", 0, 1, 1);
186 if_comparison_helper(
">", 0, 0, 1);
187 if_comparison_helper(
"!=", 1, 0, 1);
188 if_comparison_helper(
"!==", 1, 0, 1);
197 result = CompileRun(
"var a = 1234; +a");
198 ExpectInt32(1234, result);
200 result = CompileRun(
"var a = 1234.5; +a");
201 ExpectNumber(1234.5, result);
203 result = CompileRun(
"var a = '1234'; +a");
204 ExpectInt32(1234, result);
206 result = CompileRun(
"var a = '1234.5'; +a");
207 ExpectNumber(1234.5, result);
209 result = CompileRun(
"var a = 1234; +(a = 4321); a");
210 ExpectInt32(4321, result);
218 result = CompileRun(
"var a = 1234; -a");
219 ExpectInt32(-1234, result);
220 result = CompileRun(
"var a = 1234.5; -a");
221 ExpectNumber(-1234.5, result);
222 result = CompileRun(
"var a = 1234; -(a = 4321); a");
223 ExpectInt32(4321, result);
224 result = CompileRun(
"var a = '1234'; -a");
225 ExpectInt32(-1234, result);
226 result = CompileRun(
"var a = '1234.5'; -a");
227 ExpectNumber(-1234.5, result);
235 result = CompileRun(
"var a = 1234; void (a);");
236 ExpectUndefined(result);
237 result = CompileRun(
"var a = 0; void (a = 42); a");
238 ExpectInt32(42, result);
239 result = CompileRun(
"var a = 0; void (a = 42);");
240 ExpectUndefined(result);
248 result = CompileRun(
"var a = 1234; !a");
249 ExpectBoolean(
false, result);
250 result = CompileRun(
"var a = 0; !a");
251 ExpectBoolean(
true, result);
252 result = CompileRun(
"var a = 0; !(a = 1234); a");
253 ExpectInt32(1234, result);
254 result = CompileRun(
"var a = '1234'; !a");
255 ExpectBoolean(
false, result);
256 result = CompileRun(
"var a = ''; !a");
257 ExpectBoolean(
true, result);
258 result = CompileRun(
"var a = 1234; !!a");
259 ExpectBoolean(
true, result);
260 result = CompileRun(
"var a = 0; !!a");
261 ExpectBoolean(
false, result);
262 result = CompileRun(
"var a = 0; if ( !a ) { 1; } else { 0; }");
263 ExpectInt32(1, result);
264 result = CompileRun(
"var a = 1; if ( !a ) { 1; } else { 0; }");
265 ExpectInt32(0, result);
#define CHECK_EQ(expected, value)
kSerializedDataOffset Object
void(* MessageCallback)(Handle< Message > message, Handle< Value > error)
v8::Isolate * GetIsolate()
V8_INLINE Handle< Primitive > Undefined(Isolate *isolate)