19258b6bc66e09368ada54001f619d53b4fc976d5ager@chromium.org// Copyright 2007-2008 the V8 project authors. All rights reserved.
29a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com// Redistribution and use in source and binary forms, with or without
39a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com// modification, are permitted provided that the following conditions are
49a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com// met:
59a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com//
69a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com//     * Redistributions of source code must retain the above copyright
79a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com//       notice, this list of conditions and the following disclaimer.
89a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com//     * Redistributions in binary form must reproduce the above
99a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com//       copyright notice, this list of conditions and the following
109a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com//       disclaimer in the documentation and/or other materials provided
119a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com//       with the distribution.
129a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com//     * Neither the name of Google Inc. nor the names of its
139a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com//       contributors may be used to endorse or promote products derived
149a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com//       from this software without specific prior written permission.
159a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com//
169a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
179a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
189a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
199a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
209a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
219a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
229a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
239a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
249a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
259a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
269a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
279a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com
289a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com#include <stdlib.h>
299a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com
30196eb601290dc49c3754da728dc58700dff2de1bmachenbach@chromium.org#include "src/v8.h"
319a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com
32196eb601290dc49c3754da728dc58700dff2de1bmachenbach@chromium.org#include "src/heap.h"
33196eb601290dc49c3754da728dc58700dff2de1bmachenbach@chromium.org#include "test/cctest/cctest.h"
349a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com
359a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.comusing namespace v8;
369a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com
379a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com
389a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.comenum Expectations {
399a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com  EXPECT_RESULT,
4046839fbbdee40a3d2d924e8b5b13c4139b0b24f2yangguo@chromium.org  EXPECT_EXCEPTION,
4146839fbbdee40a3d2d924e8b5b13c4139b0b24f2yangguo@chromium.org  EXPECT_ERROR
429a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com};
439a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com
449a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com
459a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com// A DeclarationContext holds a reference to a v8::Context and keeps
469a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com// track of various declaration related counters to make it easier to
479a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com// track if global declarations in the presence of interceptors behave
489a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com// the right way.
499a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.comclass DeclarationContext {
509a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com public:
519a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com  DeclarationContext();
529a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com
539a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com  virtual ~DeclarationContext() {
549a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com    if (is_initialized_) {
55528ce02b8680a3ab6d75c7079f180a4016c69b7amachenbach@chromium.org      Isolate* isolate = CcTest::isolate();
56c118402c43ae44cf9255d36608a44886c98537c5jkummerow@chromium.org      HandleScope scope(isolate);
57c118402c43ae44cf9255d36608a44886c98537c5jkummerow@chromium.org      Local<Context> context = Local<Context>::New(isolate, context_);
58c118402c43ae44cf9255d36608a44886c98537c5jkummerow@chromium.org      context->Exit();
59f9841897146bc10dbb3c45f0632bb79254602c75machenbach@chromium.org      context_.Reset();
609a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com    }
619a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com  }
629a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com
639a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com  void Check(const char* source,
649a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com             int get, int set, int has,
659a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com             Expectations expectations,
669a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com             v8::Handle<Value> value = Local<Value>());
679a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com
689a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com  int get_count() const { return get_count_; }
699a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com  int set_count() const { return set_count_; }
701af7e1b5f676e5556c041fe09a5c4f5a906f27a0lrn@chromium.org  int query_count() const { return query_count_; }
719a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com
729a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com protected:
739a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com  virtual v8::Handle<Value> Get(Local<String> key);
749a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com  virtual v8::Handle<Value> Set(Local<String> key, Local<Value> value);
751af7e1b5f676e5556c041fe09a5c4f5a906f27a0lrn@chromium.org  virtual v8::Handle<Integer> Query(Local<String> key);
769a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com
779a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com  void InitializeIfNeeded();
789a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com
79de0db002768654f346a9059d80ab47602018bfa0yangguo@chromium.org  // Perform optional initialization steps on the context after it has
80de0db002768654f346a9059d80ab47602018bfa0yangguo@chromium.org  // been created. Defaults to none but may be overwritten.
81de0db002768654f346a9059d80ab47602018bfa0yangguo@chromium.org  virtual void PostInitializeContext(Handle<Context> context) {}
82de0db002768654f346a9059d80ab47602018bfa0yangguo@chromium.org
839a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com  // Get the holder for the interceptor. Default to the instance template
849a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com  // but may be overwritten.
859a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com  virtual Local<ObjectTemplate> GetHolder(Local<FunctionTemplate> function) {
869a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com    return function->InstanceTemplate();
879a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com  }
889a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com
899a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com  // The handlers are called as static functions that forward
909a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com  // to the instance specific virtual methods.
911510d58cbcf57c82a10e7d390bfe21a7ae68ba43mstarzinger@chromium.org  static void HandleGet(Local<String> key,
921510d58cbcf57c82a10e7d390bfe21a7ae68ba43mstarzinger@chromium.org                        const v8::PropertyCallbackInfo<v8::Value>& info);
931510d58cbcf57c82a10e7d390bfe21a7ae68ba43mstarzinger@chromium.org  static void HandleSet(Local<String> key,
941510d58cbcf57c82a10e7d390bfe21a7ae68ba43mstarzinger@chromium.org                        Local<Value> value,
951510d58cbcf57c82a10e7d390bfe21a7ae68ba43mstarzinger@chromium.org                        const v8::PropertyCallbackInfo<v8::Value>& info);
961510d58cbcf57c82a10e7d390bfe21a7ae68ba43mstarzinger@chromium.org  static void HandleQuery(Local<String> key,
971510d58cbcf57c82a10e7d390bfe21a7ae68ba43mstarzinger@chromium.org                          const v8::PropertyCallbackInfo<v8::Integer>& info);
989a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com
990f13e74b7310d8b14f19c6b93b36ff95059f97f6ulan@chromium.org  v8::Isolate* isolate() const { return CcTest::isolate(); }
1000f13e74b7310d8b14f19c6b93b36ff95059f97f6ulan@chromium.org
1019a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com private:
1029a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com  bool is_initialized_;
1039a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com  Persistent<Context> context_;
1049a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com
1059a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com  int get_count_;
1069a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com  int set_count_;
1071af7e1b5f676e5556c041fe09a5c4f5a906f27a0lrn@chromium.org  int query_count_;
1089a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com
1091510d58cbcf57c82a10e7d390bfe21a7ae68ba43mstarzinger@chromium.org  static DeclarationContext* GetInstance(Local<Value> data);
1109a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com};
1119a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com
1129a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com
1139a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.comDeclarationContext::DeclarationContext()
1141af7e1b5f676e5556c041fe09a5c4f5a906f27a0lrn@chromium.org    : is_initialized_(false), get_count_(0), set_count_(0), query_count_(0) {
1159a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com  // Do nothing.
1169a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com}
1179a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com
1189a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com
1199a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.comvoid DeclarationContext::InitializeIfNeeded() {
1209a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com  if (is_initialized_) return;
121528ce02b8680a3ab6d75c7079f180a4016c69b7amachenbach@chromium.org  Isolate* isolate = CcTest::isolate();
12257ff881caeb2e15b46ac9e4dfc00e378f7c5f929ulan@chromium.org  HandleScope scope(isolate);
1234f99be9ff2091451687891a05d99cc31990de709hpayer@chromium.org  Local<FunctionTemplate> function = FunctionTemplate::New(isolate);
1240cc095007a3ccded63f6577751c6a04300eb7ae9machenbach@chromium.org  Local<Value> data = External::New(CcTest::isolate(), this);
1259a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com  GetHolder(function)->SetNamedPropertyHandler(&HandleGet,
1269a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com                                               &HandleSet,
1271af7e1b5f676e5556c041fe09a5c4f5a906f27a0lrn@chromium.org                                               &HandleQuery,
1289a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com                                               0, 0,
1299a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com                                               data);
130c118402c43ae44cf9255d36608a44886c98537c5jkummerow@chromium.org  Local<Context> context = Context::New(isolate,
131c118402c43ae44cf9255d36608a44886c98537c5jkummerow@chromium.org                                        0,
132c118402c43ae44cf9255d36608a44886c98537c5jkummerow@chromium.org                                        function->InstanceTemplate(),
133c118402c43ae44cf9255d36608a44886c98537c5jkummerow@chromium.org                                        Local<Value>());
134c118402c43ae44cf9255d36608a44886c98537c5jkummerow@chromium.org  context_.Reset(isolate, context);
135c118402c43ae44cf9255d36608a44886c98537c5jkummerow@chromium.org  context->Enter();
1369a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com  is_initialized_ = true;
137c118402c43ae44cf9255d36608a44886c98537c5jkummerow@chromium.org  PostInitializeContext(context);
1389a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com}
1399a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com
1409a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com
1419a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.comvoid DeclarationContext::Check(const char* source,
1421af7e1b5f676e5556c041fe09a5c4f5a906f27a0lrn@chromium.org                               int get, int set, int query,
1439a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com                               Expectations expectations,
1449a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com                               v8::Handle<Value> value) {
1459a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com  InitializeIfNeeded();
1469a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com  // A retry after a GC may pollute the counts, so perform gc now
1479a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com  // to avoid that.
148528ce02b8680a3ab6d75c7079f180a4016c69b7amachenbach@chromium.org  CcTest::heap()->CollectGarbage(v8::internal::NEW_SPACE);
149528ce02b8680a3ab6d75c7079f180a4016c69b7amachenbach@chromium.org  HandleScope scope(CcTest::isolate());
1509a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com  TryCatch catcher;
1519a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com  catcher.SetVerbose(true);
152f9841897146bc10dbb3c45f0632bb79254602c75machenbach@chromium.org  Local<Script> script =
153f9841897146bc10dbb3c45f0632bb79254602c75machenbach@chromium.org      Script::Compile(String::NewFromUtf8(CcTest::isolate(), source));
15446839fbbdee40a3d2d924e8b5b13c4139b0b24f2yangguo@chromium.org  if (expectations == EXPECT_ERROR) {
15546839fbbdee40a3d2d924e8b5b13c4139b0b24f2yangguo@chromium.org    CHECK(script.IsEmpty());
15646839fbbdee40a3d2d924e8b5b13c4139b0b24f2yangguo@chromium.org    return;
15746839fbbdee40a3d2d924e8b5b13c4139b0b24f2yangguo@chromium.org  }
15846839fbbdee40a3d2d924e8b5b13c4139b0b24f2yangguo@chromium.org  CHECK(!script.IsEmpty());
15946839fbbdee40a3d2d924e8b5b13c4139b0b24f2yangguo@chromium.org  Local<Value> result = script->Run();
1609a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com  CHECK_EQ(get, get_count());
1619a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com  CHECK_EQ(set, set_count());
1621af7e1b5f676e5556c041fe09a5c4f5a906f27a0lrn@chromium.org  CHECK_EQ(query, query_count());
1639a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com  if (expectations == EXPECT_RESULT) {
1649a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com    CHECK(!catcher.HasCaught());
1659a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com    if (!value.IsEmpty()) {
1669a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com      CHECK_EQ(value, result);
1679a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com    }
1689a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com  } else {
1699a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com    CHECK(expectations == EXPECT_EXCEPTION);
1709a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com    CHECK(catcher.HasCaught());
1719a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com    if (!value.IsEmpty()) {
1729a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com      CHECK_EQ(value, catcher.Exception());
1739a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com    }
1749a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com  }
175528ce02b8680a3ab6d75c7079f180a4016c69b7amachenbach@chromium.org  // Clean slate for the next test.
176528ce02b8680a3ab6d75c7079f180a4016c69b7amachenbach@chromium.org  CcTest::heap()->CollectAllAvailableGarbage();
1779a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com}
1789a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com
1799a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com
1801510d58cbcf57c82a10e7d390bfe21a7ae68ba43mstarzinger@chromium.orgvoid DeclarationContext::HandleGet(
1811510d58cbcf57c82a10e7d390bfe21a7ae68ba43mstarzinger@chromium.org    Local<String> key,
1821510d58cbcf57c82a10e7d390bfe21a7ae68ba43mstarzinger@chromium.org    const v8::PropertyCallbackInfo<v8::Value>& info) {
1831510d58cbcf57c82a10e7d390bfe21a7ae68ba43mstarzinger@chromium.org  DeclarationContext* context = GetInstance(info.Data());
1849a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com  context->get_count_++;
1851510d58cbcf57c82a10e7d390bfe21a7ae68ba43mstarzinger@chromium.org  info.GetReturnValue().Set(context->Get(key));
1869a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com}
1879a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com
1889a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com
1891510d58cbcf57c82a10e7d390bfe21a7ae68ba43mstarzinger@chromium.orgvoid DeclarationContext::HandleSet(
1901510d58cbcf57c82a10e7d390bfe21a7ae68ba43mstarzinger@chromium.org    Local<String> key,
1911510d58cbcf57c82a10e7d390bfe21a7ae68ba43mstarzinger@chromium.org    Local<Value> value,
1921510d58cbcf57c82a10e7d390bfe21a7ae68ba43mstarzinger@chromium.org    const v8::PropertyCallbackInfo<v8::Value>& info) {
1931510d58cbcf57c82a10e7d390bfe21a7ae68ba43mstarzinger@chromium.org  DeclarationContext* context = GetInstance(info.Data());
1949a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com  context->set_count_++;
1951510d58cbcf57c82a10e7d390bfe21a7ae68ba43mstarzinger@chromium.org  info.GetReturnValue().Set(context->Set(key, value));
1969a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com}
1979a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com
1989a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com
1991510d58cbcf57c82a10e7d390bfe21a7ae68ba43mstarzinger@chromium.orgvoid DeclarationContext::HandleQuery(
2001510d58cbcf57c82a10e7d390bfe21a7ae68ba43mstarzinger@chromium.org    Local<String> key,
2011510d58cbcf57c82a10e7d390bfe21a7ae68ba43mstarzinger@chromium.org    const v8::PropertyCallbackInfo<v8::Integer>& info) {
2021510d58cbcf57c82a10e7d390bfe21a7ae68ba43mstarzinger@chromium.org  DeclarationContext* context = GetInstance(info.Data());
2031af7e1b5f676e5556c041fe09a5c4f5a906f27a0lrn@chromium.org  context->query_count_++;
2041510d58cbcf57c82a10e7d390bfe21a7ae68ba43mstarzinger@chromium.org  info.GetReturnValue().Set(context->Query(key));
2059a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com}
2069a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com
2079a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com
2081510d58cbcf57c82a10e7d390bfe21a7ae68ba43mstarzinger@chromium.orgDeclarationContext* DeclarationContext::GetInstance(Local<Value> data) {
2091510d58cbcf57c82a10e7d390bfe21a7ae68ba43mstarzinger@chromium.org  void* value = Local<External>::Cast(data)->Value();
210eeb44b681a16e45f1415dfacff0ba3dba9de5d8cyangguo@chromium.org  return static_cast<DeclarationContext*>(value);
2119a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com}
2129a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com
2139a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com
2149a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.comv8::Handle<Value> DeclarationContext::Get(Local<String> key) {
2159a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com  return v8::Handle<Value>();
2169a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com}
2179a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com
2189a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com
2199a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.comv8::Handle<Value> DeclarationContext::Set(Local<String> key,
2209a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com                                          Local<Value> value) {
2219a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com  return v8::Handle<Value>();
2229a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com}
2239a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com
2249a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com
2251af7e1b5f676e5556c041fe09a5c4f5a906f27a0lrn@chromium.orgv8::Handle<Integer> DeclarationContext::Query(Local<String> key) {
2261af7e1b5f676e5556c041fe09a5c4f5a906f27a0lrn@chromium.org  return v8::Handle<Integer>();
2279a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com}
2289a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com
2299a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com
2309a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com// Test global declaration of a property the interceptor doesn't know
2319a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com// about and doesn't handle.
2329a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.comTEST(Unknown) {
233528ce02b8680a3ab6d75c7079f180a4016c69b7amachenbach@chromium.org  HandleScope scope(CcTest::isolate());
234cfdf67d672b8e2cd6cc1df14c082671511745746machenbach@chromium.org  v8::V8::Initialize();
2359a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com
2369a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com  { DeclarationContext context;
2379a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com    context.Check("var x; x",
2389a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com                  1,  // access
2399a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com                  1,  // declaration
2409a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com                  2,  // declaration + initialization
241cfdf67d672b8e2cd6cc1df14c082671511745746machenbach@chromium.org                  EXPECT_RESULT, Undefined(CcTest::isolate()));
2429a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com  }
2439a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com
2449a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com  { DeclarationContext context;
2459a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com    context.Check("var x = 0; x",
2469a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com                  1,  // access
2479a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com                  2,  // declaration + initialization
2489a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com                  2,  // declaration + initialization
2490f13e74b7310d8b14f19c6b93b36ff95059f97f6ulan@chromium.org                  EXPECT_RESULT, Number::New(CcTest::isolate(), 0));
2509a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com  }
2519a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com
2529a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com  { DeclarationContext context;
2539a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com    context.Check("function x() { }; x",
2549a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com                  1,  // access
2553a5fd78f0ca6c2827bb05f69a373d152a9ce6ff3fschneider@chromium.org                  0,
2569a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com                  0,
2579a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com                  EXPECT_RESULT);
2589a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com  }
2599a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com
2609a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com  { DeclarationContext context;
2619a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com    context.Check("const x; x",
2629a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com                  1,  // access
2639a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com                  2,  // declaration + initialization
264c3b670ff19220959730d7886892bc4beb95d2ebaerik.corry@gmail.com                  1,  // declaration
265cfdf67d672b8e2cd6cc1df14c082671511745746machenbach@chromium.org                  EXPECT_RESULT, Undefined(CcTest::isolate()));
2669a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com  }
2679a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com
2689a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com  { DeclarationContext context;
269cfdf67d672b8e2cd6cc1df14c082671511745746machenbach@chromium.org    // SB 0 - BUG 1213579
2709a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com    context.Check("const x = 0; x",
2719a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com                  1,  // access
2729a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com                  2,  // declaration + initialization
273c3b670ff19220959730d7886892bc4beb95d2ebaerik.corry@gmail.com                  1,  // declaration
274cfdf67d672b8e2cd6cc1df14c082671511745746machenbach@chromium.org                  EXPECT_RESULT, Undefined(CcTest::isolate()));
2759a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com  }
2769a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com}
2779a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com
2789a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com
2799a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com
2809a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.comclass PresentPropertyContext: public DeclarationContext {
2819a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com protected:
2821af7e1b5f676e5556c041fe09a5c4f5a906f27a0lrn@chromium.org  virtual v8::Handle<Integer> Query(Local<String> key) {
2830f13e74b7310d8b14f19c6b93b36ff95059f97f6ulan@chromium.org    return Integer::New(isolate(), v8::None);
2849a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com  }
2859a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com};
2869a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com
2879a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com
2889a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com
2899a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.comTEST(Present) {
290528ce02b8680a3ab6d75c7079f180a4016c69b7amachenbach@chromium.org  HandleScope scope(CcTest::isolate());
2919a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com
2929a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com  { PresentPropertyContext context;
2939a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com    context.Check("var x; x",
2949a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com                  1,  // access
2959a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com                  0,
2969a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com                  2,  // declaration + initialization
2979a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com                  EXPECT_EXCEPTION);  // x is not defined!
2989a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com  }
2999a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com
3009a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com  { PresentPropertyContext context;
3019a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com    context.Check("var x = 0; x",
3029a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com                  1,  // access
3039a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com                  1,  // initialization
3049a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com                  2,  // declaration + initialization
3050f13e74b7310d8b14f19c6b93b36ff95059f97f6ulan@chromium.org                  EXPECT_RESULT, Number::New(CcTest::isolate(), 0));
3069a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com  }
3079a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com
3089a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com  { PresentPropertyContext context;
3099a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com    context.Check("function x() { }; x",
3109a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com                  1,  // access
3113a5fd78f0ca6c2827bb05f69a373d152a9ce6ff3fschneider@chromium.org                  0,
3129a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com                  0,
3139a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com                  EXPECT_RESULT);
3149a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com  }
3159a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com
3169a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com  { PresentPropertyContext context;
3179a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com    context.Check("const x; x",
318c3b670ff19220959730d7886892bc4beb95d2ebaerik.corry@gmail.com                  1,  // access
319c3b670ff19220959730d7886892bc4beb95d2ebaerik.corry@gmail.com                  1,  // initialization
3209a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com                  1,  // (re-)declaration
321cfdf67d672b8e2cd6cc1df14c082671511745746machenbach@chromium.org                  EXPECT_RESULT, Undefined(CcTest::isolate()));
3229a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com  }
3239a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com
3249a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com  { PresentPropertyContext context;
3259a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com    context.Check("const x = 0; x",
326c3b670ff19220959730d7886892bc4beb95d2ebaerik.corry@gmail.com                  1,  // access
327c3b670ff19220959730d7886892bc4beb95d2ebaerik.corry@gmail.com                  1,  // initialization
3289a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com                  1,  // (re-)declaration
3290f13e74b7310d8b14f19c6b93b36ff95059f97f6ulan@chromium.org                  EXPECT_RESULT, Number::New(CcTest::isolate(), 0));
3309a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com  }
3319a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com}
3329a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com
3339a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com
3349a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com
3359a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.comclass AbsentPropertyContext: public DeclarationContext {
3369a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com protected:
3371af7e1b5f676e5556c041fe09a5c4f5a906f27a0lrn@chromium.org  virtual v8::Handle<Integer> Query(Local<String> key) {
3381af7e1b5f676e5556c041fe09a5c4f5a906f27a0lrn@chromium.org    return v8::Handle<Integer>();
3399a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com  }
3409a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com};
3419a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com
3429a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com
3439a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.comTEST(Absent) {
344cfdf67d672b8e2cd6cc1df14c082671511745746machenbach@chromium.org  v8::Isolate* isolate = CcTest::isolate();
345cfdf67d672b8e2cd6cc1df14c082671511745746machenbach@chromium.org  v8::V8::Initialize();
346cfdf67d672b8e2cd6cc1df14c082671511745746machenbach@chromium.org  HandleScope scope(isolate);
3479a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com
3489a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com  { AbsentPropertyContext context;
3499a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com    context.Check("var x; x",
3509a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com                  1,  // access
3511af7e1b5f676e5556c041fe09a5c4f5a906f27a0lrn@chromium.org                  1,  // declaration
3529a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com                  2,  // declaration + initialization
353cfdf67d672b8e2cd6cc1df14c082671511745746machenbach@chromium.org                  EXPECT_RESULT, Undefined(isolate));
3549a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com  }
3559a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com
3569a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com  { AbsentPropertyContext context;
3579a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com    context.Check("var x = 0; x",
3589a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com                  1,  // access
3599a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com                  2,  // declaration + initialization
3609a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com                  2,  // declaration + initialization
3610f13e74b7310d8b14f19c6b93b36ff95059f97f6ulan@chromium.org                  EXPECT_RESULT, Number::New(isolate, 0));
3629a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com  }
3639a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com
3649a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com  { AbsentPropertyContext context;
3659a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com    context.Check("function x() { }; x",
3669a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com                  1,  // access
3673a5fd78f0ca6c2827bb05f69a373d152a9ce6ff3fschneider@chromium.org                  0,
3689a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com                  0,
3699a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com                  EXPECT_RESULT);
3709a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com  }
3719a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com
3729a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com  { AbsentPropertyContext context;
3739a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com    context.Check("const x; x",
3749a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com                  1,  // access
3759a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com                  2,  // declaration + initialization
376c3b670ff19220959730d7886892bc4beb95d2ebaerik.corry@gmail.com                  1,  // declaration
377cfdf67d672b8e2cd6cc1df14c082671511745746machenbach@chromium.org                  EXPECT_RESULT, Undefined(isolate));
3789a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com  }
3799a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com
3809a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com  { AbsentPropertyContext context;
3819a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com    context.Check("const x = 0; x",
3829a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com                  1,  // access
3839a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com                  2,  // declaration + initialization
384c3b670ff19220959730d7886892bc4beb95d2ebaerik.corry@gmail.com                  1,  // declaration
385cfdf67d672b8e2cd6cc1df14c082671511745746machenbach@chromium.org                  EXPECT_RESULT, Undefined(isolate));  // SB 0 - BUG 1213579
3869a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com  }
3879a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com
3889a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com  { AbsentPropertyContext context;
3899a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com    context.Check("if (false) { var x = 0 }; x",
3909a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com                  1,  // access
3919a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com                  1,  // declaration
3929a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com                  1,  // declaration + initialization
393cfdf67d672b8e2cd6cc1df14c082671511745746machenbach@chromium.org                  EXPECT_RESULT, Undefined(isolate));
3949a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com  }
3959a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com}
3969a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com
3979a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com
3989a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com
3999a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.comclass AppearingPropertyContext: public DeclarationContext {
4009a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com public:
4019a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com  enum State {
4029a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com    DECLARE,
4039a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com    INITIALIZE_IF_ASSIGN,
4049a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com    UNKNOWN
4059a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com  };
4069a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com
4079a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com  AppearingPropertyContext() : state_(DECLARE) { }
4089a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com
4099a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com protected:
4101af7e1b5f676e5556c041fe09a5c4f5a906f27a0lrn@chromium.org  virtual v8::Handle<Integer> Query(Local<String> key) {
4119a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com    switch (state_) {
4129a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com      case DECLARE:
4139a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com        // Force declaration by returning that the
4149a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com        // property is absent.
4159a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com        state_ = INITIALIZE_IF_ASSIGN;
4161af7e1b5f676e5556c041fe09a5c4f5a906f27a0lrn@chromium.org        return Handle<Integer>();
4179a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com      case INITIALIZE_IF_ASSIGN:
4189a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com        // Return that the property is present so we only get the
4199a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com        // setter called when initializing with a value.
4209a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com        state_ = UNKNOWN;
4210f13e74b7310d8b14f19c6b93b36ff95059f97f6ulan@chromium.org        return Integer::New(isolate(), v8::None);
4229a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com      default:
4233a37e9b96c768f6b5b6b09542e1cb1a1ece7a022ager@chromium.org        CHECK(state_ == UNKNOWN);
4249a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com        break;
4259a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com    }
4269a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com    // Do the lookup in the object.
4271af7e1b5f676e5556c041fe09a5c4f5a906f27a0lrn@chromium.org    return v8::Handle<Integer>();
4289a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com  }
4299a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com
4309a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com private:
4319a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com  State state_;
4329a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com};
4339a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com
4349a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com
4359a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.comTEST(Appearing) {
436cfdf67d672b8e2cd6cc1df14c082671511745746machenbach@chromium.org  v8::V8::Initialize();
437528ce02b8680a3ab6d75c7079f180a4016c69b7amachenbach@chromium.org  HandleScope scope(CcTest::isolate());
4389a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com
4399a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com  { AppearingPropertyContext context;
4409a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com    context.Check("var x; x",
4419a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com                  1,  // access
4429a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com                  1,  // declaration
4439a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com                  2,  // declaration + initialization
444cfdf67d672b8e2cd6cc1df14c082671511745746machenbach@chromium.org                  EXPECT_RESULT, Undefined(CcTest::isolate()));
4459a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com  }
4469a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com
4479a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com  { AppearingPropertyContext context;
4489a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com    context.Check("var x = 0; x",
4499a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com                  1,  // access
4509a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com                  2,  // declaration + initialization
4519a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com                  2,  // declaration + initialization
4520f13e74b7310d8b14f19c6b93b36ff95059f97f6ulan@chromium.org                  EXPECT_RESULT, Number::New(CcTest::isolate(), 0));
4539a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com  }
4549a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com
4559a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com  { AppearingPropertyContext context;
4569a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com    context.Check("function x() { }; x",
4579a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com                  1,  // access
4583a5fd78f0ca6c2827bb05f69a373d152a9ce6ff3fschneider@chromium.org                  0,
4599a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com                  0,
4609a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com                  EXPECT_RESULT);
4619a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com  }
4629a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com
4639a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com  { AppearingPropertyContext context;
4649a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com    context.Check("const x; x",
465c3b670ff19220959730d7886892bc4beb95d2ebaerik.corry@gmail.com                  1,  // access
4669a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com                  2,  // declaration + initialization
467c3b670ff19220959730d7886892bc4beb95d2ebaerik.corry@gmail.com                  1,  // declaration
468cfdf67d672b8e2cd6cc1df14c082671511745746machenbach@chromium.org                  EXPECT_RESULT, Undefined(CcTest::isolate()));
4699a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com  }
4709a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com
4719a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com  { AppearingPropertyContext context;
4729a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com    context.Check("const x = 0; x",
473c3b670ff19220959730d7886892bc4beb95d2ebaerik.corry@gmail.com                  1,  // access
4749a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com                  2,  // declaration + initialization
475c3b670ff19220959730d7886892bc4beb95d2ebaerik.corry@gmail.com                  1,  // declaration
476cfdf67d672b8e2cd6cc1df14c082671511745746machenbach@chromium.org                  EXPECT_RESULT, Undefined(CcTest::isolate()));
477c3b670ff19220959730d7886892bc4beb95d2ebaerik.corry@gmail.com                  // Result is undefined because declaration succeeded but
478c3b670ff19220959730d7886892bc4beb95d2ebaerik.corry@gmail.com                  // initialization to 0 failed (due to context behavior).
4799a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com  }
4809a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com}
4819a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com
4829a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com
4839a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com
4849a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.comclass ReappearingPropertyContext: public DeclarationContext {
4859a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com public:
4869a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com  enum State {
4879a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com    DECLARE,
4889a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com    DONT_DECLARE,
4899a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com    INITIALIZE,
4909a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com    UNKNOWN
4919a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com  };
4929a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com
4939a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com  ReappearingPropertyContext() : state_(DECLARE) { }
4949a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com
4959a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com protected:
4961af7e1b5f676e5556c041fe09a5c4f5a906f27a0lrn@chromium.org  virtual v8::Handle<Integer> Query(Local<String> key) {
4979a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com    switch (state_) {
4989a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com      case DECLARE:
4999a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com        // Force the first declaration by returning that
5009a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com        // the property is absent.
5019a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com        state_ = DONT_DECLARE;
5021af7e1b5f676e5556c041fe09a5c4f5a906f27a0lrn@chromium.org        return Handle<Integer>();
5039a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com      case DONT_DECLARE:
5049a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com        // Ignore the second declaration by returning
5059a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com        // that the property is already there.
5069a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com        state_ = INITIALIZE;
5070f13e74b7310d8b14f19c6b93b36ff95059f97f6ulan@chromium.org        return Integer::New(isolate(), v8::None);
5089a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com      case INITIALIZE:
5099a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com        // Force an initialization by returning that
5109a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com        // the property is absent. This will make sure
5119a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com        // that the setter is called and it will not
5129a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com        // lead to redeclaration conflicts (yet).
5139a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com        state_ = UNKNOWN;
5141af7e1b5f676e5556c041fe09a5c4f5a906f27a0lrn@chromium.org        return Handle<Integer>();
5159a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com      default:
5163a37e9b96c768f6b5b6b09542e1cb1a1ece7a022ager@chromium.org        CHECK(state_ == UNKNOWN);
5179a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com        break;
5189a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com    }
5199a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com    // Do the lookup in the object.
5201af7e1b5f676e5556c041fe09a5c4f5a906f27a0lrn@chromium.org    return Handle<Integer>();
5219a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com  }
5229a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com
5239a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com private:
5249a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com  State state_;
5259a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com};
5269a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com
5279a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com
5289a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.comTEST(Reappearing) {
529cfdf67d672b8e2cd6cc1df14c082671511745746machenbach@chromium.org  v8::V8::Initialize();
530528ce02b8680a3ab6d75c7079f180a4016c69b7amachenbach@chromium.org  HandleScope scope(CcTest::isolate());
5319a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com
5329a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com  { ReappearingPropertyContext context;
5339a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com    context.Check("const x; var x = 0",
5349a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com                  0,
535c3b670ff19220959730d7886892bc4beb95d2ebaerik.corry@gmail.com                  3,  // const declaration+initialization, var initialization
536c3b670ff19220959730d7886892bc4beb95d2ebaerik.corry@gmail.com                  3,  // 2 x declaration + var initialization
537cfdf67d672b8e2cd6cc1df14c082671511745746machenbach@chromium.org                  EXPECT_RESULT, Undefined(CcTest::isolate()));
5389a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com  }
5399a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com}
5409a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com
5419a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com
5429a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com
5439a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.comclass ExistsInPrototypeContext: public DeclarationContext {
5440f13e74b7310d8b14f19c6b93b36ff95059f97f6ulan@chromium.org public:
5450f13e74b7310d8b14f19c6b93b36ff95059f97f6ulan@chromium.org  ExistsInPrototypeContext() { InitializeIfNeeded(); }
5469a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com protected:
5471af7e1b5f676e5556c041fe09a5c4f5a906f27a0lrn@chromium.org  virtual v8::Handle<Integer> Query(Local<String> key) {
5489a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com    // Let it seem that the property exists in the prototype object.
5490f13e74b7310d8b14f19c6b93b36ff95059f97f6ulan@chromium.org    return Integer::New(isolate(), v8::None);
5509a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com  }
5519a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com
5529a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com  // Use the prototype as the holder for the interceptors.
5539a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com  virtual Local<ObjectTemplate> GetHolder(Local<FunctionTemplate> function) {
5549a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com    return function->PrototypeTemplate();
5559a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com  }
5569a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com};
5579a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com
5589a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com
5599a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.comTEST(ExistsInPrototype) {
560528ce02b8680a3ab6d75c7079f180a4016c69b7amachenbach@chromium.org  HandleScope scope(CcTest::isolate());
5619a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com
5629a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com  // Sanity check to make sure that the holder of the interceptor
5639a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com  // really is the prototype object.
5649a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com  { ExistsInPrototypeContext context;
5659a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com    context.Check("this.x = 87; this.x",
5669a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com                  0,
5679a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com                  0,
5689a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com                  0,
5690f13e74b7310d8b14f19c6b93b36ff95059f97f6ulan@chromium.org                  EXPECT_RESULT, Number::New(CcTest::isolate(), 87));
5709a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com  }
5719a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com
5729a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com  { ExistsInPrototypeContext context;
5739a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com    context.Check("var x; x",
5749a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com                  0,
575de0db002768654f346a9059d80ab47602018bfa0yangguo@chromium.org                  0,
576de0db002768654f346a9059d80ab47602018bfa0yangguo@chromium.org                  0,
577cfdf67d672b8e2cd6cc1df14c082671511745746machenbach@chromium.org                  EXPECT_RESULT, Undefined(CcTest::isolate()));
5789a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com  }
5799a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com
5809a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com  { ExistsInPrototypeContext context;
5819a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com    context.Check("var x = 0; x",
5829a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com                  0,
5839a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com                  0,
584de0db002768654f346a9059d80ab47602018bfa0yangguo@chromium.org                  0,
5850f13e74b7310d8b14f19c6b93b36ff95059f97f6ulan@chromium.org                  EXPECT_RESULT, Number::New(CcTest::isolate(), 0));
5869a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com  }
5879a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com
5889a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com  { ExistsInPrototypeContext context;
5899a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com    context.Check("const x; x",
5909a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com                  0,
5919a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com                  0,
592de0db002768654f346a9059d80ab47602018bfa0yangguo@chromium.org                  0,
593cfdf67d672b8e2cd6cc1df14c082671511745746machenbach@chromium.org                  EXPECT_RESULT, Undefined(CcTest::isolate()));
5949a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com  }
5959a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com
5969a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com  { ExistsInPrototypeContext context;
5979a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com    context.Check("const x = 0; x",
5989a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com                  0,
5999a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com                  0,
600de0db002768654f346a9059d80ab47602018bfa0yangguo@chromium.org                  0,
6010f13e74b7310d8b14f19c6b93b36ff95059f97f6ulan@chromium.org                  EXPECT_RESULT, Number::New(CcTest::isolate(), 0));
6029a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com  }
6039a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com}
6049a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com
6059a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com
6069a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com
6079a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.comclass AbsentInPrototypeContext: public DeclarationContext {
6089a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com protected:
6091af7e1b5f676e5556c041fe09a5c4f5a906f27a0lrn@chromium.org  virtual v8::Handle<Integer> Query(Local<String> key) {
6109a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com    // Let it seem that the property is absent in the prototype object.
6111af7e1b5f676e5556c041fe09a5c4f5a906f27a0lrn@chromium.org    return Handle<Integer>();
6129a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com  }
6139a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com
6149a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com  // Use the prototype as the holder for the interceptors.
6159a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com  virtual Local<ObjectTemplate> GetHolder(Local<FunctionTemplate> function) {
6169a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com    return function->PrototypeTemplate();
6179a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com  }
6189a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com};
6199a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com
6209a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com
6219a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.comTEST(AbsentInPrototype) {
622cfdf67d672b8e2cd6cc1df14c082671511745746machenbach@chromium.org  v8::V8::Initialize();
623528ce02b8680a3ab6d75c7079f180a4016c69b7amachenbach@chromium.org  HandleScope scope(CcTest::isolate());
6249a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com
6259a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com  { AbsentInPrototypeContext context;
6269a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com    context.Check("if (false) { var x = 0; }; x",
6279a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com                  0,
6289a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com                  0,
629de0db002768654f346a9059d80ab47602018bfa0yangguo@chromium.org                  0,
630cfdf67d672b8e2cd6cc1df14c082671511745746machenbach@chromium.org                  EXPECT_RESULT, Undefined(CcTest::isolate()));
6319a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com  }
6329a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.com}
633de0db002768654f346a9059d80ab47602018bfa0yangguo@chromium.org
634de0db002768654f346a9059d80ab47602018bfa0yangguo@chromium.org
635de0db002768654f346a9059d80ab47602018bfa0yangguo@chromium.org
636de0db002768654f346a9059d80ab47602018bfa0yangguo@chromium.orgclass ExistsInHiddenPrototypeContext: public DeclarationContext {
637de0db002768654f346a9059d80ab47602018bfa0yangguo@chromium.org public:
638de0db002768654f346a9059d80ab47602018bfa0yangguo@chromium.org  ExistsInHiddenPrototypeContext() {
6394f99be9ff2091451687891a05d99cc31990de709hpayer@chromium.org    hidden_proto_ = FunctionTemplate::New(CcTest::isolate());
640de0db002768654f346a9059d80ab47602018bfa0yangguo@chromium.org    hidden_proto_->SetHiddenPrototype(true);
641de0db002768654f346a9059d80ab47602018bfa0yangguo@chromium.org  }
642de0db002768654f346a9059d80ab47602018bfa0yangguo@chromium.org
643de0db002768654f346a9059d80ab47602018bfa0yangguo@chromium.org protected:
644de0db002768654f346a9059d80ab47602018bfa0yangguo@chromium.org  virtual v8::Handle<Integer> Query(Local<String> key) {
645de0db002768654f346a9059d80ab47602018bfa0yangguo@chromium.org    // Let it seem that the property exists in the hidden prototype object.
6460f13e74b7310d8b14f19c6b93b36ff95059f97f6ulan@chromium.org    return Integer::New(isolate(), v8::None);
647de0db002768654f346a9059d80ab47602018bfa0yangguo@chromium.org  }
648de0db002768654f346a9059d80ab47602018bfa0yangguo@chromium.org
649de0db002768654f346a9059d80ab47602018bfa0yangguo@chromium.org  // Install the hidden prototype after the global object has been created.
650de0db002768654f346a9059d80ab47602018bfa0yangguo@chromium.org  virtual void PostInitializeContext(Handle<Context> context) {
651de0db002768654f346a9059d80ab47602018bfa0yangguo@chromium.org    Local<Object> global_object = context->Global();
652de0db002768654f346a9059d80ab47602018bfa0yangguo@chromium.org    Local<Object> hidden_proto = hidden_proto_->GetFunction()->NewInstance();
653113035e2f19feb7032fbe57b2e3e376f1dfc4110jkummerow@chromium.org    Local<Object> inner_global =
654113035e2f19feb7032fbe57b2e3e376f1dfc4110jkummerow@chromium.org        Local<Object>::Cast(global_object->GetPrototype());
655113035e2f19feb7032fbe57b2e3e376f1dfc4110jkummerow@chromium.org    inner_global->SetPrototype(hidden_proto);
656de0db002768654f346a9059d80ab47602018bfa0yangguo@chromium.org  }
657de0db002768654f346a9059d80ab47602018bfa0yangguo@chromium.org
658de0db002768654f346a9059d80ab47602018bfa0yangguo@chromium.org  // Use the hidden prototype as the holder for the interceptors.
659de0db002768654f346a9059d80ab47602018bfa0yangguo@chromium.org  virtual Local<ObjectTemplate> GetHolder(Local<FunctionTemplate> function) {
660de0db002768654f346a9059d80ab47602018bfa0yangguo@chromium.org    return hidden_proto_->InstanceTemplate();
661de0db002768654f346a9059d80ab47602018bfa0yangguo@chromium.org  }
662de0db002768654f346a9059d80ab47602018bfa0yangguo@chromium.org
663de0db002768654f346a9059d80ab47602018bfa0yangguo@chromium.org private:
664de0db002768654f346a9059d80ab47602018bfa0yangguo@chromium.org  Local<FunctionTemplate> hidden_proto_;
665de0db002768654f346a9059d80ab47602018bfa0yangguo@chromium.org};
666de0db002768654f346a9059d80ab47602018bfa0yangguo@chromium.org
667de0db002768654f346a9059d80ab47602018bfa0yangguo@chromium.org
668de0db002768654f346a9059d80ab47602018bfa0yangguo@chromium.orgTEST(ExistsInHiddenPrototype) {
669528ce02b8680a3ab6d75c7079f180a4016c69b7amachenbach@chromium.org  HandleScope scope(CcTest::isolate());
670de0db002768654f346a9059d80ab47602018bfa0yangguo@chromium.org
671de0db002768654f346a9059d80ab47602018bfa0yangguo@chromium.org  { ExistsInHiddenPrototypeContext context;
672de0db002768654f346a9059d80ab47602018bfa0yangguo@chromium.org    context.Check("var x; x",
673de0db002768654f346a9059d80ab47602018bfa0yangguo@chromium.org                  1,  // access
674de0db002768654f346a9059d80ab47602018bfa0yangguo@chromium.org                  0,
675de0db002768654f346a9059d80ab47602018bfa0yangguo@chromium.org                  2,  // declaration + initialization
676de0db002768654f346a9059d80ab47602018bfa0yangguo@chromium.org                  EXPECT_EXCEPTION);  // x is not defined!
677de0db002768654f346a9059d80ab47602018bfa0yangguo@chromium.org  }
678de0db002768654f346a9059d80ab47602018bfa0yangguo@chromium.org
679de0db002768654f346a9059d80ab47602018bfa0yangguo@chromium.org  { ExistsInHiddenPrototypeContext context;
680de0db002768654f346a9059d80ab47602018bfa0yangguo@chromium.org    context.Check("var x = 0; x",
681de0db002768654f346a9059d80ab47602018bfa0yangguo@chromium.org                  1,  // access
682de0db002768654f346a9059d80ab47602018bfa0yangguo@chromium.org                  1,  // initialization
683de0db002768654f346a9059d80ab47602018bfa0yangguo@chromium.org                  2,  // declaration + initialization
6840f13e74b7310d8b14f19c6b93b36ff95059f97f6ulan@chromium.org                  EXPECT_RESULT, Number::New(CcTest::isolate(), 0));
685de0db002768654f346a9059d80ab47602018bfa0yangguo@chromium.org  }
686de0db002768654f346a9059d80ab47602018bfa0yangguo@chromium.org
687de0db002768654f346a9059d80ab47602018bfa0yangguo@chromium.org  { ExistsInHiddenPrototypeContext context;
688de0db002768654f346a9059d80ab47602018bfa0yangguo@chromium.org    context.Check("function x() { }; x",
689de0db002768654f346a9059d80ab47602018bfa0yangguo@chromium.org                  0,
690de0db002768654f346a9059d80ab47602018bfa0yangguo@chromium.org                  0,
691de0db002768654f346a9059d80ab47602018bfa0yangguo@chromium.org                  0,
692de0db002768654f346a9059d80ab47602018bfa0yangguo@chromium.org                  EXPECT_RESULT);
693de0db002768654f346a9059d80ab47602018bfa0yangguo@chromium.org  }
694de0db002768654f346a9059d80ab47602018bfa0yangguo@chromium.org
695de0db002768654f346a9059d80ab47602018bfa0yangguo@chromium.org  // TODO(mstarzinger): The semantics of global const is vague.
696de0db002768654f346a9059d80ab47602018bfa0yangguo@chromium.org  { ExistsInHiddenPrototypeContext context;
697de0db002768654f346a9059d80ab47602018bfa0yangguo@chromium.org    context.Check("const x; x",
698de0db002768654f346a9059d80ab47602018bfa0yangguo@chromium.org                  0,
699de0db002768654f346a9059d80ab47602018bfa0yangguo@chromium.org                  0,
700de0db002768654f346a9059d80ab47602018bfa0yangguo@chromium.org                  1,  // (re-)declaration
701cfdf67d672b8e2cd6cc1df14c082671511745746machenbach@chromium.org                  EXPECT_RESULT, Undefined(CcTest::isolate()));
702de0db002768654f346a9059d80ab47602018bfa0yangguo@chromium.org  }
703de0db002768654f346a9059d80ab47602018bfa0yangguo@chromium.org
704de0db002768654f346a9059d80ab47602018bfa0yangguo@chromium.org  // TODO(mstarzinger): The semantics of global const is vague.
705de0db002768654f346a9059d80ab47602018bfa0yangguo@chromium.org  { ExistsInHiddenPrototypeContext context;
706de0db002768654f346a9059d80ab47602018bfa0yangguo@chromium.org    context.Check("const x = 0; x",
707de0db002768654f346a9059d80ab47602018bfa0yangguo@chromium.org                  0,
708de0db002768654f346a9059d80ab47602018bfa0yangguo@chromium.org                  0,
709de0db002768654f346a9059d80ab47602018bfa0yangguo@chromium.org                  1,  // (re-)declaration
7100f13e74b7310d8b14f19c6b93b36ff95059f97f6ulan@chromium.org                  EXPECT_RESULT, Number::New(CcTest::isolate(), 0));
711de0db002768654f346a9059d80ab47602018bfa0yangguo@chromium.org  }
712de0db002768654f346a9059d80ab47602018bfa0yangguo@chromium.org}
71346839fbbdee40a3d2d924e8b5b13c4139b0b24f2yangguo@chromium.org
71446839fbbdee40a3d2d924e8b5b13c4139b0b24f2yangguo@chromium.org
71546839fbbdee40a3d2d924e8b5b13c4139b0b24f2yangguo@chromium.org
71646839fbbdee40a3d2d924e8b5b13c4139b0b24f2yangguo@chromium.orgclass SimpleContext {
71746839fbbdee40a3d2d924e8b5b13c4139b0b24f2yangguo@chromium.org public:
71857ff881caeb2e15b46ac9e4dfc00e378f7c5f929ulan@chromium.org  SimpleContext()
719528ce02b8680a3ab6d75c7079f180a4016c69b7amachenbach@chromium.org      : handle_scope_(CcTest::isolate()),
720528ce02b8680a3ab6d75c7079f180a4016c69b7amachenbach@chromium.org        context_(Context::New(CcTest::isolate())) {
72146839fbbdee40a3d2d924e8b5b13c4139b0b24f2yangguo@chromium.org    context_->Enter();
72246839fbbdee40a3d2d924e8b5b13c4139b0b24f2yangguo@chromium.org  }
72346839fbbdee40a3d2d924e8b5b13c4139b0b24f2yangguo@chromium.org
72457ff881caeb2e15b46ac9e4dfc00e378f7c5f929ulan@chromium.org  ~SimpleContext() {
72546839fbbdee40a3d2d924e8b5b13c4139b0b24f2yangguo@chromium.org    context_->Exit();
72646839fbbdee40a3d2d924e8b5b13c4139b0b24f2yangguo@chromium.org  }
72746839fbbdee40a3d2d924e8b5b13c4139b0b24f2yangguo@chromium.org
72846839fbbdee40a3d2d924e8b5b13c4139b0b24f2yangguo@chromium.org  void Check(const char* source,
72946839fbbdee40a3d2d924e8b5b13c4139b0b24f2yangguo@chromium.org             Expectations expectations,
73046839fbbdee40a3d2d924e8b5b13c4139b0b24f2yangguo@chromium.org             v8::Handle<Value> value = Local<Value>()) {
7312bda543d75374afd8d7e98f56ca99a57ae1b7bd1svenpanne@chromium.org    HandleScope scope(context_->GetIsolate());
73246839fbbdee40a3d2d924e8b5b13c4139b0b24f2yangguo@chromium.org    TryCatch catcher;
73346839fbbdee40a3d2d924e8b5b13c4139b0b24f2yangguo@chromium.org    catcher.SetVerbose(true);
734f9841897146bc10dbb3c45f0632bb79254602c75machenbach@chromium.org    Local<Script> script =
735f9841897146bc10dbb3c45f0632bb79254602c75machenbach@chromium.org        Script::Compile(String::NewFromUtf8(context_->GetIsolate(), source));
73646839fbbdee40a3d2d924e8b5b13c4139b0b24f2yangguo@chromium.org    if (expectations == EXPECT_ERROR) {
73746839fbbdee40a3d2d924e8b5b13c4139b0b24f2yangguo@chromium.org      CHECK(script.IsEmpty());
73846839fbbdee40a3d2d924e8b5b13c4139b0b24f2yangguo@chromium.org      return;
73946839fbbdee40a3d2d924e8b5b13c4139b0b24f2yangguo@chromium.org    }
74046839fbbdee40a3d2d924e8b5b13c4139b0b24f2yangguo@chromium.org    CHECK(!script.IsEmpty());
74146839fbbdee40a3d2d924e8b5b13c4139b0b24f2yangguo@chromium.org    Local<Value> result = script->Run();
74246839fbbdee40a3d2d924e8b5b13c4139b0b24f2yangguo@chromium.org    if (expectations == EXPECT_RESULT) {
74346839fbbdee40a3d2d924e8b5b13c4139b0b24f2yangguo@chromium.org      CHECK(!catcher.HasCaught());
74446839fbbdee40a3d2d924e8b5b13c4139b0b24f2yangguo@chromium.org      if (!value.IsEmpty()) {
74546839fbbdee40a3d2d924e8b5b13c4139b0b24f2yangguo@chromium.org        CHECK_EQ(value, result);
74646839fbbdee40a3d2d924e8b5b13c4139b0b24f2yangguo@chromium.org      }
74746839fbbdee40a3d2d924e8b5b13c4139b0b24f2yangguo@chromium.org    } else {
74846839fbbdee40a3d2d924e8b5b13c4139b0b24f2yangguo@chromium.org      CHECK(expectations == EXPECT_EXCEPTION);
74946839fbbdee40a3d2d924e8b5b13c4139b0b24f2yangguo@chromium.org      CHECK(catcher.HasCaught());
75046839fbbdee40a3d2d924e8b5b13c4139b0b24f2yangguo@chromium.org      if (!value.IsEmpty()) {
75146839fbbdee40a3d2d924e8b5b13c4139b0b24f2yangguo@chromium.org        CHECK_EQ(value, catcher.Exception());
75246839fbbdee40a3d2d924e8b5b13c4139b0b24f2yangguo@chromium.org      }
75346839fbbdee40a3d2d924e8b5b13c4139b0b24f2yangguo@chromium.org    }
75446839fbbdee40a3d2d924e8b5b13c4139b0b24f2yangguo@chromium.org  }
75546839fbbdee40a3d2d924e8b5b13c4139b0b24f2yangguo@chromium.org
75646839fbbdee40a3d2d924e8b5b13c4139b0b24f2yangguo@chromium.org private:
75757ff881caeb2e15b46ac9e4dfc00e378f7c5f929ulan@chromium.org  HandleScope handle_scope_;
75857ff881caeb2e15b46ac9e4dfc00e378f7c5f929ulan@chromium.org  Local<Context> context_;
75946839fbbdee40a3d2d924e8b5b13c4139b0b24f2yangguo@chromium.org};
76046839fbbdee40a3d2d924e8b5b13c4139b0b24f2yangguo@chromium.org
76146839fbbdee40a3d2d924e8b5b13c4139b0b24f2yangguo@chromium.org
7628e8d8825f97138de12985f8e0d3163074dff5258ulan@chromium.orgTEST(CrossScriptReferences) {
7630f13e74b7310d8b14f19c6b93b36ff95059f97f6ulan@chromium.org  v8::Isolate* isolate = CcTest::isolate();
7640f13e74b7310d8b14f19c6b93b36ff95059f97f6ulan@chromium.org  HandleScope scope(isolate);
76546839fbbdee40a3d2d924e8b5b13c4139b0b24f2yangguo@chromium.org
76646839fbbdee40a3d2d924e8b5b13c4139b0b24f2yangguo@chromium.org  { SimpleContext context;
76746839fbbdee40a3d2d924e8b5b13c4139b0b24f2yangguo@chromium.org    context.Check("var x = 1; x",
7680f13e74b7310d8b14f19c6b93b36ff95059f97f6ulan@chromium.org                  EXPECT_RESULT, Number::New(isolate, 1));
76946839fbbdee40a3d2d924e8b5b13c4139b0b24f2yangguo@chromium.org    context.Check("var x = 2; x",
7700f13e74b7310d8b14f19c6b93b36ff95059f97f6ulan@chromium.org                  EXPECT_RESULT, Number::New(isolate, 2));
77146839fbbdee40a3d2d924e8b5b13c4139b0b24f2yangguo@chromium.org    context.Check("const x = 3; x",
7720f13e74b7310d8b14f19c6b93b36ff95059f97f6ulan@chromium.org                  EXPECT_RESULT, Number::New(isolate, 3));
77346839fbbdee40a3d2d924e8b5b13c4139b0b24f2yangguo@chromium.org    context.Check("const x = 4; x",
7740f13e74b7310d8b14f19c6b93b36ff95059f97f6ulan@chromium.org                  EXPECT_RESULT, Number::New(isolate, 4));
77546839fbbdee40a3d2d924e8b5b13c4139b0b24f2yangguo@chromium.org    context.Check("x = 5; x",
7760f13e74b7310d8b14f19c6b93b36ff95059f97f6ulan@chromium.org                  EXPECT_RESULT, Number::New(isolate, 5));
77746839fbbdee40a3d2d924e8b5b13c4139b0b24f2yangguo@chromium.org    context.Check("var x = 6; x",
7780f13e74b7310d8b14f19c6b93b36ff95059f97f6ulan@chromium.org                  EXPECT_RESULT, Number::New(isolate, 6));
77946839fbbdee40a3d2d924e8b5b13c4139b0b24f2yangguo@chromium.org    context.Check("this.x",
7800f13e74b7310d8b14f19c6b93b36ff95059f97f6ulan@chromium.org                  EXPECT_RESULT, Number::New(isolate, 6));
78146839fbbdee40a3d2d924e8b5b13c4139b0b24f2yangguo@chromium.org    context.Check("function x() { return 7 }; x()",
7820f13e74b7310d8b14f19c6b93b36ff95059f97f6ulan@chromium.org                  EXPECT_RESULT, Number::New(isolate, 7));
78346839fbbdee40a3d2d924e8b5b13c4139b0b24f2yangguo@chromium.org  }
78446839fbbdee40a3d2d924e8b5b13c4139b0b24f2yangguo@chromium.org
78546839fbbdee40a3d2d924e8b5b13c4139b0b24f2yangguo@chromium.org  { SimpleContext context;
78646839fbbdee40a3d2d924e8b5b13c4139b0b24f2yangguo@chromium.org    context.Check("const x = 1; x",
7870f13e74b7310d8b14f19c6b93b36ff95059f97f6ulan@chromium.org                  EXPECT_RESULT, Number::New(isolate, 1));
78846839fbbdee40a3d2d924e8b5b13c4139b0b24f2yangguo@chromium.org    context.Check("var x = 2; x",  // assignment ignored
7890f13e74b7310d8b14f19c6b93b36ff95059f97f6ulan@chromium.org                  EXPECT_RESULT, Number::New(isolate, 1));
79046839fbbdee40a3d2d924e8b5b13c4139b0b24f2yangguo@chromium.org    context.Check("const x = 3; x",
7910f13e74b7310d8b14f19c6b93b36ff95059f97f6ulan@chromium.org                  EXPECT_RESULT, Number::New(isolate, 1));
79246839fbbdee40a3d2d924e8b5b13c4139b0b24f2yangguo@chromium.org    context.Check("x = 4; x",  // assignment ignored
7930f13e74b7310d8b14f19c6b93b36ff95059f97f6ulan@chromium.org                  EXPECT_RESULT, Number::New(isolate, 1));
79446839fbbdee40a3d2d924e8b5b13c4139b0b24f2yangguo@chromium.org    context.Check("var x = 5; x",  // assignment ignored
7950f13e74b7310d8b14f19c6b93b36ff95059f97f6ulan@chromium.org                  EXPECT_RESULT, Number::New(isolate, 1));
79646839fbbdee40a3d2d924e8b5b13c4139b0b24f2yangguo@chromium.org    context.Check("this.x",
7970f13e74b7310d8b14f19c6b93b36ff95059f97f6ulan@chromium.org                  EXPECT_RESULT, Number::New(isolate, 1));
79846839fbbdee40a3d2d924e8b5b13c4139b0b24f2yangguo@chromium.org    context.Check("function x() { return 7 }; x",
79946839fbbdee40a3d2d924e8b5b13c4139b0b24f2yangguo@chromium.org                  EXPECT_EXCEPTION);
80046839fbbdee40a3d2d924e8b5b13c4139b0b24f2yangguo@chromium.org  }
8018e8d8825f97138de12985f8e0d3163074dff5258ulan@chromium.org}
8028e8d8825f97138de12985f8e0d3163074dff5258ulan@chromium.org
80346839fbbdee40a3d2d924e8b5b13c4139b0b24f2yangguo@chromium.org
8048e8d8825f97138de12985f8e0d3163074dff5258ulan@chromium.orgTEST(CrossScriptReferencesHarmony) {
80546839fbbdee40a3d2d924e8b5b13c4139b0b24f2yangguo@chromium.org  i::FLAG_use_strict = true;
80646839fbbdee40a3d2d924e8b5b13c4139b0b24f2yangguo@chromium.org  i::FLAG_harmony_scoping = true;
8078e8d8825f97138de12985f8e0d3163074dff5258ulan@chromium.org  i::FLAG_harmony_modules = true;
80846839fbbdee40a3d2d924e8b5b13c4139b0b24f2yangguo@chromium.org
8090f13e74b7310d8b14f19c6b93b36ff95059f97f6ulan@chromium.org  v8::Isolate* isolate = CcTest::isolate();
8100f13e74b7310d8b14f19c6b93b36ff95059f97f6ulan@chromium.org  HandleScope scope(isolate);
811355cfd19c23ac613f2738a40e356ea48297f7d5eyangguo@chromium.org
8128e8d8825f97138de12985f8e0d3163074dff5258ulan@chromium.org  const char* decs[] = {
8138e8d8825f97138de12985f8e0d3163074dff5258ulan@chromium.org    "var x = 1; x", "x", "this.x",
8148e8d8825f97138de12985f8e0d3163074dff5258ulan@chromium.org    "function x() { return 1 }; x()", "x()", "this.x()",
8158e8d8825f97138de12985f8e0d3163074dff5258ulan@chromium.org    "let x = 1; x", "x", "this.x",
8168e8d8825f97138de12985f8e0d3163074dff5258ulan@chromium.org    "const x = 1; x", "x", "this.x",
8178e8d8825f97138de12985f8e0d3163074dff5258ulan@chromium.org    "module x { export let a = 1 }; x.a", "x.a", "this.x.a",
8188e8d8825f97138de12985f8e0d3163074dff5258ulan@chromium.org    NULL
8198e8d8825f97138de12985f8e0d3163074dff5258ulan@chromium.org  };
82046839fbbdee40a3d2d924e8b5b13c4139b0b24f2yangguo@chromium.org
8218e8d8825f97138de12985f8e0d3163074dff5258ulan@chromium.org  for (int i = 0; decs[i] != NULL; i += 3) {
8228e8d8825f97138de12985f8e0d3163074dff5258ulan@chromium.org    SimpleContext context;
8230f13e74b7310d8b14f19c6b93b36ff95059f97f6ulan@chromium.org    context.Check(decs[i], EXPECT_RESULT, Number::New(isolate, 1));
8240f13e74b7310d8b14f19c6b93b36ff95059f97f6ulan@chromium.org    context.Check(decs[i+1], EXPECT_RESULT, Number::New(isolate, 1));
825355cfd19c23ac613f2738a40e356ea48297f7d5eyangguo@chromium.org    // TODO(rossberg): The current ES6 draft spec does not reflect lexical
826355cfd19c23ac613f2738a40e356ea48297f7d5eyangguo@chromium.org    // bindings on the global object. However, this will probably change, in
827355cfd19c23ac613f2738a40e356ea48297f7d5eyangguo@chromium.org    // which case we reactivate the following test.
8280f13e74b7310d8b14f19c6b93b36ff95059f97f6ulan@chromium.org    if (i/3 < 2) {
8290f13e74b7310d8b14f19c6b93b36ff95059f97f6ulan@chromium.org      context.Check(decs[i+2], EXPECT_RESULT, Number::New(isolate, 1));
8300f13e74b7310d8b14f19c6b93b36ff95059f97f6ulan@chromium.org    }
83146839fbbdee40a3d2d924e8b5b13c4139b0b24f2yangguo@chromium.org  }
8328e8d8825f97138de12985f8e0d3163074dff5258ulan@chromium.org}
83346839fbbdee40a3d2d924e8b5b13c4139b0b24f2yangguo@chromium.org
83446839fbbdee40a3d2d924e8b5b13c4139b0b24f2yangguo@chromium.org
8358e8d8825f97138de12985f8e0d3163074dff5258ulan@chromium.orgTEST(CrossScriptConflicts) {
8368e8d8825f97138de12985f8e0d3163074dff5258ulan@chromium.org  i::FLAG_use_strict = true;
8378e8d8825f97138de12985f8e0d3163074dff5258ulan@chromium.org  i::FLAG_harmony_scoping = true;
8388e8d8825f97138de12985f8e0d3163074dff5258ulan@chromium.org  i::FLAG_harmony_modules = true;
83946839fbbdee40a3d2d924e8b5b13c4139b0b24f2yangguo@chromium.org
840528ce02b8680a3ab6d75c7079f180a4016c69b7amachenbach@chromium.org  HandleScope scope(CcTest::isolate());
84146839fbbdee40a3d2d924e8b5b13c4139b0b24f2yangguo@chromium.org
8428e8d8825f97138de12985f8e0d3163074dff5258ulan@chromium.org  const char* firsts[] = {
8438e8d8825f97138de12985f8e0d3163074dff5258ulan@chromium.org    "var x = 1; x",
8448e8d8825f97138de12985f8e0d3163074dff5258ulan@chromium.org    "function x() { return 1 }; x()",
8458e8d8825f97138de12985f8e0d3163074dff5258ulan@chromium.org    "let x = 1; x",
8468e8d8825f97138de12985f8e0d3163074dff5258ulan@chromium.org    "const x = 1; x",
8478e8d8825f97138de12985f8e0d3163074dff5258ulan@chromium.org    "module x { export let a = 1 }; x.a",
8488e8d8825f97138de12985f8e0d3163074dff5258ulan@chromium.org    NULL
8498e8d8825f97138de12985f8e0d3163074dff5258ulan@chromium.org  };
8508e8d8825f97138de12985f8e0d3163074dff5258ulan@chromium.org  const char* seconds[] = {
8518e8d8825f97138de12985f8e0d3163074dff5258ulan@chromium.org    "var x = 2; x",
8528e8d8825f97138de12985f8e0d3163074dff5258ulan@chromium.org    "function x() { return 2 }; x()",
8538e8d8825f97138de12985f8e0d3163074dff5258ulan@chromium.org    "let x = 2; x",
8548e8d8825f97138de12985f8e0d3163074dff5258ulan@chromium.org    "const x = 2; x",
8558e8d8825f97138de12985f8e0d3163074dff5258ulan@chromium.org    "module x { export let a = 2 }; x.a",
8568e8d8825f97138de12985f8e0d3163074dff5258ulan@chromium.org    NULL
8578e8d8825f97138de12985f8e0d3163074dff5258ulan@chromium.org  };
85846839fbbdee40a3d2d924e8b5b13c4139b0b24f2yangguo@chromium.org
8598e8d8825f97138de12985f8e0d3163074dff5258ulan@chromium.org  for (int i = 0; firsts[i] != NULL; ++i) {
8608e8d8825f97138de12985f8e0d3163074dff5258ulan@chromium.org    for (int j = 0; seconds[j] != NULL; ++j) {
8618e8d8825f97138de12985f8e0d3163074dff5258ulan@chromium.org      SimpleContext context;
8620f13e74b7310d8b14f19c6b93b36ff95059f97f6ulan@chromium.org      context.Check(firsts[i], EXPECT_RESULT,
8630f13e74b7310d8b14f19c6b93b36ff95059f97f6ulan@chromium.org                    Number::New(CcTest::isolate(), 1));
8648e8d8825f97138de12985f8e0d3163074dff5258ulan@chromium.org      // TODO(rossberg): All tests should actually be errors in Harmony,
8658e8d8825f97138de12985f8e0d3163074dff5258ulan@chromium.org      // but we currently do not detect the cases where the first declaration
8668e8d8825f97138de12985f8e0d3163074dff5258ulan@chromium.org      // is not lexical.
8678e8d8825f97138de12985f8e0d3163074dff5258ulan@chromium.org      context.Check(seconds[j],
8680f13e74b7310d8b14f19c6b93b36ff95059f97f6ulan@chromium.org                    i < 2 ? EXPECT_RESULT : EXPECT_ERROR,
8690f13e74b7310d8b14f19c6b93b36ff95059f97f6ulan@chromium.org                    Number::New(CcTest::isolate(), 2));
8708e8d8825f97138de12985f8e0d3163074dff5258ulan@chromium.org    }
87146839fbbdee40a3d2d924e8b5b13c4139b0b24f2yangguo@chromium.org  }
87246839fbbdee40a3d2d924e8b5b13c4139b0b24f2yangguo@chromium.org}
873