1b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch// Copyright 2013 the V8 project authors. All rights reserved.
2b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch// Redistribution and use in source and binary forms, with or without
3b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch// modification, are permitted provided that the following conditions are
4b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch// met:
5b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch//
6b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch//     * Redistributions of source code must retain the above copyright
7b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch//       notice, this list of conditions and the following disclaimer.
8b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch//     * Redistributions in binary form must reproduce the above
9b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch//       copyright notice, this list of conditions and the following
10b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch//       disclaimer in the documentation and/or other materials provided
11b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch//       with the distribution.
12b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch//     * Neither the name of Google Inc. nor the names of its
13b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch//       contributors may be used to endorse or promote products derived
14b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch//       from this software without specific prior written permission.
15b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch//
16b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch
28b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch#include <limits.h>
29b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch
30b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch#include "src/v8.h"
31b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch
32b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch#include "src/api.h"
33b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch#include "src/base/platform/platform.h"
34b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch#include "src/compilation-cache.h"
35b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch#include "src/execution.h"
36b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch#include "src/isolate.h"
37b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch#include "src/parser.h"
38b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch#include "src/snapshot.h"
39b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch#include "src/unicode-inl.h"
40b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch#include "src/utils.h"
41b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch#include "test/cctest/cctest.h"
42b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch
43b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdochusing ::v8::Context;
44b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdochusing ::v8::Extension;
45b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdochusing ::v8::Function;
46b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdochusing ::v8::FunctionTemplate;
47b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdochusing ::v8::Handle;
48b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdochusing ::v8::HandleScope;
49b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdochusing ::v8::Local;
50b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdochusing ::v8::Message;
51b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdochusing ::v8::MessageCallback;
52b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdochusing ::v8::Object;
53b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdochusing ::v8::ObjectTemplate;
54b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdochusing ::v8::Persistent;
55b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdochusing ::v8::Script;
56b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdochusing ::v8::StackTrace;
57b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdochusing ::v8::String;
58b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdochusing ::v8::TryCatch;
59b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdochusing ::v8::Undefined;
60b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdochusing ::v8::V8;
61b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdochusing ::v8::Value;
62b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch
63b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdochstatic void ExpectBoolean(bool expected, Local<Value> result) {
64b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch  CHECK(result->IsBoolean());
65b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch  CHECK_EQ(expected, result->BooleanValue());
66b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch}
67b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch
68b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch
69b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdochstatic void ExpectInt32(int32_t expected, Local<Value> result) {
70b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch  CHECK(result->IsInt32());
71b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch  CHECK_EQ(expected, result->Int32Value());
72b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch}
73b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch
74b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch
75b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdochstatic void ExpectNumber(double expected, Local<Value> result) {
76b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch  CHECK(result->IsNumber());
77b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch  CHECK_EQ(expected, result->NumberValue());
78b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch}
79b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch
80b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch
81b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdochstatic void ExpectUndefined(Local<Value> result) {
82b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch  CHECK(result->IsUndefined());
83b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch}
84b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch
85b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch
86b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch// Tests are sorted by order of implementation.
87b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch
88b8a8cc1952d61a2f3a2568848933943a543b5d3eBen MurdochTEST(simple_value) {
89b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch  LocalContext env;
90b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch  v8::HandleScope scope(env->GetIsolate());
91b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch  Local<Value> result = CompileRun("0x271828;");
92b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch  ExpectInt32(0x271828, result);
93b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch}
94b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch
95b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch
96b8a8cc1952d61a2f3a2568848933943a543b5d3eBen MurdochTEST(global_variable) {
97b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch  LocalContext env;
98b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch  v8::HandleScope scope(env->GetIsolate());
99b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch  Local<Value> result = CompileRun("var my_global_var = 0x123; my_global_var;");
100b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch  ExpectInt32(0x123, result);
101b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch}
102b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch
103b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch
104b8a8cc1952d61a2f3a2568848933943a543b5d3eBen MurdochTEST(simple_function_call) {
105b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch  LocalContext env;
106b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch  v8::HandleScope scope(env->GetIsolate());
107b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch  Local<Value> result = CompileRun(
108b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch      "function foo() { return 0x314; }"
109b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch      "foo();");
110b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch  ExpectInt32(0x314, result);
111b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch}
112b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch
113b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch
114b8a8cc1952d61a2f3a2568848933943a543b5d3eBen MurdochTEST(binary_op) {
115b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch  LocalContext env;
116b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch  v8::HandleScope scope(env->GetIsolate());
117b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch  Local<Value> result = CompileRun(
118b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch      "function foo() {"
119b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch      "  var a = 0x1200;"
120b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch      "  var b = 0x0035;"
121b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch      "  return 2 * (a + b - 1);"
122b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch      "}"
123b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch      "foo();");
124b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch  ExpectInt32(0x2468, result);
125b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch}
126b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch
127b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdochstatic void if_comparison_testcontext_helper(
128b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch    char const * op,
129b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch    char const * lhs,
130b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch    char const * rhs,
131b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch    int          expect) {
132b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch  char buffer[256];
133b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch  snprintf(buffer, sizeof(buffer),
134b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch           "var lhs = %s;"
135b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch           "var rhs = %s;"
136b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch           "if ( lhs %s rhs ) { 1; }"
137b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch           "else { 0; }",
138b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch           lhs, rhs, op);
139b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch  Local<Value> result = CompileRun(buffer);
140b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch  ExpectInt32(expect, result);
141b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch}
142b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch
143b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdochstatic void if_comparison_effectcontext_helper(
144b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch    char const * op,
145b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch    char const * lhs,
146b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch    char const * rhs,
147b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch    int          expect) {
148b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch  char buffer[256];
149b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch  snprintf(buffer, sizeof(buffer),
150b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch           "var lhs = %s;"
151b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch           "var rhs = %s;"
152b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch           "var test = lhs %s rhs;"
153b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch           "if ( test ) { 1; }"
154b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch           "else { 0; }",
155b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch           lhs, rhs, op);
156b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch  Local<Value> result = CompileRun(buffer);
157b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch  ExpectInt32(expect, result);
158b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch}
159b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch
160b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdochstatic void if_comparison_helper(
161b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch    char const * op,
162b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch    int          expect_when_lt,
163b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch    int          expect_when_eq,
164b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch    int          expect_when_gt) {
165b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch  // TODO(all): Non-SMI tests.
166b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch
167b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch  if_comparison_testcontext_helper(op, "1", "3", expect_when_lt);
168b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch  if_comparison_testcontext_helper(op, "5", "5", expect_when_eq);
169b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch  if_comparison_testcontext_helper(op, "9", "7", expect_when_gt);
170b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch
171b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch  if_comparison_effectcontext_helper(op, "1", "3", expect_when_lt);
172b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch  if_comparison_effectcontext_helper(op, "5", "5", expect_when_eq);
173b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch  if_comparison_effectcontext_helper(op, "9", "7", expect_when_gt);
174b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch}
175b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch
176b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch
177b8a8cc1952d61a2f3a2568848933943a543b5d3eBen MurdochTEST(if_comparison) {
178b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch  LocalContext env;
179b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch  v8::HandleScope scope(env->GetIsolate());
180b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch
181b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch  if_comparison_helper("<",   1, 0, 0);
182b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch  if_comparison_helper("<=",  1, 1, 0);
183b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch  if_comparison_helper("==",  0, 1, 0);
184b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch  if_comparison_helper("===", 0, 1, 0);
185b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch  if_comparison_helper(">=",  0, 1, 1);
186b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch  if_comparison_helper(">",   0, 0, 1);
187b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch  if_comparison_helper("!=",  1, 0, 1);
188b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch  if_comparison_helper("!==", 1, 0, 1);
189b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch}
190b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch
191b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch
192b8a8cc1952d61a2f3a2568848933943a543b5d3eBen MurdochTEST(unary_plus) {
193b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch  LocalContext env;
194b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch  v8::HandleScope scope(env->GetIsolate());
195b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch  Local<Value> result;
196b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch  // SMI
197b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch  result = CompileRun("var a = 1234; +a");
198b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch  ExpectInt32(1234, result);
199b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch  // Number
200b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch  result = CompileRun("var a = 1234.5; +a");
201b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch  ExpectNumber(1234.5, result);
202b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch  // String (SMI)
203b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch  result = CompileRun("var a = '1234'; +a");
204b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch  ExpectInt32(1234, result);
205b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch  // String (Number)
206b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch  result = CompileRun("var a = '1234.5'; +a");
207b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch  ExpectNumber(1234.5, result);
208b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch  // Check side effects.
209b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch  result = CompileRun("var a = 1234; +(a = 4321); a");
210b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch  ExpectInt32(4321, result);
211b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch}
212b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch
213b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch
214b8a8cc1952d61a2f3a2568848933943a543b5d3eBen MurdochTEST(unary_minus) {
215b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch  LocalContext env;
216b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch  v8::HandleScope scope(env->GetIsolate());
217b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch  Local<Value> result;
218b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch  result = CompileRun("var a = 1234; -a");
219b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch  ExpectInt32(-1234, result);
220b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch  result = CompileRun("var a = 1234.5; -a");
221b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch  ExpectNumber(-1234.5, result);
222b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch  result = CompileRun("var a = 1234; -(a = 4321); a");
223b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch  ExpectInt32(4321, result);
224b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch  result = CompileRun("var a = '1234'; -a");
225b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch  ExpectInt32(-1234, result);
226b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch  result = CompileRun("var a = '1234.5'; -a");
227b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch  ExpectNumber(-1234.5, result);
228b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch}
229b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch
230b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch
231b8a8cc1952d61a2f3a2568848933943a543b5d3eBen MurdochTEST(unary_void) {
232b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch  LocalContext env;
233b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch  v8::HandleScope scope(env->GetIsolate());
234b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch  Local<Value> result;
235b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch  result = CompileRun("var a = 1234; void (a);");
236b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch  ExpectUndefined(result);
237b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch  result = CompileRun("var a = 0; void (a = 42); a");
238b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch  ExpectInt32(42, result);
239b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch  result = CompileRun("var a = 0; void (a = 42);");
240b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch  ExpectUndefined(result);
241b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch}
242b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch
243b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch
244b8a8cc1952d61a2f3a2568848933943a543b5d3eBen MurdochTEST(unary_not) {
245b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch  LocalContext env;
246b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch  v8::HandleScope scope(env->GetIsolate());
247b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch  Local<Value> result;
248b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch  result = CompileRun("var a = 1234; !a");
249b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch  ExpectBoolean(false, result);
250b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch  result = CompileRun("var a = 0; !a");
251b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch  ExpectBoolean(true, result);
252b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch  result = CompileRun("var a = 0; !(a = 1234); a");
253b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch  ExpectInt32(1234, result);
254b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch  result = CompileRun("var a = '1234'; !a");
255b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch  ExpectBoolean(false, result);
256b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch  result = CompileRun("var a = ''; !a");
257b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch  ExpectBoolean(true, result);
258b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch  result = CompileRun("var a = 1234; !!a");
259b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch  ExpectBoolean(true, result);
260b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch  result = CompileRun("var a = 0; !!a");
261b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch  ExpectBoolean(false, result);
262b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch  result = CompileRun("var a = 0; if ( !a ) { 1; } else { 0; }");
263b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch  ExpectInt32(1, result);
264b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch  result = CompileRun("var a = 1; if ( !a ) { 1; } else { 0; }");
265b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch  ExpectInt32(0, result);
266b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch}
267