Line data Source code
1 : // Copyright 2018 the V8 project authors. All rights reserved.
2 : // Use of this source code is governed by a BSD-style license that can be
3 : // found in the LICENSE file.
4 :
5 : #include "include/v8.h"
6 :
7 : #include "src/code-desc.h"
8 : #include "src/handles-inl.h"
9 : #include "src/isolate.h"
10 : #include "test/cctest/cctest.h"
11 :
12 : namespace v8 {
13 : namespace internal {
14 : namespace test_factory {
15 :
16 26644 : TEST(Factory_NewCode) {
17 5 : LocalContext env;
18 5 : v8::Isolate* isolate = env->GetIsolate();
19 : Isolate* i_isolate = reinterpret_cast<Isolate*>(isolate);
20 : HandleScope scope(i_isolate);
21 :
22 : // Create a big function that ends up in CODE_LO_SPACE.
23 : const int instruction_size = kMaxRegularHeapObjectSize + 1;
24 5 : std::unique_ptr<byte[]> instructions(new byte[instruction_size]);
25 :
26 5 : CodeDesc desc;
27 5 : desc.buffer = instructions.get();
28 5 : desc.buffer_size = instruction_size;
29 5 : desc.instr_size = instruction_size;
30 : desc.reloc_size = 0;
31 : desc.constant_pool_size = 0;
32 : desc.unwinding_info = nullptr;
33 : desc.unwinding_info_size = 0;
34 : desc.origin = nullptr;
35 : Handle<Object> self_ref;
36 : Handle<Code> code =
37 5 : i_isolate->factory()->NewCode(desc, Code::WASM_FUNCTION, self_ref);
38 :
39 10 : CHECK(i_isolate->heap()->InSpace(*code, CODE_LO_SPACE));
40 : #if VERIFY_HEAP
41 : code->ObjectVerify(i_isolate);
42 : #endif
43 5 : }
44 :
45 : } // namespace test_factory
46 : } // namespace internal
47 79917 : } // namespace v8
|