Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(399)

Side by Side Diff: test/cctest/test-api.cc

Issue 151163005: A64: Synchronize with r16356. (Closed) Base URL: https://v8.googlecode.com/svn/branches/experimental/a64
Patch Set: Created 6 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « test/cctest/test-accessors.cc ('k') | test/cctest/test-circular-queue.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 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 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
46 #include "objects.h" 46 #include "objects.h"
47 #include "parser.h" 47 #include "parser.h"
48 #include "platform.h" 48 #include "platform.h"
49 #include "snapshot.h" 49 #include "snapshot.h"
50 #include "unicode-inl.h" 50 #include "unicode-inl.h"
51 #include "utils.h" 51 #include "utils.h"
52 #include "vm-state.h" 52 #include "vm-state.h"
53 53
54 static const bool kLogThreading = false; 54 static const bool kLogThreading = false;
55 55
56 using ::v8::AccessorInfo;
57 using ::v8::Arguments;
58 using ::v8::Boolean; 56 using ::v8::Boolean;
59 using ::v8::BooleanObject; 57 using ::v8::BooleanObject;
60 using ::v8::Context; 58 using ::v8::Context;
61 using ::v8::Extension; 59 using ::v8::Extension;
62 using ::v8::Function; 60 using ::v8::Function;
63 using ::v8::FunctionTemplate; 61 using ::v8::FunctionTemplate;
64 using ::v8::Handle; 62 using ::v8::Handle;
65 using ::v8::HandleScope; 63 using ::v8::HandleScope;
66 using ::v8::Local; 64 using ::v8::Local;
67 using ::v8::Message; 65 using ::v8::Message;
(...skipping 3104 matching lines...) Expand 10 before | Expand all | Expand 10 after
3172 #else 3170 #else
3173 v8::Persistent<Value>& global_value = 3171 v8::Persistent<Value>& global_value =
3174 v8::Persistent<Value>::Cast(global_string); 3172 v8::Persistent<Value>::Cast(global_string);
3175 #endif 3173 #endif
3176 CHECK(v8::Local<v8::Value>::New(isolate, global_value)->IsString()); 3174 CHECK(v8::Local<v8::Value>::New(isolate, global_value)->IsString());
3177 CHECK(global_string == v8::Persistent<String>::Cast(global_value)); 3175 CHECK(global_string == v8::Persistent<String>::Cast(global_value));
3178 global_string.Dispose(); 3176 global_string.Dispose();
3179 } 3177 }
3180 3178
3181 3179
3180 THREADED_TEST(HandleEquality) {
3181 v8::Isolate* isolate = v8::Isolate::GetCurrent();
3182 v8::Persistent<String> global1;
3183 v8::Persistent<String> global2;
3184 {
3185 v8::HandleScope scope(isolate);
3186 global1.Reset(isolate, v8_str("str"));
3187 global2.Reset(isolate, v8_str("str2"));
3188 }
3189 CHECK_EQ(global1 == global1, true);
3190 CHECK_EQ(global1 != global1, false);
3191 {
3192 v8::HandleScope scope(isolate);
3193 Local<String> local1 = Local<String>::New(isolate, global1);
3194 Local<String> local2 = Local<String>::New(isolate, global2);
3195
3196 CHECK_EQ(global1 == local1, true);
3197 CHECK_EQ(global1 != local1, false);
3198 CHECK_EQ(local1 == global1, true);
3199 CHECK_EQ(local1 != global1, false);
3200
3201 CHECK_EQ(global1 == local2, false);
3202 CHECK_EQ(global1 != local2, true);
3203 CHECK_EQ(local2 == global1, false);
3204 CHECK_EQ(local2 != global1, true);
3205
3206 CHECK_EQ(local1 == local2, false);
3207 CHECK_EQ(local1 != local2, true);
3208
3209 Local<String> anotherLocal1 = Local<String>::New(isolate, global1);
3210 CHECK_EQ(local1 == anotherLocal1, true);
3211 CHECK_EQ(local1 != anotherLocal1, false);
3212 }
3213 global1.Dispose();
3214 global2.Dispose();
3215 }
3216
3217
3182 THREADED_TEST(LocalHandle) { 3218 THREADED_TEST(LocalHandle) {
3183 v8::HandleScope scope(v8::Isolate::GetCurrent()); 3219 v8::HandleScope scope(v8::Isolate::GetCurrent());
3184 v8::Local<String> local = v8::Local<String>::New(v8_str("str")); 3220 v8::Local<String> local = v8::Local<String>::New(v8_str("str"));
3185 CHECK_EQ(local->Length(), 3); 3221 CHECK_EQ(local->Length(), 3);
3186 3222
3187 local = v8::Local<String>::New(v8::Isolate::GetCurrent(), v8_str("str")); 3223 local = v8::Local<String>::New(v8::Isolate::GetCurrent(), v8_str("str"));
3188 CHECK_EQ(local->Length(), 3); 3224 CHECK_EQ(local->Length(), 3);
3189 } 3225 }
3190 3226
3191 3227
(...skipping 5020 matching lines...) Expand 10 before | Expand all | Expand 10 after
8212 8248
8213 static bool IndexedAccessBlocker(Local<v8::Object> global, 8249 static bool IndexedAccessBlocker(Local<v8::Object> global,
8214 uint32_t key, 8250 uint32_t key,
8215 v8::AccessType type, 8251 v8::AccessType type,
8216 Local<Value> data) { 8252 Local<Value> data) {
8217 return Context::GetCurrent()->Global()->Equals(global) || 8253 return Context::GetCurrent()->Global()->Equals(global) ||
8218 allowed_access_type[type]; 8254 allowed_access_type[type];
8219 } 8255 }
8220 8256
8221 8257
8222 static int g_echo_value = -1; 8258 static int g_echo_value_1 = -1;
8259 static int g_echo_value_2 = -1;
8260
8261
8223 static void EchoGetter( 8262 static void EchoGetter(
8224 Local<String> name, 8263 Local<String> name,
8225 const v8::PropertyCallbackInfo<v8::Value>& info) { 8264 const v8::PropertyCallbackInfo<v8::Value>& info) {
8226 info.GetReturnValue().Set(v8_num(g_echo_value)); 8265 info.GetReturnValue().Set(v8_num(g_echo_value_1));
8227 } 8266 }
8228 8267
8229 8268
8269 static void EchoGetter(const v8::FunctionCallbackInfo<v8::Value>& info) {
8270 info.GetReturnValue().Set(v8_num(g_echo_value_2));
8271 }
8272
8273
8230 static void EchoSetter(Local<String> name, 8274 static void EchoSetter(Local<String> name,
8231 Local<Value> value, 8275 Local<Value> value,
8232 const v8::PropertyCallbackInfo<void>&) { 8276 const v8::PropertyCallbackInfo<void>&) {
8233 if (value->IsNumber()) 8277 if (value->IsNumber())
8234 g_echo_value = value->Int32Value(); 8278 g_echo_value_1 = value->Int32Value();
8235 } 8279 }
8236 8280
8237 8281
8282 static void EchoSetter(const v8::FunctionCallbackInfo<v8::Value>& info) {
8283 v8::Handle<v8::Value> value = info[0];
8284 if (value->IsNumber())
8285 g_echo_value_2 = value->Int32Value();
8286 }
8287
8288
8238 static void UnreachableGetter( 8289 static void UnreachableGetter(
8239 Local<String> name, 8290 Local<String> name,
8240 const v8::PropertyCallbackInfo<v8::Value>& info) { 8291 const v8::PropertyCallbackInfo<v8::Value>& info) {
8241 CHECK(false); // This function should not be called.. 8292 CHECK(false); // This function should not be called..
8242 } 8293 }
8243 8294
8244 8295
8245 static void UnreachableSetter(Local<String>, 8296 static void UnreachableSetter(Local<String>,
8246 Local<Value>, 8297 Local<Value>,
8247 const v8::PropertyCallbackInfo<void>&) { 8298 const v8::PropertyCallbackInfo<void>&) {
8248 CHECK(false); // This function should nto be called. 8299 CHECK(false); // This function should nto be called.
8249 } 8300 }
8250 8301
8251 8302
8303 static void UnreachableFunction(
8304 const v8::FunctionCallbackInfo<v8::Value>& info) {
8305 CHECK(false); // This function should not be called..
8306 }
8307
8308
8252 TEST(AccessControl) { 8309 TEST(AccessControl) {
8253 v8::Isolate* isolate = v8::Isolate::GetCurrent(); 8310 v8::Isolate* isolate = v8::Isolate::GetCurrent();
8254 v8::HandleScope handle_scope(isolate); 8311 v8::HandleScope handle_scope(isolate);
8255 v8::Handle<v8::ObjectTemplate> global_template = v8::ObjectTemplate::New(); 8312 v8::Handle<v8::ObjectTemplate> global_template = v8::ObjectTemplate::New();
8256 8313
8257 global_template->SetAccessCheckCallbacks(NamedAccessBlocker, 8314 global_template->SetAccessCheckCallbacks(NamedAccessBlocker,
8258 IndexedAccessBlocker); 8315 IndexedAccessBlocker);
8259 8316
8260 // Add an accessor accessible by cross-domain JS code. 8317 // Add an accessor accessible by cross-domain JS code.
8261 global_template->SetAccessor( 8318 global_template->SetAccessor(
8262 v8_str("accessible_prop"), 8319 v8_str("accessible_prop"),
8263 EchoGetter, EchoSetter, 8320 EchoGetter, EchoSetter,
8264 v8::Handle<Value>(), 8321 v8::Handle<Value>(),
8265 v8::AccessControl(v8::ALL_CAN_READ | v8::ALL_CAN_WRITE)); 8322 v8::AccessControl(v8::ALL_CAN_READ | v8::ALL_CAN_WRITE));
8266 8323
8324
8325 global_template->SetAccessorProperty(
8326 v8_str("accessible_js_prop"),
8327 v8::FunctionTemplate::New(EchoGetter),
8328 v8::FunctionTemplate::New(EchoSetter),
8329 v8::None,
8330 v8::AccessControl(v8::ALL_CAN_READ | v8::ALL_CAN_WRITE));
8331
8267 // Add an accessor that is not accessible by cross-domain JS code. 8332 // Add an accessor that is not accessible by cross-domain JS code.
8268 global_template->SetAccessor(v8_str("blocked_prop"), 8333 global_template->SetAccessor(v8_str("blocked_prop"),
8269 UnreachableGetter, UnreachableSetter, 8334 UnreachableGetter, UnreachableSetter,
8270 v8::Handle<Value>(), 8335 v8::Handle<Value>(),
8271 v8::DEFAULT); 8336 v8::DEFAULT);
8272 8337
8338 global_template->SetAccessorProperty(
8339 v8_str("blocked_js_prop"),
8340 v8::FunctionTemplate::New(UnreachableFunction),
8341 v8::FunctionTemplate::New(UnreachableFunction),
8342 v8::None,
8343 v8::DEFAULT);
8344
8273 // Create an environment 8345 // Create an environment
8274 v8::Local<Context> context0 = Context::New(isolate, NULL, global_template); 8346 v8::Local<Context> context0 = Context::New(isolate, NULL, global_template);
8275 context0->Enter(); 8347 context0->Enter();
8276 8348
8277 v8::Handle<v8::Object> global0 = context0->Global(); 8349 v8::Handle<v8::Object> global0 = context0->Global();
8278 8350
8279 // Define a property with JS getter and setter. 8351 // Define a property with JS getter and setter.
8280 CompileRun( 8352 CompileRun(
8281 "function getter() { return 'getter'; };\n" 8353 "function getter() { return 'getter'; };\n"
8282 "function setter() { return 'setter'; }\n" 8354 "function setter() { return 'setter'; }\n"
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after
8455 allowed_access_type[v8::ACCESS_SET] = false; 8527 allowed_access_type[v8::ACCESS_SET] = false;
8456 allowed_access_type[v8::ACCESS_GET] = false; 8528 allowed_access_type[v8::ACCESS_GET] = false;
8457 allowed_access_type[v8::ACCESS_HAS] = false; 8529 allowed_access_type[v8::ACCESS_HAS] = false;
8458 8530
8459 v8::Handle<Value> value; 8531 v8::Handle<Value> value;
8460 8532
8461 // Access accessible property 8533 // Access accessible property
8462 value = CompileRun("other.accessible_prop = 3"); 8534 value = CompileRun("other.accessible_prop = 3");
8463 CHECK(value->IsNumber()); 8535 CHECK(value->IsNumber());
8464 CHECK_EQ(3, value->Int32Value()); 8536 CHECK_EQ(3, value->Int32Value());
8465 CHECK_EQ(3, g_echo_value); 8537 CHECK_EQ(3, g_echo_value_1);
8538
8539 // Access accessible js property
8540 value = CompileRun("other.accessible_js_prop = 3");
8541 CHECK(value->IsNumber());
8542 CHECK_EQ(3, value->Int32Value());
8543 CHECK_EQ(3, g_echo_value_2);
8466 8544
8467 value = CompileRun("other.accessible_prop"); 8545 value = CompileRun("other.accessible_prop");
8468 CHECK(value->IsNumber()); 8546 CHECK(value->IsNumber());
8469 CHECK_EQ(3, value->Int32Value()); 8547 CHECK_EQ(3, value->Int32Value());
8470 8548
8549 value = CompileRun("other.accessible_js_prop");
8550 CHECK(value->IsNumber());
8551 CHECK_EQ(3, value->Int32Value());
8552
8471 value = CompileRun( 8553 value = CompileRun(
8472 "Object.getOwnPropertyDescriptor(other, 'accessible_prop').value"); 8554 "Object.getOwnPropertyDescriptor(other, 'accessible_prop').value");
8473 CHECK(value->IsNumber()); 8555 CHECK(value->IsNumber());
8474 CHECK_EQ(3, value->Int32Value()); 8556 CHECK_EQ(3, value->Int32Value());
8475 8557
8558 value = CompileRun(
8559 "Object.getOwnPropertyDescriptor(other, 'accessible_js_prop').get()");
8560 CHECK(value->IsNumber());
8561 CHECK_EQ(3, value->Int32Value());
8562
8476 value = CompileRun("propertyIsEnumerable.call(other, 'accessible_prop')"); 8563 value = CompileRun("propertyIsEnumerable.call(other, 'accessible_prop')");
8477 CHECK(value->IsTrue()); 8564 CHECK(value->IsTrue());
8478 8565
8566 value = CompileRun("propertyIsEnumerable.call(other, 'accessible_js_prop')");
8567 CHECK(value->IsTrue());
8568
8479 // Enumeration doesn't enumerate accessors from inaccessible objects in 8569 // Enumeration doesn't enumerate accessors from inaccessible objects in
8480 // the prototype chain even if the accessors are in themselves accessible. 8570 // the prototype chain even if the accessors are in themselves accessible.
8481 value = 8571 value =
8482 CompileRun("(function(){var obj = {'__proto__':other};" 8572 CompileRun("(function(){var obj = {'__proto__':other};"
8483 "for (var p in obj)" 8573 "for (var p in obj)"
8484 " if (p == 'accessible_prop' || p == 'blocked_prop') {" 8574 " if (p == 'accessible_prop' ||"
8575 " p == 'accessible_js_prop' ||"
8576 " p == 'blocked_js_prop' ||"
8577 " p == 'blocked_js_prop') {"
8485 " return false;" 8578 " return false;"
8486 " }" 8579 " }"
8487 "return true;})()"); 8580 "return true;})()");
8488 CHECK(value->IsTrue()); 8581 CHECK(value->IsTrue());
8489 8582
8490 context1->Exit(); 8583 context1->Exit();
8491 context0->Exit(); 8584 context0->Exit();
8492 } 8585 }
8493 8586
8494 8587
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
8546 CompileRun("Object.freeze(other)"); 8639 CompileRun("Object.freeze(other)");
8547 ExpectTrue("Object.isExtensible(other)"); 8640 ExpectTrue("Object.isExtensible(other)");
8548 8641
8549 CompileRun("Object.seal(other)"); 8642 CompileRun("Object.seal(other)");
8550 ExpectTrue("Object.isExtensible(other)"); 8643 ExpectTrue("Object.isExtensible(other)");
8551 8644
8552 // Regression test for issue 1250. 8645 // Regression test for issue 1250.
8553 // Make sure that we can set the accessible accessors value using normal 8646 // Make sure that we can set the accessible accessors value using normal
8554 // assignment. 8647 // assignment.
8555 CompileRun("other.accessible_prop = 42"); 8648 CompileRun("other.accessible_prop = 42");
8556 CHECK_EQ(42, g_echo_value); 8649 CHECK_EQ(42, g_echo_value_1);
8557 8650
8558 v8::Handle<Value> value; 8651 v8::Handle<Value> value;
8559 // We follow Safari in ignoring assignments to host object accessors. 8652 // We follow Safari in ignoring assignments to host object accessors.
8560 CompileRun("Object.defineProperty(other, 'accessible_prop', {value: -1})"); 8653 CompileRun("Object.defineProperty(other, 'accessible_prop', {value: -1})");
8561 value = CompileRun("other.accessible_prop == 42"); 8654 value = CompileRun("other.accessible_prop == 42");
8562 CHECK(value->IsTrue()); 8655 CHECK(value->IsTrue());
8563 } 8656 }
8564 8657
8565 8658
8566 static bool GetOwnPropertyNamesNamedBlocker(Local<v8::Object> global, 8659 static bool GetOwnPropertyNamesNamedBlocker(Local<v8::Object> global,
(...skipping 939 matching lines...) Expand 10 before | Expand all | Expand 10 after
9506 // return false and keep VM in sane state. 9599 // return false and keep VM in sane state.
9507 v8::TryCatch try_catch; 9600 v8::TryCatch try_catch;
9508 CHECK(!o1->SetPrototype(o0)); 9601 CHECK(!o1->SetPrototype(o0));
9509 CHECK(!try_catch.HasCaught()); 9602 CHECK(!try_catch.HasCaught());
9510 ASSERT(!i::Isolate::Current()->has_pending_exception()); 9603 ASSERT(!i::Isolate::Current()->has_pending_exception());
9511 9604
9512 CHECK_EQ(42, CompileRun("function f() { return 42; }; f()")->Int32Value()); 9605 CHECK_EQ(42, CompileRun("function f() { return 42; }; f()")->Int32Value());
9513 } 9606 }
9514 9607
9515 9608
9609 THREADED_TEST(FunctionRemovePrototype) {
9610 LocalContext context;
9611 v8::HandleScope handle_scope(context->GetIsolate());
9612
9613 Local<v8::FunctionTemplate> t1 = v8::FunctionTemplate::New();
9614 t1->RemovePrototype();
9615 Local<v8::Function> fun = t1->GetFunction();
9616 context->Global()->Set(v8_str("fun"), fun);
9617 CHECK(!CompileRun("'prototype' in fun")->BooleanValue());
9618
9619 v8::TryCatch try_catch;
9620 CompileRun("new fun()");
9621 CHECK(try_catch.HasCaught());
9622
9623 try_catch.Reset();
9624 fun->NewInstance();
9625 CHECK(try_catch.HasCaught());
9626 }
9627
9628
9516 THREADED_TEST(GetterSetterExceptions) { 9629 THREADED_TEST(GetterSetterExceptions) {
9517 LocalContext context; 9630 LocalContext context;
9518 v8::HandleScope handle_scope(context->GetIsolate()); 9631 v8::HandleScope handle_scope(context->GetIsolate());
9519 CompileRun( 9632 CompileRun(
9520 "function Foo() { };" 9633 "function Foo() { };"
9521 "function Throw() { throw 5; };" 9634 "function Throw() { throw 5; };"
9522 "var x = { };" 9635 "var x = { };"
9523 "x.__defineSetter__('set', Throw);" 9636 "x.__defineSetter__('set', Throw);"
9524 "x.__defineGetter__('get', Throw);"); 9637 "x.__defineGetter__('get', Throw);");
9525 Local<v8::Object> x = 9638 Local<v8::Object> x =
(...skipping 2716 matching lines...) Expand 10 before | Expand all | Expand 10 after
12242 fuzzing_ = false; 12355 fuzzing_ = false;
12243 for (int i = 0; i < RegisterThreadedTest::count(); i++) { 12356 for (int i = 0; i < RegisterThreadedTest::count(); i++) {
12244 ApiTestFuzzer *fuzzer = RegisterThreadedTest::nth(i)->fuzzer_; 12357 ApiTestFuzzer *fuzzer = RegisterThreadedTest::nth(i)->fuzzer_;
12245 if (fuzzer != NULL) fuzzer->Join(); 12358 if (fuzzer != NULL) fuzzer->Join();
12246 } 12359 }
12247 } 12360 }
12248 12361
12249 12362
12250 // Lets not be needlessly self-referential. 12363 // Lets not be needlessly self-referential.
12251 TEST(Threading1) { 12364 TEST(Threading1) {
12252 // TODO(mstarzinger): Disabled in GC stress mode for now, we should find the
12253 // correct timeout for this an re-enable this test again
12254 if (i::FLAG_stress_compaction) return;
12255 ApiTestFuzzer::SetUp(ApiTestFuzzer::FIRST_PART); 12365 ApiTestFuzzer::SetUp(ApiTestFuzzer::FIRST_PART);
12256 ApiTestFuzzer::RunAllTests(); 12366 ApiTestFuzzer::RunAllTests();
12257 ApiTestFuzzer::TearDown(); 12367 ApiTestFuzzer::TearDown();
12258 } 12368 }
12259 12369
12260 12370
12261 TEST(Threading2) { 12371 TEST(Threading2) {
12262 ApiTestFuzzer::SetUp(ApiTestFuzzer::SECOND_PART); 12372 ApiTestFuzzer::SetUp(ApiTestFuzzer::SECOND_PART);
12263 ApiTestFuzzer::RunAllTests(); 12373 ApiTestFuzzer::RunAllTests();
12264 ApiTestFuzzer::TearDown(); 12374 ApiTestFuzzer::TearDown();
(...skipping 7892 matching lines...) Expand 10 before | Expand all | Expand 10 after
20157 CheckCorrectThrow("%GetLocalPropertyNames(other, true)"); 20267 CheckCorrectThrow("%GetLocalPropertyNames(other, true)");
20158 CheckCorrectThrow("%DefineOrRedefineAccessorProperty(" 20268 CheckCorrectThrow("%DefineOrRedefineAccessorProperty("
20159 "other, 'x', null, null, 1)"); 20269 "other, 'x', null, null, 1)");
20160 20270
20161 // Reset the failed access check callback so it does not influence 20271 // Reset the failed access check callback so it does not influence
20162 // the other tests. 20272 // the other tests.
20163 v8::V8::SetFailedAccessCheckCallbackFunction(NULL); 20273 v8::V8::SetFailedAccessCheckCallbackFunction(NULL);
20164 } 20274 }
20165 20275
20166 #endif // WIN32 20276 #endif // WIN32
OLDNEW
« no previous file with comments | « test/cctest/test-accessors.cc ('k') | test/cctest/test-circular-queue.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698