OLD | NEW |
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 21427 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
21438 } | 21438 } |
21439 obj->ForceSet(v8_str("foo"), v8_num(1), v8::None); | 21439 obj->ForceSet(v8_str("foo"), v8_num(1), v8::None); |
21440 obj->ForceSet(v8_str("2"), v8_num(1), v8::None); | 21440 obj->ForceSet(v8_str("2"), v8_num(1), v8::None); |
21441 CHECK(obj->HasOwnProperty(v8_str("foo"))); | 21441 CHECK(obj->HasOwnProperty(v8_str("foo"))); |
21442 CHECK(obj->HasOwnProperty(v8_str("2"))); | 21442 CHECK(obj->HasOwnProperty(v8_str("2"))); |
21443 CHECK(!obj->Delete(v8_str("foo"))); | 21443 CHECK(!obj->Delete(v8_str("foo"))); |
21444 CHECK(!obj->Delete(2)); | 21444 CHECK(!obj->Delete(2)); |
21445 } | 21445 } |
21446 | 21446 |
21447 | 21447 |
| 21448 static void ExtrasExportsTestRuntimeFunction( |
| 21449 const v8::FunctionCallbackInfo<v8::Value>& args) { |
| 21450 CHECK_EQ(3, args[0]->Int32Value()); |
| 21451 args.GetReturnValue().Set(v8_num(7)); |
| 21452 } |
| 21453 |
| 21454 |
21448 TEST(ExtrasExportsObject) { | 21455 TEST(ExtrasExportsObject) { |
21449 v8::Isolate* isolate = CcTest::isolate(); | 21456 v8::Isolate* isolate = CcTest::isolate(); |
21450 v8::HandleScope handle_scope(isolate); | 21457 v8::HandleScope handle_scope(isolate); |
21451 LocalContext env; | 21458 LocalContext env; |
21452 | 21459 |
21453 // standalone.gypi ensures we include the test-extra.js file, which should | 21460 // standalone.gypi ensures we include the test-extra.js file, which should |
21454 // add the testExtraShouldReturnFive export | 21461 // export the tested functions. |
21455 v8::Local<v8::Object> exports = env->GetExtrasExportsObject(); | 21462 v8::Local<v8::Object> exports = env->GetExtrasExportsObject(); |
21456 | 21463 |
21457 auto func = | 21464 auto func = |
21458 exports->Get(v8_str("testExtraShouldReturnFive")).As<v8::Function>(); | 21465 exports->Get(v8_str("testExtraShouldReturnFive")).As<v8::Function>(); |
21459 auto undefined = v8::Undefined(isolate); | 21466 auto undefined = v8::Undefined(isolate); |
21460 auto result = func->Call(undefined, 0, {}).As<v8::Number>(); | 21467 auto result = func->Call(undefined, 0, {}).As<v8::Number>(); |
| 21468 CHECK_EQ(5, result->Int32Value()); |
21461 | 21469 |
21462 CHECK(result->Value() == 5.0); | 21470 v8::Handle<v8::FunctionTemplate> runtimeFunction = |
| 21471 v8::FunctionTemplate::New(isolate, ExtrasExportsTestRuntimeFunction); |
| 21472 exports->Set(v8_str("runtime"), runtimeFunction->GetFunction()); |
| 21473 func = |
| 21474 exports->Get(v8_str("testExtraShouldCallToRuntime")).As<v8::Function>(); |
| 21475 result = func->Call(undefined, 0, {}).As<v8::Number>(); |
| 21476 CHECK_EQ(7, result->Int32Value()); |
21463 } | 21477 } |
21464 | 21478 |
21465 | 21479 |
21466 TEST(Map) { | 21480 TEST(Map) { |
21467 v8::Isolate* isolate = CcTest::isolate(); | 21481 v8::Isolate* isolate = CcTest::isolate(); |
21468 v8::HandleScope handle_scope(isolate); | 21482 v8::HandleScope handle_scope(isolate); |
21469 LocalContext env; | 21483 LocalContext env; |
21470 | 21484 |
21471 v8::Local<v8::Map> map = v8::Map::New(isolate); | 21485 v8::Local<v8::Map> map = v8::Map::New(isolate); |
21472 CHECK(map->IsObject()); | 21486 CHECK(map->IsObject()); |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
21512 CHECK_EQ(2U, set->Size()); | 21526 CHECK_EQ(2U, set->Size()); |
21513 | 21527 |
21514 v8::Local<v8::Array> keys = set->AsArray(); | 21528 v8::Local<v8::Array> keys = set->AsArray(); |
21515 CHECK_EQ(2U, keys->Length()); | 21529 CHECK_EQ(2U, keys->Length()); |
21516 CHECK_EQ(1, keys->Get(0).As<v8::Int32>()->Value()); | 21530 CHECK_EQ(1, keys->Get(0).As<v8::Int32>()->Value()); |
21517 CHECK_EQ(2, keys->Get(1).As<v8::Int32>()->Value()); | 21531 CHECK_EQ(2, keys->Get(1).As<v8::Int32>()->Value()); |
21518 | 21532 |
21519 set = v8::Set::FromArray(env.local(), keys).ToLocalChecked(); | 21533 set = v8::Set::FromArray(env.local(), keys).ToLocalChecked(); |
21520 CHECK_EQ(2U, set->Size()); | 21534 CHECK_EQ(2U, set->Size()); |
21521 } | 21535 } |
OLD | NEW |