OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2009 Google Inc. All rights reserved. | 2 * Copyright (C) 2009 Google Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
6 * met: | 6 * met: |
7 * | 7 * |
8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
77 void DateExtension::setAllowSleep(bool allow, v8::Isolate* isolate) | 77 void DateExtension::setAllowSleep(bool allow, v8::Isolate* isolate) |
78 { | 78 { |
79 v8::Local<v8::Value> result = v8::Context::GetCurrent()->Global()->Get(v8::S
tring::NewSymbol("Date")); | 79 v8::Local<v8::Value> result = v8::Context::GetCurrent()->Global()->Get(v8::S
tring::NewSymbol("Date")); |
80 if (result.IsEmpty() || !result->IsObject()) | 80 if (result.IsEmpty() || !result->IsObject()) |
81 return; | 81 return; |
82 | 82 |
83 v8::Handle<v8::Object> dateObject = v8::Handle<v8::Object>::Cast(result); | 83 v8::Handle<v8::Object> dateObject = v8::Handle<v8::Object>::Cast(result); |
84 if (dateObject.IsEmpty()) | 84 if (dateObject.IsEmpty()) |
85 return; | 85 return; |
86 | 86 |
87 v8::Local<v8::Value> sleepFunctionHandle = dateObject->GetHiddenValue(V8Hidd
enPropertyName::sleepFunction()); | 87 v8::Local<v8::Value> sleepFunctionHandle = dateObject->GetHiddenValue(V8Hidd
enPropertyName::sleepFunction(isolate)); |
88 if (sleepFunctionHandle.IsEmpty() || !sleepFunctionHandle->IsFunction()) | 88 if (sleepFunctionHandle.IsEmpty() || !sleepFunctionHandle->IsFunction()) |
89 return; | 89 return; |
90 | 90 |
91 v8::Handle<v8::Value> argv[1]; | 91 v8::Handle<v8::Value> argv[1]; |
92 argv[0] = v8::Boolean::New(!allow); | 92 argv[0] = v8::Boolean::New(!allow); |
93 V8ScriptRunner::callInternalFunction(v8::Handle<v8::Function>::Cast(sleepFun
ctionHandle), v8::Object::New(), WTF_ARRAY_LENGTH(argv), argv, isolate); | 93 V8ScriptRunner::callInternalFunction(v8::Handle<v8::Function>::Cast(sleepFun
ctionHandle), v8::Object::New(), WTF_ARRAY_LENGTH(argv), argv, isolate); |
94 } | 94 } |
95 | 95 |
96 v8::Handle<v8::FunctionTemplate> DateExtension::GetNativeFunction(v8::Handle<v8:
:String> name) | 96 v8::Handle<v8::FunctionTemplate> DateExtension::GetNativeFunction(v8::Handle<v8:
:String> name) |
97 { | 97 { |
98 if (name->Equals(v8::String::NewSymbol("Setup"))) | 98 if (name->Equals(v8::String::NewSymbol("Setup"))) |
99 return v8::FunctionTemplate::New(Setup); | 99 return v8::FunctionTemplate::New(Setup); |
100 if (name->Equals(v8::String::NewSymbol("OnSleepDetected"))) | 100 if (name->Equals(v8::String::NewSymbol("OnSleepDetected"))) |
101 return v8::FunctionTemplate::New(OnSleepDetected); | 101 return v8::FunctionTemplate::New(OnSleepDetected); |
102 | 102 |
103 return v8::Handle<v8::FunctionTemplate>(); | 103 return v8::Handle<v8::FunctionTemplate>(); |
104 } | 104 } |
105 | 105 |
106 void DateExtension::Setup(const v8::FunctionCallbackInfo<v8::Value>& args) | 106 void DateExtension::Setup(const v8::FunctionCallbackInfo<v8::Value>& args) |
107 { | 107 { |
108 if (args.Length() != 2 || !args[0]->IsObject() || !args[1]->IsFunction()) | 108 if (args.Length() != 2 || !args[0]->IsObject() || !args[1]->IsFunction()) |
109 return; | 109 return; |
110 | 110 |
111 v8::Handle<v8::Object> dateObject = v8::Handle<v8::Object>::Cast(args[0]); | 111 v8::Handle<v8::Object> dateObject = v8::Handle<v8::Object>::Cast(args[0]); |
112 v8::Handle<v8::Function> enableSleepDetectionFunction = v8::Handle<v8::Funct
ion>::Cast(args[1]); | 112 v8::Handle<v8::Function> enableSleepDetectionFunction = v8::Handle<v8::Funct
ion>::Cast(args[1]); |
113 | 113 |
114 dateObject->SetHiddenValue(V8HiddenPropertyName::sleepFunction(), enableSlee
pDetectionFunction); | 114 dateObject->SetHiddenValue(V8HiddenPropertyName::sleepFunction(args.GetIsola
te()), enableSleepDetectionFunction); |
115 return; | 115 return; |
116 } | 116 } |
117 | 117 |
118 void DateExtension::OnSleepDetected(const v8::FunctionCallbackInfo<v8::Value>& a
rgs) | 118 void DateExtension::OnSleepDetected(const v8::FunctionCallbackInfo<v8::Value>& a
rgs) |
119 { | 119 { |
120 throwError(v8GeneralError, "Too much time spent in unload handler.", args.Ge
tIsolate()); | 120 throwError(v8GeneralError, "Too much time spent in unload handler.", args.Ge
tIsolate()); |
121 } | 121 } |
122 | 122 |
123 } // namespace WebCore | 123 } // namespace WebCore |
OLD | NEW |