| Index: test/cctest/test-api.cc
|
| ===================================================================
|
| --- test/cctest/test-api.cc (revision 7180)
|
| +++ test/cctest/test-api.cc (working copy)
|
| @@ -2691,6 +2691,41 @@
|
| }
|
|
|
|
|
| +THREADED_TEST(TryCatchAndFinallyHidingException) {
|
| + v8::HandleScope scope;
|
| + LocalContext context;
|
| + v8::TryCatch try_catch;
|
| + CHECK(!try_catch.HasCaught());
|
| + CompileRun("function f(k) { try { this[k]; } finally { return 0; } };");
|
| + CompileRun("f({toString: function() { throw 42; }});");
|
| + CHECK(!try_catch.HasCaught());
|
| +}
|
| +
|
| +
|
| +v8::Handle<v8::Value> WithTryCatch(const v8::Arguments& args) {
|
| + v8::TryCatch try_catch;
|
| + return v8::Undefined();
|
| +}
|
| +
|
| +
|
| +THREADED_TEST(TryCatchAndFinally) {
|
| + v8::HandleScope scope;
|
| + LocalContext context;
|
| + context->Global()->Set(
|
| + v8_str("native_with_try_catch"),
|
| + v8::FunctionTemplate::New(WithTryCatch)->GetFunction());
|
| + v8::TryCatch try_catch;
|
| + CHECK(!try_catch.HasCaught());
|
| + CompileRun(
|
| + "try {\n"
|
| + " throw new Error('a');\n"
|
| + "} finally {\n"
|
| + " native_with_try_catch();\n"
|
| + "}\n");
|
| + CHECK(try_catch.HasCaught());
|
| +}
|
| +
|
| +
|
| THREADED_TEST(Equality) {
|
| v8::HandleScope scope;
|
| LocalContext context;
|
| @@ -5617,14 +5652,21 @@
|
| }
|
|
|
|
|
| -// This is a regression test for issue 1154.
|
| -TEST(AccessControlObjectKeys) {
|
| +TEST(AccessControlES5) {
|
| v8::HandleScope handle_scope;
|
| v8::Handle<v8::ObjectTemplate> global_template = v8::ObjectTemplate::New();
|
|
|
| global_template->SetAccessCheckCallbacks(NamedAccessBlocker,
|
| IndexedAccessBlocker);
|
|
|
| + // Add accessible accessor.
|
| + global_template->SetAccessor(
|
| + v8_str("accessible_prop"),
|
| + EchoGetter, EchoSetter,
|
| + v8::Handle<Value>(),
|
| + v8::AccessControl(v8::ALL_CAN_READ | v8::ALL_CAN_WRITE));
|
| +
|
| +
|
| // Add an accessor that is not accessible by cross-domain JS code.
|
| global_template->SetAccessor(v8_str("blocked_prop"),
|
| UnreachableGetter, UnreachableSetter,
|
| @@ -5642,7 +5684,41 @@
|
| v8::Handle<v8::Object> global1 = context1->Global();
|
| global1->Set(v8_str("other"), global0);
|
|
|
| + // Regression test for issue 1154.
|
| ExpectTrue("Object.keys(other).indexOf('blocked_prop') == -1");
|
| +
|
| + ExpectUndefined("other.blocked_prop");
|
| +
|
| + // Regression test for issue 1027.
|
| + CompileRun("Object.defineProperty(\n"
|
| + " other, 'blocked_prop', {configurable: false})");
|
| + ExpectUndefined("other.blocked_prop");
|
| + ExpectUndefined(
|
| + "Object.getOwnPropertyDescriptor(other, 'blocked_prop')");
|
| +
|
| + // Regression test for issue 1171.
|
| + ExpectTrue("Object.isExtensible(other)");
|
| + CompileRun("Object.preventExtensions(other)");
|
| + ExpectTrue("Object.isExtensible(other)");
|
| +
|
| + // Object.seal and Object.freeze.
|
| + CompileRun("Object.freeze(other)");
|
| + ExpectTrue("Object.isExtensible(other)");
|
| +
|
| + CompileRun("Object.seal(other)");
|
| + ExpectTrue("Object.isExtensible(other)");
|
| +
|
| + // Regression test for issue 1250.
|
| + // Make sure that we can set the accessible accessors value using normal
|
| + // assignment.
|
| + CompileRun("other.accessible_prop = 42");
|
| + CHECK_EQ(42, g_echo_value);
|
| +
|
| + v8::Handle<Value> value;
|
| + // We follow Safari in ignoring assignments to host object accessors.
|
| + CompileRun("Object.defineProperty(other, 'accessible_prop', {value: -1})");
|
| + value = CompileRun("other.accessible_prop == 42");
|
| + CHECK(value->IsTrue());
|
| }
|
|
|
|
|
| @@ -7571,10 +7647,11 @@
|
| "garbage = undefined;");
|
| }
|
|
|
| +
|
| v8::Handle<v8::Value> DirectApiCallback(const v8::Arguments& args) {
|
| static int count = 0;
|
| if (count++ % 3 == 0) {
|
| - v8::V8::LowMemoryNotification(); // This should move the stub
|
| + i::Heap::CollectAllGarbage(true); // This should move the stub
|
| GenerateSomeGarbage(); // This should ensure the old stub memory is flushed
|
| }
|
| return v8::Handle<v8::Value>();
|
| @@ -7626,6 +7703,54 @@
|
| }
|
|
|
|
|
| +v8::Handle<v8::Value> DirectGetterCallback(Local<String> name,
|
| + const v8::AccessorInfo& info) {
|
| + if (++p_getter_count % 3 == 0) {
|
| + i::Heap::CollectAllGarbage(true);
|
| + GenerateSomeGarbage();
|
| + }
|
| + return v8::Handle<v8::Value>();
|
| +}
|
| +
|
| +
|
| +THREADED_TEST(LoadICFastApi_DirectCall_GCMoveStub) {
|
| + v8::HandleScope scope;
|
| + LocalContext context;
|
| + v8::Handle<v8::ObjectTemplate> obj = v8::ObjectTemplate::New();
|
| + obj->SetAccessor(v8_str("p1"), DirectGetterCallback);
|
| + context->Global()->Set(v8_str("o1"), obj->NewInstance());
|
| + p_getter_count = 0;
|
| + CompileRun(
|
| + "function f() {"
|
| + " for (var i = 0; i < 30; i++) o1.p1;"
|
| + "}"
|
| + "f();");
|
| + CHECK_EQ(30, p_getter_count);
|
| +}
|
| +
|
| +
|
| +v8::Handle<v8::Value> ThrowingDirectGetterCallback(
|
| + Local<String> name, const v8::AccessorInfo& info) {
|
| + return v8::ThrowException(v8_str("g"));
|
| +}
|
| +
|
| +
|
| +THREADED_TEST(LoadICFastApi_DirectCall_Throw) {
|
| + v8::HandleScope scope;
|
| + LocalContext context;
|
| + v8::Handle<v8::ObjectTemplate> obj = v8::ObjectTemplate::New();
|
| + obj->SetAccessor(v8_str("p1"), ThrowingDirectGetterCallback);
|
| + context->Global()->Set(v8_str("o1"), obj->NewInstance());
|
| + v8::Handle<Value> result = CompileRun(
|
| + "var result = '';"
|
| + "for (var i = 0; i < 5; i++) {"
|
| + " try { o1.p1; } catch (e) { result += e; }"
|
| + "}"
|
| + "result;");
|
| + CHECK_EQ(v8_str("ggggg"), result);
|
| +}
|
| +
|
| +
|
| THREADED_TEST(InterceptorCallICFastApi_TrivialSignature) {
|
| int interceptor_call_count = 0;
|
| v8::HandleScope scope;
|
| @@ -9986,11 +10111,12 @@
|
| // Inject the input as a global variable.
|
| i::Handle<i::String> input_name =
|
| i::Factory::NewStringFromAscii(i::Vector<const char>("input", 5));
|
| - i::Top::global_context()->global()->SetProperty(*input_name,
|
| - *input_,
|
| - NONE)->ToObjectChecked();
|
| + i::Top::global_context()->global()->SetProperty(
|
| + *input_name,
|
| + *input_,
|
| + NONE,
|
| + i::kNonStrictMode)->ToObjectChecked();
|
|
|
| -
|
| MorphThread morph_thread(this);
|
| morph_thread.Start();
|
| v8::Locker::StartPreemption(1);
|
| @@ -10443,8 +10569,11 @@
|
| LocalContext context;
|
| const int kElementCount = 260;
|
| uint8_t* pixel_data = reinterpret_cast<uint8_t*>(malloc(kElementCount));
|
| - i::Handle<i::PixelArray> pixels = i::Factory::NewPixelArray(kElementCount,
|
| - pixel_data);
|
| + i::Handle<i::ExternalPixelArray> pixels =
|
| + i::Handle<i::ExternalPixelArray>::cast(
|
| + i::Factory::NewExternalArray(kElementCount,
|
| + v8::kExternalPixelArray,
|
| + pixel_data));
|
| i::Heap::CollectAllGarbage(false); // Force GC to trigger verification.
|
| for (int i = 0; i < kElementCount; i++) {
|
| pixels->set(i, i % 256);
|
| @@ -10511,14 +10640,14 @@
|
| CHECK_EQ(28, result->Int32Value());
|
|
|
| i::Handle<i::Smi> value(i::Smi::FromInt(2));
|
| - i::SetElement(jsobj, 1, value);
|
| + i::SetElement(jsobj, 1, value, i::kNonStrictMode);
|
| CHECK_EQ(2, i::Smi::cast(jsobj->GetElement(1)->ToObjectChecked())->value());
|
| *value.location() = i::Smi::FromInt(256);
|
| - i::SetElement(jsobj, 1, value);
|
| + i::SetElement(jsobj, 1, value, i::kNonStrictMode);
|
| CHECK_EQ(255,
|
| i::Smi::cast(jsobj->GetElement(1)->ToObjectChecked())->value());
|
| *value.location() = i::Smi::FromInt(-1);
|
| - i::SetElement(jsobj, 1, value);
|
| + i::SetElement(jsobj, 1, value, i::kNonStrictMode);
|
| CHECK_EQ(0, i::Smi::cast(jsobj->GetElement(1)->ToObjectChecked())->value());
|
|
|
| result = CompileRun("for (var i = 0; i < 8; i++) {"
|
| @@ -10784,12 +10913,30 @@
|
| " return sum; "
|
| "}"
|
| "for (var i = 0; i < 256; ++i) { pixels[i] = i; }"
|
| - "for (var i = 0; i < 10000; ++i) {"
|
| + "for (var i = 0; i < 5000; ++i) {"
|
| " result = pa_load(pixels);"
|
| "}"
|
| "result");
|
| CHECK_EQ(32640, result->Int32Value());
|
|
|
| + // Make sure that pixel array stores are optimized by crankshaft.
|
| + result = CompileRun("function pa_init(p) {"
|
| + "for (var i = 0; i < 256; ++i) { p[i] = i; }"
|
| + "}"
|
| + "function pa_load(p) {"
|
| + " var sum = 0;"
|
| + " for (var i=0; i<256; ++i) {"
|
| + " sum += p[i];"
|
| + " }"
|
| + " return sum; "
|
| + "}"
|
| + "for (var i = 0; i < 5000; ++i) {"
|
| + " pa_init(pixels);"
|
| + "}"
|
| + "result = pa_load(pixels);"
|
| + "result");
|
| + CHECK_EQ(32640, result->Int32Value());
|
| +
|
| free(pixel_data);
|
| }
|
|
|
| @@ -10809,10 +10956,61 @@
|
| }
|
|
|
|
|
| +static v8::Handle<Value> NotHandledIndexedPropertyGetter(
|
| + uint32_t index,
|
| + const AccessorInfo& info) {
|
| + ApiTestFuzzer::Fuzz();
|
| + return v8::Handle<Value>();
|
| +}
|
| +
|
| +
|
| +static v8::Handle<Value> NotHandledIndexedPropertySetter(
|
| + uint32_t index,
|
| + Local<Value> value,
|
| + const AccessorInfo& info) {
|
| + ApiTestFuzzer::Fuzz();
|
| + return v8::Handle<Value>();
|
| +}
|
| +
|
| +
|
| +THREADED_TEST(PixelArrayWithInterceptor) {
|
| + v8::HandleScope scope;
|
| + LocalContext context;
|
| + const int kElementCount = 260;
|
| + uint8_t* pixel_data = reinterpret_cast<uint8_t*>(malloc(kElementCount));
|
| + i::Handle<i::ExternalPixelArray> pixels =
|
| + i::Handle<i::ExternalPixelArray>::cast(
|
| + i::Factory::NewExternalArray(kElementCount,
|
| + v8::kExternalPixelArray,
|
| + pixel_data));
|
| + for (int i = 0; i < kElementCount; i++) {
|
| + pixels->set(i, i % 256);
|
| + }
|
| + v8::Handle<v8::ObjectTemplate> templ = v8::ObjectTemplate::New();
|
| + templ->SetIndexedPropertyHandler(NotHandledIndexedPropertyGetter,
|
| + NotHandledIndexedPropertySetter);
|
| + v8::Handle<v8::Object> obj = templ->NewInstance();
|
| + obj->SetIndexedPropertiesToPixelData(pixel_data, kElementCount);
|
| + context->Global()->Set(v8_str("pixels"), obj);
|
| + v8::Handle<v8::Value> result = CompileRun("pixels[1]");
|
| + CHECK_EQ(1, result->Int32Value());
|
| + result = CompileRun("var sum = 0;"
|
| + "for (var i = 0; i < 8; i++) {"
|
| + " sum += pixels[i] = pixels[i] = -i;"
|
| + "}"
|
| + "sum;");
|
| + CHECK_EQ(-28, result->Int32Value());
|
| + result = CompileRun("pixels.hasOwnProperty('1')");
|
| + CHECK(result->BooleanValue());
|
| + free(pixel_data);
|
| +}
|
| +
|
| +
|
| static int ExternalArrayElementSize(v8::ExternalArrayType array_type) {
|
| switch (array_type) {
|
| case v8::kExternalByteArray:
|
| case v8::kExternalUnsignedByteArray:
|
| + case v8::kExternalPixelArray:
|
| return 1;
|
| break;
|
| case v8::kExternalShortArray:
|
| @@ -11034,8 +11232,10 @@
|
| " ext_array[i] = Infinity;"
|
| "}"
|
| "ext_array[5];");
|
| - CHECK_EQ(0, result->Int32Value());
|
| - CHECK_EQ(0,
|
| + int expected_value =
|
| + (array_type == v8::kExternalPixelArray) ? 255 : 0;
|
| + CHECK_EQ(expected_value, result->Int32Value());
|
| + CHECK_EQ(expected_value,
|
| i::Smi::cast(jsobj->GetElement(5)->ToObjectChecked())->value());
|
|
|
| result = CompileRun("for (var i = 0; i < 8; i++) {"
|
| @@ -11056,10 +11256,14 @@
|
| const char* signed_data =
|
| "var source_data = [0.6, 10.6, -0.6, -10.6];"
|
| "var expected_results = [0, 10, 0, -10];";
|
| + const char* pixel_data =
|
| + "var source_data = [0.6, 10.6];"
|
| + "var expected_results = [1, 11];";
|
| bool is_unsigned =
|
| (array_type == v8::kExternalUnsignedByteArray ||
|
| array_type == v8::kExternalUnsignedShortArray ||
|
| array_type == v8::kExternalUnsignedIntArray);
|
| + bool is_pixel_data = array_type == v8::kExternalPixelArray;
|
|
|
| i::OS::SNPrintF(test_buf,
|
| "%s"
|
| @@ -11072,7 +11276,9 @@
|
| " (ext_array[5] == expected_results[i]);"
|
| "}"
|
| "all_passed;",
|
| - (is_unsigned ? unsigned_data : signed_data));
|
| + (is_unsigned ?
|
| + unsigned_data :
|
| + (is_pixel_data ? pixel_data : signed_data)));
|
| result = CompileRun(test_buf.start());
|
| CHECK_EQ(true, result->BooleanValue());
|
| }
|
| @@ -11203,6 +11409,14 @@
|
| }
|
|
|
|
|
| +THREADED_TEST(ExternalPixelArray) {
|
| + ExternalArrayTestHelper<i::ExternalPixelArray, uint8_t>(
|
| + v8::kExternalPixelArray,
|
| + 0,
|
| + 255);
|
| +}
|
| +
|
| +
|
| THREADED_TEST(ExternalShortArray) {
|
| ExternalArrayTestHelper<i::ExternalShortArray, int16_t>(
|
| v8::kExternalShortArray,
|
| @@ -11280,6 +11494,7 @@
|
| ExternalArrayInfoTestHelper(v8::kExternalIntArray);
|
| ExternalArrayInfoTestHelper(v8::kExternalUnsignedIntArray);
|
| ExternalArrayInfoTestHelper(v8::kExternalFloatArray);
|
| + ExternalArrayInfoTestHelper(v8::kExternalPixelArray);
|
| }
|
|
|
|
|
|
|