preparser-unittest.cc 1.04 KB
Newer Older
1 2 3 4
// Copyright 2017 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

5
#include "src/api/api-inl.h"
6
#include "src/objects/objects-inl.h"
7 8 9 10 11 12 13
#include "test/unittests/test-helpers.h"
#include "test/unittests/test-utils.h"
#include "testing/gtest/include/gtest/gtest.h"

namespace v8 {
namespace internal {

14
class PreParserTest : public TestWithNativeContext {
15
 public:
16
  PreParserTest() = default;
17 18 19 20 21 22 23 24

 private:
  DISALLOW_COPY_AND_ASSIGN(PreParserTest);
};

TEST_F(PreParserTest, LazyFunctionLength) {
  const char* script_source = "function lazy(a, b, c) { } lazy";

25
  Handle<JSFunction> lazy_function = RunJS<JSFunction>(script_source);
26

27 28
  Handle<SharedFunctionInfo> shared(lazy_function->shared(),
                                    lazy_function->GetIsolate());
29
  CHECK_EQ(3, shared->length());
30

31
  Handle<Smi> length = RunJS<Smi>("lazy.length");
32 33 34 35 36 37 38
  int32_t value;
  CHECK(length->ToInt32(&value));
  CHECK_EQ(3, value);
}

}  // namespace internal
}  // namespace v8