dart-sdk/runtime/vm/stub_code_test.cc
Ryan Macnak b1c09ecd8f [vm] Make naming more consistent when converting between handles, tagged and untagged pointers.
Currently we have things called XPtr which are not what you get from ptr().

Old world:
handle->raw() returns RawObject* (tagged)
raw_obj->ptr() returns RawObject* (untagged)

After 6fe15f6df9:
handle->raw() returns ObjectPtr
obj_ptr->ptr() returns ObjectLayout*

New world:
handle->ptr() returns ObjectPtr
obj_ptr->untag() returns UntaggedObject*

TEST=ci
Change-Id: I6c7f34014cf20737607caaf84979838300d12df2
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/149367
Commit-Queue: Ryan Macnak <rmacnak@google.com>
Reviewed-by: Martin Kustermann <kustermann@google.com>
Reviewed-by: Siva Annamalai <asiva@google.com>
Reviewed-by: Vyacheslav Egorov <vegorov@google.com>
2021-01-15 23:32:02 +00:00

36 lines
1.5 KiB
C++

// Copyright (c) 2020, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
#include "vm/globals.h"
#include "vm/object.h"
#include "vm/symbols.h"
namespace dart {
// Add function to a class and that class to the class dictionary so that
// frame walking can be used.
const Function& RegisterFakeFunction(const char* name, const Code& code) {
Thread* thread = Thread::Current();
const String& class_name = String::Handle(Symbols::New(thread, "ownerClass"));
const Script& script = Script::Handle();
const Library& lib = Library::Handle(Library::CoreLibrary());
const Class& owner_class = Class::Handle(
Class::New(lib, class_name, script, TokenPosition::kNoSource));
const String& function_name = String::ZoneHandle(Symbols::New(thread, name));
const FunctionType& signature = FunctionType::ZoneHandle(FunctionType::New());
Function& function = Function::ZoneHandle(Function::New(
signature, function_name, UntaggedFunction::kRegularFunction, true, false,
false, false, false, owner_class, TokenPosition::kNoSource));
const Array& functions = Array::Handle(Array::New(1));
functions.SetAt(0, function);
{
SafepointWriteRwLocker ml(thread, thread->isolate_group()->program_lock());
owner_class.SetFunctions(functions);
}
lib.AddClass(owner_class);
function.AttachCode(code);
return function;
}
} // namespace dart