OLD | NEW |
1 // Copyright 2014 PDFium Authors. All rights reserved. | 1 // Copyright 2014 PDFium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com | 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com |
6 | 6 |
7 #include "fpdfsdk/include/jsapi/fxjs_v8.h" | 7 #include "fpdfsdk/include/jsapi/fxjs_v8.h" |
8 | 8 |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
(...skipping 274 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
285 CFX_ByteString bsMethodName = CFX_WideString(sMethodName).UTF8Encode(); | 285 CFX_ByteString bsMethodName = CFX_WideString(sMethodName).UTF8Encode(); |
286 GetGlobalObjectTemplate(pIsolate) | 286 GetGlobalObjectTemplate(pIsolate) |
287 ->Set(v8::String::NewFromUtf8(pIsolate, bsMethodName.c_str(), | 287 ->Set(v8::String::NewFromUtf8(pIsolate, bsMethodName.c_str(), |
288 v8::NewStringType::kNormal) | 288 v8::NewStringType::kNormal) |
289 .ToLocalChecked(), | 289 .ToLocalChecked(), |
290 v8::FunctionTemplate::New(pIsolate, pMethodCall), v8::ReadOnly); | 290 v8::FunctionTemplate::New(pIsolate, pMethodCall), v8::ReadOnly); |
291 } | 291 } |
292 | 292 |
293 void FXJS_DefineGlobalConst(v8::Isolate* pIsolate, | 293 void FXJS_DefineGlobalConst(v8::Isolate* pIsolate, |
294 const wchar_t* sConstName, | 294 const wchar_t* sConstName, |
295 v8::Local<v8::Value> pDefault) { | 295 v8::FunctionCallback pConstGetter) { |
296 v8::Isolate::Scope isolate_scope(pIsolate); | 296 v8::Isolate::Scope isolate_scope(pIsolate); |
297 v8::HandleScope handle_scope(pIsolate); | 297 v8::HandleScope handle_scope(pIsolate); |
298 CFX_ByteString bsConst = CFX_WideString(sConstName).UTF8Encode(); | 298 CFX_ByteString bsConst = CFX_WideString(sConstName).UTF8Encode(); |
299 GetGlobalObjectTemplate(pIsolate)->Set( | 299 GetGlobalObjectTemplate(pIsolate) |
300 v8::String::NewFromUtf8(pIsolate, bsConst.c_str(), | 300 ->SetAccessorProperty(v8::String::NewFromUtf8(pIsolate, bsConst.c_str(), |
301 v8::NewStringType::kNormal).ToLocalChecked(), | 301 v8::NewStringType::kNormal) |
302 pDefault, v8::ReadOnly); | 302 .ToLocalChecked(), |
| 303 v8::FunctionTemplate::New(pIsolate, pConstGetter)); |
303 } | 304 } |
304 | 305 |
305 void FXJS_InitializeRuntime( | 306 void FXJS_InitializeRuntime( |
306 v8::Isolate* pIsolate, | 307 v8::Isolate* pIsolate, |
307 IJS_Runtime* pIRuntime, | 308 IJS_Runtime* pIRuntime, |
308 v8::Global<v8::Context>* pV8PersistentContext, | 309 v8::Global<v8::Context>* pV8PersistentContext, |
309 std::vector<v8::Global<v8::Object>*>* pStaticObjects) { | 310 std::vector<v8::Global<v8::Object>*>* pStaticObjects) { |
310 if (pIsolate == g_isolate) | 311 if (pIsolate == g_isolate) |
311 ++g_isolate_ref_count; | 312 ++g_isolate_ref_count; |
312 | 313 |
(...skipping 500 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
813 v8::Local<v8::Value> pValue) { | 814 v8::Local<v8::Value> pValue) { |
814 if (pValue.IsEmpty()) | 815 if (pValue.IsEmpty()) |
815 return v8::Local<v8::Array>(); | 816 return v8::Local<v8::Array>(); |
816 v8::Local<v8::Context> context = pIsolate->GetCurrentContext(); | 817 v8::Local<v8::Context> context = pIsolate->GetCurrentContext(); |
817 return v8::Local<v8::Array>::Cast(pValue->ToObject(context).ToLocalChecked()); | 818 return v8::Local<v8::Array>::Cast(pValue->ToObject(context).ToLocalChecked()); |
818 } | 819 } |
819 | 820 |
820 void FXJS_ValueCopy(v8::Local<v8::Value>& pTo, v8::Local<v8::Value> pFrom) { | 821 void FXJS_ValueCopy(v8::Local<v8::Value>& pTo, v8::Local<v8::Value> pFrom) { |
821 pTo = pFrom; | 822 pTo = pFrom; |
822 } | 823 } |
OLD | NEW |