| OLD | NEW | 
|    1 // Copyright 2007-2008 the V8 project authors. All rights reserved. |    1 // Copyright 2007-2008 the V8 project authors. All rights reserved. | 
|    2 // Redistribution and use in source and binary forms, with or without |    2 // Redistribution and use in source and binary forms, with or without | 
|    3 // modification, are permitted provided that the following conditions are |    3 // modification, are permitted provided that the following conditions are | 
|    4 // met: |    4 // met: | 
|    5 // |    5 // | 
|    6 //     * Redistributions of source code must retain the above copyright |    6 //     * Redistributions of source code must retain the above copyright | 
|    7 //       notice, this list of conditions and the following disclaimer. |    7 //       notice, this list of conditions and the following disclaimer. | 
|    8 //     * Redistributions in binary form must reproduce the above |    8 //     * Redistributions in binary form must reproduce the above | 
|    9 //       copyright notice, this list of conditions and the following |    9 //       copyright notice, this list of conditions and the following | 
|   10 //       disclaimer in the documentation and/or other materials provided |   10 //       disclaimer in the documentation and/or other materials provided | 
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|   89   // The handlers are called as static functions that forward |   89   // The handlers are called as static functions that forward | 
|   90   // to the instance specific virtual methods. |   90   // to the instance specific virtual methods. | 
|   91   static void HandleGet(Local<String> key, |   91   static void HandleGet(Local<String> key, | 
|   92                         const v8::PropertyCallbackInfo<v8::Value>& info); |   92                         const v8::PropertyCallbackInfo<v8::Value>& info); | 
|   93   static void HandleSet(Local<String> key, |   93   static void HandleSet(Local<String> key, | 
|   94                         Local<Value> value, |   94                         Local<Value> value, | 
|   95                         const v8::PropertyCallbackInfo<v8::Value>& info); |   95                         const v8::PropertyCallbackInfo<v8::Value>& info); | 
|   96   static void HandleQuery(Local<String> key, |   96   static void HandleQuery(Local<String> key, | 
|   97                           const v8::PropertyCallbackInfo<v8::Integer>& info); |   97                           const v8::PropertyCallbackInfo<v8::Integer>& info); | 
|   98  |   98  | 
 |   99   v8::Isolate* isolate() const { return CcTest::isolate(); } | 
 |  100  | 
