[M120 Migration] Set IO|GPU thread type with higher priorites
[platform/framework/web/chromium-efl.git] / gin / function_template.cc
1 // Copyright 2013 The Chromium Authors
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 "gin/function_template.h"
6
7 #include "base/strings/strcat.h"
8
9 namespace gin {
10
11 namespace internal {
12
13 CallbackHolderBase::CallbackHolderBase(v8::Isolate* isolate)
14     : v8_ref_(isolate, v8::External::New(isolate, this)) {
15   v8_ref_.SetWeak(this, &CallbackHolderBase::FirstWeakCallback,
16                   v8::WeakCallbackType::kParameter);
17 }
18
19 CallbackHolderBase::~CallbackHolderBase() {
20   DCHECK(v8_ref_.IsEmpty());
21 }
22
23 v8::Local<v8::External> CallbackHolderBase::GetHandle(v8::Isolate* isolate) {
24   return v8::Local<v8::External>::New(isolate, v8_ref_);
25 }
26
27 // static
28 void CallbackHolderBase::FirstWeakCallback(
29     const v8::WeakCallbackInfo<CallbackHolderBase>& data) {
30   data.GetParameter()->v8_ref_.Reset();
31   data.SetSecondPassCallback(SecondWeakCallback);
32 }
33
34 // static
35 void CallbackHolderBase::SecondWeakCallback(
36     const v8::WeakCallbackInfo<CallbackHolderBase>& data) {
37   delete data.GetParameter();
38 }
39
40 void ThrowConversionError(Arguments* args,
41                           const InvokerOptions& invoker_options,
42                           size_t index) {
43   if (index == 0 && invoker_options.holder_is_first_argument) {
44     // Failed to get the appropriate `this` object. This can happen if a
45     // method is invoked using Function.prototype.[call|apply] and passed an
46     // invalid (or null) `this` argument.
47     std::string error =
48         invoker_options.holder_type
49             ? base::StrCat({"Illegal invocation: Function must be "
50                             "called on an object of type ",
51                             invoker_options.holder_type})
52             : "Illegal invocation";
53     args->ThrowTypeError(error);
54   } else {
55     // Otherwise, this failed parsing on a different argument.
56     // Arguments::ThrowError() will try to include appropriate information.
57     // Ideally we would include the expected c++ type in the error message
58     // here, too (which we can access via typeid(ArgType).name()), however we
59     // compile with no-rtti, which disables typeid.
60     args->ThrowError();
61   }
62 }
63
64 }  // namespace internal
65
66 }  // namespace gin