1c47dff5fc3b12ecc3a7a9fc61fbd02868548dde6mvstanton@chromium.org// Copyright 2013 the V8 project authors. All rights reserved.
2c47dff5fc3b12ecc3a7a9fc61fbd02868548dde6mvstanton@chromium.org// Redistribution and use in source and binary forms, with or without
3c47dff5fc3b12ecc3a7a9fc61fbd02868548dde6mvstanton@chromium.org// modification, are permitted provided that the following conditions are
4c47dff5fc3b12ecc3a7a9fc61fbd02868548dde6mvstanton@chromium.org// met:
5c47dff5fc3b12ecc3a7a9fc61fbd02868548dde6mvstanton@chromium.org//
6c47dff5fc3b12ecc3a7a9fc61fbd02868548dde6mvstanton@chromium.org//     * Redistributions of source code must retain the above copyright
7c47dff5fc3b12ecc3a7a9fc61fbd02868548dde6mvstanton@chromium.org//       notice, this list of conditions and the following disclaimer.
8c47dff5fc3b12ecc3a7a9fc61fbd02868548dde6mvstanton@chromium.org//     * Redistributions in binary form must reproduce the above
9c47dff5fc3b12ecc3a7a9fc61fbd02868548dde6mvstanton@chromium.org//       copyright notice, this list of conditions and the following
10c47dff5fc3b12ecc3a7a9fc61fbd02868548dde6mvstanton@chromium.org//       disclaimer in the documentation and/or other materials provided
11c47dff5fc3b12ecc3a7a9fc61fbd02868548dde6mvstanton@chromium.org//       with the distribution.
12c47dff5fc3b12ecc3a7a9fc61fbd02868548dde6mvstanton@chromium.org//     * Neither the name of Google Inc. nor the names of its
13c47dff5fc3b12ecc3a7a9fc61fbd02868548dde6mvstanton@chromium.org//       contributors may be used to endorse or promote products derived
14c47dff5fc3b12ecc3a7a9fc61fbd02868548dde6mvstanton@chromium.org//       from this software without specific prior written permission.
15c47dff5fc3b12ecc3a7a9fc61fbd02868548dde6mvstanton@chromium.org//
16c47dff5fc3b12ecc3a7a9fc61fbd02868548dde6mvstanton@chromium.org// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17c47dff5fc3b12ecc3a7a9fc61fbd02868548dde6mvstanton@chromium.org// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18c47dff5fc3b12ecc3a7a9fc61fbd02868548dde6mvstanton@chromium.org// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19c47dff5fc3b12ecc3a7a9fc61fbd02868548dde6mvstanton@chromium.org// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20c47dff5fc3b12ecc3a7a9fc61fbd02868548dde6mvstanton@chromium.org// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21c47dff5fc3b12ecc3a7a9fc61fbd02868548dde6mvstanton@chromium.org// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22c47dff5fc3b12ecc3a7a9fc61fbd02868548dde6mvstanton@chromium.org// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23c47dff5fc3b12ecc3a7a9fc61fbd02868548dde6mvstanton@chromium.org// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24c47dff5fc3b12ecc3a7a9fc61fbd02868548dde6mvstanton@chromium.org// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25c47dff5fc3b12ecc3a7a9fc61fbd02868548dde6mvstanton@chromium.org// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26c47dff5fc3b12ecc3a7a9fc61fbd02868548dde6mvstanton@chromium.org// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27c47dff5fc3b12ecc3a7a9fc61fbd02868548dde6mvstanton@chromium.org
28196eb601290dc49c3754da728dc58700dff2de1bmachenbach@chromium.org#include "src/v8.h"
29c47dff5fc3b12ecc3a7a9fc61fbd02868548dde6mvstanton@chromium.org
30196eb601290dc49c3754da728dc58700dff2de1bmachenbach@chromium.org#include "test/cctest/cctest.h"
31c47dff5fc3b12ecc3a7a9fc61fbd02868548dde6mvstanton@chromium.org
32c47dff5fc3b12ecc3a7a9fc61fbd02868548dde6mvstanton@chromium.orgusing namespace v8;
33c47dff5fc3b12ecc3a7a9fc61fbd02868548dde6mvstanton@chromium.org
34c47dff5fc3b12ecc3a7a9fc61fbd02868548dde6mvstanton@chromium.org// This test fails if properties on the prototype of the global object appear
35c47dff5fc3b12ecc3a7a9fc61fbd02868548dde6mvstanton@chromium.org// as declared globals.
36c47dff5fc3b12ecc3a7a9fc61fbd02868548dde6mvstanton@chromium.orgTEST(StrictUndeclaredGlobalVariable) {
37528ce02b8680a3ab6d75c7079f180a4016c69b7amachenbach@chromium.org  HandleScope scope(CcTest::isolate());
38c47dff5fc3b12ecc3a7a9fc61fbd02868548dde6mvstanton@chromium.org  v8::Local<v8::String> var_name = v8_str("x");
39f95d4b920abb640ab0986d138ad559a7d3b91d04danno@chromium.org  LocalContext context;
40c47dff5fc3b12ecc3a7a9fc61fbd02868548dde6mvstanton@chromium.org  v8::TryCatch try_catch;
41c47dff5fc3b12ecc3a7a9fc61fbd02868548dde6mvstanton@chromium.org  v8::Local<v8::Script> script = v8_compile("\"use strict\"; x = 42;");
420f13e74b7310d8b14f19c6b93b36ff95059f97f6ulan@chromium.org  v8::Handle<v8::Object> proto = v8::Object::New(CcTest::isolate());
43c47dff5fc3b12ecc3a7a9fc61fbd02868548dde6mvstanton@chromium.org  v8::Handle<v8::Object> global =
44c47dff5fc3b12ecc3a7a9fc61fbd02868548dde6mvstanton@chromium.org      context->Global()->GetPrototype().As<v8::Object>();
45c47dff5fc3b12ecc3a7a9fc61fbd02868548dde6mvstanton@chromium.org  proto->Set(var_name, v8_num(100));
46c47dff5fc3b12ecc3a7a9fc61fbd02868548dde6mvstanton@chromium.org  global->SetPrototype(proto);
47c47dff5fc3b12ecc3a7a9fc61fbd02868548dde6mvstanton@chromium.org  script->Run();
48c47dff5fc3b12ecc3a7a9fc61fbd02868548dde6mvstanton@chromium.org  CHECK(try_catch.HasCaught());
49c47dff5fc3b12ecc3a7a9fc61fbd02868548dde6mvstanton@chromium.org  v8::String::Utf8Value exception(try_catch.Exception());
50c47dff5fc3b12ecc3a7a9fc61fbd02868548dde6mvstanton@chromium.org  CHECK_EQ("ReferenceError: x is not defined", *exception);
51c47dff5fc3b12ecc3a7a9fc61fbd02868548dde6mvstanton@chromium.org}
52