|   99  private: |  101  private: | 
|  100   bool is_initialized_; |  102   bool is_initialized_; | 
|  101   Persistent<Context> context_; |  103   Persistent<Context> context_; | 
|  102  |  104  | 
|  103   int get_count_; |  105   int get_count_; | 
|  104   int set_count_; |  106   int set_count_; | 
|  105   int query_count_; |  107   int query_count_; | 
|  106  |  108  | 
|  107   static DeclarationContext* GetInstance(Local<Value> data); |  109   static DeclarationContext* GetInstance(Local<Value> data); | 
|  108 }; |  110 }; | 
| (...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  237                   1,  // declaration |  239                   1,  // declaration | 
|  238                   2,  // declaration + initialization |  240                   2,  // declaration + initialization | 
|  239                   EXPECT_RESULT, Undefined(CcTest::isolate())); |  241                   EXPECT_RESULT, Undefined(CcTest::isolate())); | 
|  240   } |  242   } | 
|  241  |  243  | 
|  242   { DeclarationContext context; |  244   { DeclarationContext context; | 
|  243     context.Check("var x = 0; x", |  245     context.Check("var x = 0; x", | 
|  244                   1,  // access |  246                   1,  // access | 
|  245                   2,  // declaration + initialization |  247                   2,  // declaration + initialization | 
|  246                   2,  // declaration + initialization |  248                   2,  // declaration + initialization | 
|  247                   EXPECT_RESULT, Number::New(0)); |  249                   EXPECT_RESULT, Number::New(CcTest::isolate(), 0)); | 
|  248   } |  250   } | 
|  249  |  251  | 
|  250   { DeclarationContext context; |  252   { DeclarationContext context; | 
|  251     context.Check("function x() { }; x", |  253     context.Check("function x() { }; x", | 
|  252                   1,  // access |  254                   1,  // access | 
|  253                   0, |  255                   0, | 
|  254                   0, |  256                   0, | 
|  255                   EXPECT_RESULT); |  257                   EXPECT_RESULT); | 
|  256   } |  258   } | 
|  257  |  259  | 
| (...skipping 13 matching lines...) Expand all  Loading... | 
|  271                   1,  // declaration |  273                   1,  // declaration | 
|  272                   EXPECT_RESULT, Undefined(CcTest::isolate())); |  274                   EXPECT_RESULT, Undefined(CcTest::isolate())); | 
|  273   } |  275   } | 
|  274 } |  276 } | 
|  275  |  277  | 
|  276  |  278  | 
|  277  |  279  | 
|  278 class PresentPropertyContext: public DeclarationContext { |  280 class PresentPropertyContext: public DeclarationContext { | 
|  279  protected: |  281  protected: | 
|  280   virtual v8::Handle<Integer> Query(Local<String> key) { |  282   virtual v8::Handle<Integer> Query(Local<String> key) { | 
|  281     return Integer::New(v8::None); |  283     return Integer::New(isolate(), v8::None); | 
|  282   } |  284   } | 
|  283 }; |  285 }; | 
|  284  |  286  | 
|  285  |  287  | 
|  286  |  288  | 
|  287 TEST(Present) { |  289 TEST(Present) { | 
|  288   HandleScope scope(CcTest::isolate()); |  290   HandleScope scope(CcTest::isolate()); | 
|  289  |  291  | 
|  290   { PresentPropertyContext context; |  292   { PresentPropertyContext context; | 
|  291     context.Check("var x; x", |  293     context.Check("var x; x", | 
|  292                   1,  // access |  294                   1,  // access | 
|  293                   0, |  295                   0, | 
|  294                   2,  // declaration + initialization |  296                   2,  // declaration + initialization | 
|  295                   EXPECT_EXCEPTION);  // x is not defined! |  297                   EXPECT_EXCEPTION);  // x is not defined! | 
|  296   } |  298   } | 
|  297  |  299  | 
|  298   { PresentPropertyContext context; |  300   { PresentPropertyContext context; | 
|  299     context.Check("var x = 0; x", |  301     context.Check("var x = 0; x", | 
|  300                   1,  // access |  302                   1,  // access | 
|  301                   1,  // initialization |  303                   1,  // initialization | 
|  302                   2,  // declaration + initialization |  304                   2,  // declaration + initialization | 
|  303                   EXPECT_RESULT, Number::New(0)); |  305                   EXPECT_RESULT, Number::New(CcTest::isolate(), 0)); | 
|  304   } |  306   } | 
|  305  |  307  | 
|  306   { PresentPropertyContext context; |  308   { PresentPropertyContext context; | 
|  307     context.Check("function x() { }; x", |  309     context.Check("function x() { }; x", | 
|  308                   1,  // access |  310                   1,  // access | 
|  309                   0, |  311                   0, | 
|  310                   0, |  312                   0, | 
|  311                   EXPECT_RESULT); |  313                   EXPECT_RESULT); | 
|  312   } |  314   } | 
|  313  |  315  | 
|  314   { PresentPropertyContext context; |  316   { PresentPropertyContext context; | 
|  315     context.Check("const x; x", |  317     context.Check("const x; x", | 
|  316                   1,  // access |  318                   1,  // access | 
|  317                   1,  // initialization |  319                   1,  // initialization | 
|  318                   1,  // (re-)declaration |  320                   1,  // (re-)declaration | 
|  319                   EXPECT_RESULT, Undefined(CcTest::isolate())); |  321                   EXPECT_RESULT, Undefined(CcTest::isolate())); | 
|  320   } |  322   } | 
|  321  |  323  | 
|  322   { PresentPropertyContext context; |  324   { PresentPropertyContext context; | 
|  323     context.Check("const x = 0; x", |  325     context.Check("const x = 0; x", | 
|  324                   1,  // access |  326                   1,  // access | 
|  325                   1,  // initialization |  327                   1,  // initialization | 
|  326                   1,  // (re-)declaration |  328                   1,  // (re-)declaration | 
|  327                   EXPECT_RESULT, Number::New(0)); |  329                   EXPECT_RESULT, Number::New(CcTest::isolate(), 0)); | 
|  328   } |  330   } | 
|  329 } |  331 } | 
|  330  |  332  | 
|  331  |  333  | 
|  332  |  334  | 
|  333 class AbsentPropertyContext: public DeclarationContext { |  335 class AbsentPropertyContext: public DeclarationContext { | 
|  334  protected: |  336  protected: | 
|  335   virtual v8::Handle<Integer> Query(Local<String> key) { |  337   virtual v8::Handle<Integer> Query(Local<String> key) { | 
|  336     return v8::Handle<Integer>(); |  338     return v8::Handle<Integer>(); | 
|  337   } |  339   } | 
| (...skipping 11 matching lines...) Expand all  Loading... | 
|  349                   1,  // declaration |  351                   1,  // declaration | 
|  350                   2,  // declaration + initialization |  352                   2,  // declaration + initialization | 
|  351                   EXPECT_RESULT, Undefined(isolate)); |  353                   EXPECT_RESULT, Undefined(isolate)); | 
|  352   } |  354   } | 
|  353  |  355  | 
|  354   { AbsentPropertyContext context; |  356   { AbsentPropertyContext context; | 
|  355     context.Check("var x = 0; x", |  357     context.Check("var x = 0; x", | 
|  356                   1,  // access |  358                   1,  // access | 
|  357                   2,  // declaration + initialization |  359                   2,  // declaration + initialization | 
|  358                   2,  // declaration + initialization |  360                   2,  // declaration + initialization | 
|  359                   EXPECT_RESULT, Number::New(0)); |  361                   EXPECT_RESULT, Number::New(isolate, 0)); | 
|  360   } |  362   } | 
|  361  |  363  | 
|  362   { AbsentPropertyContext context; |  364   { AbsentPropertyContext context; | 
|  363     context.Check("function x() { }; x", |  365     context.Check("function x() { }; x", | 
|  364                   1,  // access |  366                   1,  // access | 
|  365                   0, |  367                   0, | 
|  366                   0, |  368                   0, | 
|  367                   EXPECT_RESULT); |  369                   EXPECT_RESULT); | 
|  368   } |  370   } | 
|  369  |  371  | 
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  409     switch (state_) { |  411     switch (state_) { | 
|  410       case DECLARE: |  412       case DECLARE: | 
|  411         // Force declaration by returning that the |  413         // Force declaration by returning that the | 
|  412         // property is absent. |  414         // property is absent. | 
|  413         state_ = INITIALIZE_IF_ASSIGN; |  415         state_ = INITIALIZE_IF_ASSIGN; | 
|  414         return Handle<Integer>(); |  416         return Handle<Integer>(); | 
|  415       case INITIALIZE_IF_ASSIGN: |  417       case INITIALIZE_IF_ASSIGN: | 
|  416         // Return that the property is present so we only get the |  418         // Return that the property is present so we only get the | 
|  417         // setter called when initializing with a value. |  419         // setter called when initializing with a value. | 
|  418         state_ = UNKNOWN; |  420         state_ = UNKNOWN; | 
|  419         return Integer::New(v8::None); |  421         return Integer::New(isolate(), v8::None); | 
|  420       default: |  422       default: | 
|  421         CHECK(state_ == UNKNOWN); |  423         CHECK(state_ == UNKNOWN); | 
|  422         break; |  424         break; | 
|  423     } |  425     } | 
|  424     // Do the lookup in the object. |  426     // Do the lookup in the object. | 
|  425     return v8::Handle<Integer>(); |  427     return v8::Handle<Integer>(); | 
|  426   } |  428   } | 
|  427  |  429  | 
|  428  private: |  430  private: | 
|  429   State state_; |  431   State state_; | 
| (...skipping 10 matching lines...) Expand all  Loading... | 
|  440                   1,  // declaration |  442                   1,  // declaration | 
|  441                   2,  // declaration + initialization |  443                   2,  // declaration + initialization | 
|  442                   EXPECT_RESULT, Undefined(CcTest::isolate())); |  444                   EXPECT_RESULT, Undefined(CcTest::isolate())); | 
|  443   } |  445   } | 
|  444  |  446  | 
|  445   { AppearingPropertyContext context; |  447   { AppearingPropertyContext context; | 
|  446     context.Check("var x = 0; x", |  448     context.Check("var x = 0; x", | 
|  447                   1,  // access |  449                   1,  // access | 
|  448                   2,  // declaration + initialization |  450                   2,  // declaration + initialization | 
|  449                   2,  // declaration + initialization |  451                   2,  // declaration + initialization | 
|  450                   EXPECT_RESULT, Number::New(0)); |  452                   EXPECT_RESULT, Number::New(CcTest::isolate(), 0)); | 
|  451   } |  453   } | 
|  452  |  454  | 
|  453   { AppearingPropertyContext context; |  455   { AppearingPropertyContext context; | 
|  454     context.Check("function x() { }; x", |  456     context.Check("function x() { }; x", | 
|  455                   1,  // access |  457                   1,  // access | 
|  456                   0, |  458                   0, | 
|  457                   0, |  459                   0, | 
|  458                   EXPECT_RESULT); |  460                   EXPECT_RESULT); | 
|  459   } |  461   } | 
|  460  |  462  | 
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  495     switch (state_) { |  497     switch (state_) { | 
|  496       case DECLARE: |  498       case DECLARE: | 
|  497         // Force the first declaration by returning that |  499         // Force the first declaration by returning that | 
|  498         // the property is absent. |  500         // the property is absent. | 
|  499         state_ = DONT_DECLARE; |  501         state_ = DONT_DECLARE; | 
|  500         return Handle<Integer>(); |  502         return Handle<Integer>(); | 
|  501       case DONT_DECLARE: |  503       case DONT_DECLARE: | 
|  502         // Ignore the second declaration by returning |  504         // Ignore the second declaration by returning | 
|  503         // that the property is already there. |  505         // that the property is already there. | 
|  504         state_ = INITIALIZE; |  506         state_ = INITIALIZE; | 
|  505         return Integer::New(v8::None); |  507         return Integer::New(isolate(), v8::None); | 
|  506       case INITIALIZE: |  508       case INITIALIZE: | 
|  507         // Force an initialization by returning that |  509         // Force an initialization by returning that | 
|  508         // the property is absent. This will make sure |  510         // the property is absent. This will make sure | 
|  509         // that the setter is called and it will not |  511         // that the setter is called and it will not | 
|  510         // lead to redeclaration conflicts (yet). |  512         // lead to redeclaration conflicts (yet). | 
|  511         state_ = UNKNOWN; |  513         state_ = UNKNOWN; | 
|  512         return Handle<Integer>(); |  514         return Handle<Integer>(); | 
|  513       default: |  515       default: | 
|  514         CHECK(state_ == UNKNOWN); |  516         CHECK(state_ == UNKNOWN); | 
|  515         break; |  517         break; | 
| (...skipping 16 matching lines...) Expand all  Loading... | 
|  532                   0, |  534                   0, | 
|  533                   3,  // const declaration+initialization, var initialization |  535                   3,  // const declaration+initialization, var initialization | 
|  534                   3,  // 2 x declaration + var initialization |  536                   3,  // 2 x declaration + var initialization | 
|  535                   EXPECT_RESULT, Undefined(CcTest::isolate())); |  537                   EXPECT_RESULT, Undefined(CcTest::isolate())); | 
|  536   } |  538   } | 
|  537 } |  539 } | 
|  538  |  540  | 
|  539  |  541  | 
|  540  |  542  | 
|  541 class ExistsInPrototypeContext: public DeclarationContext { |  543 class ExistsInPrototypeContext: public DeclarationContext { | 
 |  544  public: | 
 |  545   ExistsInPrototypeContext() { InitializeIfNeeded(); } | 
|  542  protected: |  546  protected: | 
|  543   virtual v8::Handle<Integer> Query(Local<String> key) { |  547   virtual v8::Handle<Integer> Query(Local<String> key) { | 
|  544     // Let it seem that the property exists in the prototype object. |  548     // Let it seem that the property exists in the prototype object. | 
|  545     return Integer::New(v8::None); |  549     return Integer::New(isolate(), v8::None); | 
|  546   } |  550   } | 
|  547  |  551  | 
|  548   // Use the prototype as the holder for the interceptors. |  552   // Use the prototype as the holder for the interceptors. | 
|  549   virtual Local<ObjectTemplate> GetHolder(Local<FunctionTemplate> function) { |  553   virtual Local<ObjectTemplate> GetHolder(Local<FunctionTemplate> function) { | 
|  550     return function->PrototypeTemplate(); |  554     return function->PrototypeTemplate(); | 
|  551   } |  555   } | 
|  552 }; |  556 }; | 
|  553  |  557  | 
|  554  |  558  | 
|  555 TEST(ExistsInPrototype) { |  559 TEST(ExistsInPrototype) { | 
|  556   i::FLAG_es52_globals = true; |  560   i::FLAG_es52_globals = true; | 
|  557   HandleScope scope(CcTest::isolate()); |  561   HandleScope scope(CcTest::isolate()); | 
|  558  |  562  | 
|  559   // Sanity check to make sure that the holder of the interceptor |  563   // Sanity check to make sure that the holder of the interceptor | 
|  560   // really is the prototype object. |  564   // really is the prototype object. | 
|  561   { ExistsInPrototypeContext context; |  565   { ExistsInPrototypeContext context; | 
|  562     context.Check("this.x = 87; this.x", |  566     context.Check("this.x = 87; this.x", | 
|  563                   0, |  567                   0, | 
|  564                   0, |  568                   0, | 
|  565                   0, |  569                   0, | 
|  566                   EXPECT_RESULT, Number::New(87)); |  570                   EXPECT_RESULT, Number::New(CcTest::isolate(), 87)); | 
|  567   } |  571   } | 
|  568  |  572  | 
|  569   { ExistsInPrototypeContext context; |  573   { ExistsInPrototypeContext context; | 
|  570     context.Check("var x; x", |  574     context.Check("var x; x", | 
|  571                   0, |  575                   0, | 
|  572                   0, |  576                   0, | 
|  573                   0, |  577                   0, | 
|  574                   EXPECT_RESULT, Undefined(CcTest::isolate())); |  578                   EXPECT_RESULT, Undefined(CcTest::isolate())); | 
|  575   } |  579   } | 
|  576  |  580  | 
|  577   { ExistsInPrototypeContext context; |  581   { ExistsInPrototypeContext context; | 
|  578     context.Check("var x = 0; x", |  582     context.Check("var x = 0; x", | 
|  579                   0, |  583                   0, | 
|  580                   0, |  584                   0, | 
|  581                   0, |  585                   0, | 
|  582                   EXPECT_RESULT, Number::New(0)); |  586                   EXPECT_RESULT, Number::New(CcTest::isolate(), 0)); | 
|  583   } |  587   } | 
|  584  |  588  | 
|  585   { ExistsInPrototypeContext context; |  589   { ExistsInPrototypeContext context; | 
|  586     context.Check("const x; x", |  590     context.Check("const x; x", | 
|  587                   0, |  591                   0, | 
|  588                   0, |  592                   0, | 
|  589                   0, |  593                   0, | 
|  590                   EXPECT_RESULT, Undefined(CcTest::isolate())); |  594                   EXPECT_RESULT, Undefined(CcTest::isolate())); | 
|  591   } |  595   } | 
|  592  |  596  | 
|  593   { ExistsInPrototypeContext context; |  597   { ExistsInPrototypeContext context; | 
|  594     context.Check("const x = 0; x", |  598     context.Check("const x = 0; x", | 
|  595                   0, |  599                   0, | 
|  596                   0, |  600                   0, | 
|  597                   0, |  601                   0, | 
|  598                   EXPECT_RESULT, Number::New(0)); |  602                   EXPECT_RESULT, Number::New(CcTest::isolate(), 0)); | 
|  599   } |  603   } | 
|  600 } |  604 } | 
|  601  |  605  | 
|  602  |  606  | 
|  603  |  607  | 
|  604 class AbsentInPrototypeContext: public DeclarationContext { |  608 class AbsentInPrototypeContext: public DeclarationContext { | 
|  605  protected: |  609  protected: | 
|  606   virtual v8::Handle<Integer> Query(Local<String> key) { |  610   virtual v8::Handle<Integer> Query(Local<String> key) { | 
|  607     // Let it seem that the property is absent in the prototype object. |  611     // Let it seem that the property is absent in the prototype object. | 
|  608     return Handle<Integer>(); |  612     return Handle<Integer>(); | 
| (...skipping 25 matching lines...) Expand all  Loading... | 
|  634 class ExistsInHiddenPrototypeContext: public DeclarationContext { |  638 class ExistsInHiddenPrototypeContext: public DeclarationContext { | 
|  635  public: |  639  public: | 
|  636   ExistsInHiddenPrototypeContext() { |  640   ExistsInHiddenPrototypeContext() { | 
|  637     hidden_proto_ = FunctionTemplate::New(CcTest::isolate()); |  641     hidden_proto_ = FunctionTemplate::New(CcTest::isolate()); | 
|  638     hidden_proto_->SetHiddenPrototype(true); |  642     hidden_proto_->SetHiddenPrototype(true); | 
|  639   } |  643   } | 
|  640  |  644  | 
|  641  protected: |  645  protected: | 
|  642   virtual v8::Handle<Integer> Query(Local<String> key) { |  646   virtual v8::Handle<Integer> Query(Local<String> key) { | 
|  643     // Let it seem that the property exists in the hidden prototype object. |  647     // Let it seem that the property exists in the hidden prototype object. | 
|  644     return Integer::New(v8::None); |  648     return Integer::New(isolate(), v8::None); | 
|  645   } |  649   } | 
|  646  |  650  | 
|  647   // Install the hidden prototype after the global object has been created. |  651   // Install the hidden prototype after the global object has been created. | 
|  648   virtual void PostInitializeContext(Handle<Context> context) { |  652   virtual void PostInitializeContext(Handle<Context> context) { | 
|  649     Local<Object> global_object = context->Global(); |  653     Local<Object> global_object = context->Global(); | 
|  650     Local<Object> hidden_proto = hidden_proto_->GetFunction()->NewInstance(); |  654     Local<Object> hidden_proto = hidden_proto_->GetFunction()->NewInstance(); | 
|  651     Local<Object> inner_global = |  655     Local<Object> inner_global = | 
|  652         Local<Object>::Cast(global_object->GetPrototype()); |  656         Local<Object>::Cast(global_object->GetPrototype()); | 
|  653     inner_global->SetPrototype(hidden_proto); |  657     inner_global->SetPrototype(hidden_proto); | 
|  654   } |  658   } | 
| (...skipping 18 matching lines...) Expand all  Loading... | 
|  673                   0, |  677                   0, | 
|  674                   2,  // declaration + initialization |  678                   2,  // declaration + initialization | 
|  675                   EXPECT_EXCEPTION);  // x is not defined! |  679                   EXPECT_EXCEPTION);  // x is not defined! | 
|  676   } |  680   } | 
|  677  |  681  | 
|  678   { ExistsInHiddenPrototypeContext context; |  682   { ExistsInHiddenPrototypeContext context; | 
|  679     context.Check("var x = 0; x", |  683     context.Check("var x = 0; x", | 
|  680                   1,  // access |  684                   1,  // access | 
|  681                   1,  // initialization |  685                   1,  // initialization | 
|  682                   2,  // declaration + initialization |  686                   2,  // declaration + initialization | 
|  683                   EXPECT_RESULT, Number::New(0)); |  687                   EXPECT_RESULT, Number::New(CcTest::isolate(), 0)); | 
|  684   } |  688   } | 
|  685  |  689  | 
|  686   { ExistsInHiddenPrototypeContext context; |  690   { ExistsInHiddenPrototypeContext context; | 
|  687     context.Check("function x() { }; x", |  691     context.Check("function x() { }; x", | 
|  688                   0, |  692                   0, | 
|  689                   0, |  693                   0, | 
|  690                   0, |  694                   0, | 
|  691                   EXPECT_RESULT); |  695                   EXPECT_RESULT); | 
|  692   } |  696   } | 
|  693  |  697  | 
|  694   // TODO(mstarzinger): The semantics of global const is vague. |  698   // TODO(mstarzinger): The semantics of global const is vague. | 
|  695   { ExistsInHiddenPrototypeContext context; |  699   { ExistsInHiddenPrototypeContext context; | 
|  696     context.Check("const x; x", |  700     context.Check("const x; x", | 
|  697                   0, |  701                   0, | 
|  698                   0, |  702                   0, | 
|  699                   1,  // (re-)declaration |  703                   1,  // (re-)declaration | 
|  700                   EXPECT_RESULT, Undefined(CcTest::isolate())); |  704                   EXPECT_RESULT, Undefined(CcTest::isolate())); | 
|  701   } |  705   } | 
|  702  |  706  | 
|  703   // TODO(mstarzinger): The semantics of global const is vague. |  707   // TODO(mstarzinger): The semantics of global const is vague. | 
|  704   { ExistsInHiddenPrototypeContext context; |  708   { ExistsInHiddenPrototypeContext context; | 
|  705     context.Check("const x = 0; x", |  709     context.Check("const x = 0; x", | 
|  706                   0, |  710                   0, | 
|  707                   0, |  711                   0, | 
|  708                   1,  // (re-)declaration |  712                   1,  // (re-)declaration | 
|  709                   EXPECT_RESULT, Number::New(0)); |  713                   EXPECT_RESULT, Number::New(CcTest::isolate(), 0)); | 
|  710   } |  714   } | 
|  711 } |  715 } | 
|  712  |  716  | 
|  713  |  717  | 
|  714  |  718  | 
|  715 class SimpleContext { |  719 class SimpleContext { | 
|  716  public: |  720  public: | 
|  717   SimpleContext() |  721   SimpleContext() | 
|  718       : handle_scope_(CcTest::isolate()), |  722       : handle_scope_(CcTest::isolate()), | 
|  719         context_(Context::New(CcTest::isolate())) { |  723         context_(Context::New(CcTest::isolate())) { | 
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  752     } |  756     } | 
|  753   } |  757   } | 
|  754  |  758  | 
|  755  private: |  759  private: | 
|  756   HandleScope handle_scope_; |  760   HandleScope handle_scope_; | 
|  757   Local<Context> context_; |  761   Local<Context> context_; | 
|  758 }; |  762 }; | 
|  759  |  763  | 
|  760  |  764  | 
|  761 TEST(CrossScriptReferences) { |  765 TEST(CrossScriptReferences) { | 
|  762   HandleScope scope(CcTest::isolate()); |  766   v8::Isolate* isolate = CcTest::isolate(); | 
 |  767   HandleScope scope(isolate); | 
|  763  |  768  | 
|  764   { SimpleContext context; |  769   { SimpleContext context; | 
|  765     context.Check("var x = 1; x", |  770     context.Check("var x = 1; x", | 
|  766                   EXPECT_RESULT, Number::New(1)); |  771                   EXPECT_RESULT, Number::New(isolate, 1)); | 
|  767     context.Check("var x = 2; x", |  772     context.Check("var x = 2; x", | 
|  768                   EXPECT_RESULT, Number::New(2)); |  773                   EXPECT_RESULT, Number::New(isolate, 2)); | 
|  769     context.Check("const x = 3; x", |  774     context.Check("const x = 3; x", | 
|  770                   EXPECT_RESULT, Number::New(3)); |  775                   EXPECT_RESULT, Number::New(isolate, 3)); | 
|  771     context.Check("const x = 4; x", |  776     context.Check("const x = 4; x", | 
|  772                   EXPECT_RESULT, Number::New(4)); |  777                   EXPECT_RESULT, Number::New(isolate, 4)); | 
|  773     context.Check("x = 5; x", |  778     context.Check("x = 5; x", | 
|  774                   EXPECT_RESULT, Number::New(5)); |  779                   EXPECT_RESULT, Number::New(isolate, 5)); | 
|  775     context.Check("var x = 6; x", |  780     context.Check("var x = 6; x", | 
|  776                   EXPECT_RESULT, Number::New(6)); |  781                   EXPECT_RESULT, Number::New(isolate, 6)); | 
|  777     context.Check("this.x", |  782     context.Check("this.x", | 
|  778                   EXPECT_RESULT, Number::New(6)); |  783                   EXPECT_RESULT, Number::New(isolate, 6)); | 
|  779     context.Check("function x() { return 7 }; x()", |  784     context.Check("function x() { return 7 }; x()", | 
|  780                   EXPECT_RESULT, Number::New(7)); |  785                   EXPECT_RESULT, Number::New(isolate, 7)); | 
|  781   } |  786   } | 
|  782  |  787  | 
|  783   { SimpleContext context; |  788   { SimpleContext context; | 
|  784     context.Check("const x = 1; x", |  789     context.Check("const x = 1; x", | 
|  785                   EXPECT_RESULT, Number::New(1)); |  790                   EXPECT_RESULT, Number::New(isolate, 1)); | 
|  786     context.Check("var x = 2; x",  // assignment ignored |  791     context.Check("var x = 2; x",  // assignment ignored | 
|  787                   EXPECT_RESULT, Number::New(1)); |  792                   EXPECT_RESULT, Number::New(isolate, 1)); | 
|  788     context.Check("const x = 3; x", |  793     context.Check("const x = 3; x", | 
|  789                   EXPECT_RESULT, Number::New(1)); |  794                   EXPECT_RESULT, Number::New(isolate, 1)); | 
|  790     context.Check("x = 4; x",  // assignment ignored |  795     context.Check("x = 4; x",  // assignment ignored | 
|  791                   EXPECT_RESULT, Number::New(1)); |  796                   EXPECT_RESULT, Number::New(isolate, 1)); | 
|  792     context.Check("var x = 5; x",  // assignment ignored |  797     context.Check("var x = 5; x",  // assignment ignored | 
|  793                   EXPECT_RESULT, Number::New(1)); |  798                   EXPECT_RESULT, Number::New(isolate, 1)); | 
|  794     context.Check("this.x", |  799     context.Check("this.x", | 
|  795                   EXPECT_RESULT, Number::New(1)); |  800                   EXPECT_RESULT, Number::New(isolate, 1)); | 
|  796     context.Check("function x() { return 7 }; x", |  801     context.Check("function x() { return 7 }; x", | 
|  797                   EXPECT_EXCEPTION); |  802                   EXPECT_EXCEPTION); | 
|  798   } |  803   } | 
|  799 } |  804 } | 
|  800  |  805  | 
|  801  |  806  | 
|  802 TEST(CrossScriptReferencesHarmony) { |  807 TEST(CrossScriptReferencesHarmony) { | 
|  803   i::FLAG_use_strict = true; |  808   i::FLAG_use_strict = true; | 
|  804   i::FLAG_harmony_scoping = true; |  809   i::FLAG_harmony_scoping = true; | 
|  805   i::FLAG_harmony_modules = true; |  810   i::FLAG_harmony_modules = true; | 
|  806  |  811  | 
|  807   HandleScope scope(CcTest::isolate()); |  812   v8::Isolate* isolate = CcTest::isolate(); | 
 |  813   HandleScope scope(isolate); | 
|  808  |  814  | 
|  809   const char* decs[] = { |  815   const char* decs[] = { | 
|  810     "var x = 1; x", "x", "this.x", |  816     "var x = 1; x", "x", "this.x", | 
|  811     "function x() { return 1 }; x()", "x()", "this.x()", |  817     "function x() { return 1 }; x()", "x()", "this.x()", | 
|  812     "let x = 1; x", "x", "this.x", |  818     "let x = 1; x", "x", "this.x", | 
|  813     "const x = 1; x", "x", "this.x", |  819     "const x = 1; x", "x", "this.x", | 
|  814     "module x { export let a = 1 }; x.a", "x.a", "this.x.a", |  820     "module x { export let a = 1 }; x.a", "x.a", "this.x.a", | 
|  815     NULL |  821     NULL | 
|  816   }; |  822   }; | 
|  817  |  823  | 
|  818   for (int i = 0; decs[i] != NULL; i += 3) { |  824   for (int i = 0; decs[i] != NULL; i += 3) { | 
|  819     SimpleContext context; |  825     SimpleContext context; | 
|  820     context.Check(decs[i], EXPECT_RESULT, Number::New(1)); |  826     context.Check(decs[i], EXPECT_RESULT, Number::New(isolate, 1)); | 
|  821     context.Check(decs[i+1], EXPECT_RESULT, Number::New(1)); |  827     context.Check(decs[i+1], EXPECT_RESULT, Number::New(isolate, 1)); | 
|  822     // TODO(rossberg): The current ES6 draft spec does not reflect lexical |  828     // TODO(rossberg): The current ES6 draft spec does not reflect lexical | 
|  823     // bindings on the global object. However, this will probably change, in |  829     // bindings on the global object. However, this will probably change, in | 
|  824     // which case we reactivate the following test. |  830     // which case we reactivate the following test. | 
|  825     if (i/3 < 2) context.Check(decs[i+2], EXPECT_RESULT, Number::New(1)); |  831     if (i/3 < 2) { | 
 |  832       context.Check(decs[i+2], EXPECT_RESULT, Number::New(isolate, 1)); | 
 |  833     } | 
|  826   } |  834   } | 
|  827 } |  835 } | 
|  828  |  836  | 
|  829  |  837  | 
|  830 TEST(CrossScriptConflicts) { |  838 TEST(CrossScriptConflicts) { | 
|  831   i::FLAG_use_strict = true; |  839   i::FLAG_use_strict = true; | 
|  832   i::FLAG_harmony_scoping = true; |  840   i::FLAG_harmony_scoping = true; | 
|  833   i::FLAG_harmony_modules = true; |  841   i::FLAG_harmony_modules = true; | 
|  834  |  842  | 
|  835   HandleScope scope(CcTest::isolate()); |  843   HandleScope scope(CcTest::isolate()); | 
| (...skipping 11 matching lines...) Expand all  Loading... | 
|  847     "function x() { return 2 }; x()", |  855     "function x() { return 2 }; x()", | 
|  848     "let x = 2; x", |  856     "let x = 2; x", | 
|  849     "const x = 2; x", |  857     "const x = 2; x", | 
|  850     "module x { export let a = 2 }; x.a", |  858     "module x { export let a = 2 }; x.a", | 
|  851     NULL |  859     NULL | 
|  852   }; |  860   }; | 
|  853  |  861  | 
|  854   for (int i = 0; firsts[i] != NULL; ++i) { |  862   for (int i = 0; firsts[i] != NULL; ++i) { | 
|  855     for (int j = 0; seconds[j] != NULL; ++j) { |  863     for (int j = 0; seconds[j] != NULL; ++j) { | 
|  856       SimpleContext context; |  864       SimpleContext context; | 
|  857       context.Check(firsts[i], EXPECT_RESULT, Number::New(1)); |  865       context.Check(firsts[i], EXPECT_RESULT, | 
 |  866                     Number::New(CcTest::isolate(), 1)); | 
|  858       // TODO(rossberg): All tests should actually be errors in Harmony, |  867       // TODO(rossberg): All tests should actually be errors in Harmony, | 
|  859       // but we currently do not detect the cases where the first declaration |  868       // but we currently do not detect the cases where the first declaration | 
|  860       // is not lexical. |  869       // is not lexical. | 
|  861       context.Check(seconds[j], |  870       context.Check(seconds[j], | 
|  862                     i < 2 ? EXPECT_RESULT : EXPECT_ERROR, Number::New(2)); |  871                     i < 2 ? EXPECT_RESULT : EXPECT_ERROR, | 
 |  872                     Number::New(CcTest::isolate(), 2)); | 
|  863     } |  873     } | 
|  864   } |  874   } | 
|  865 } |  875 } | 
| OLD | NEW |