2 * Copyright (c) 2015 Samsung Electronics Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
19 #include "path-constraint-wrapper.h"
23 #include <dali-wrapper.h>
24 #include <shared/object-template-helper.h>
32 PathConstraintWrapper::PathConstraintWrapper( PathConstraint pathConstraint, GarbageCollectorInterface& gc )
33 :HandleWrapper( BaseWrappedObject::PATH_CONSTRAINT, pathConstraint, gc ),
34 mPathConstraint( pathConstraint )
38 v8::Handle<v8::ObjectTemplate> PathConstraintWrapper::MakePathConstraintTemplate( v8::Isolate* isolate )
40 v8::EscapableHandleScope handleScope( isolate );
42 v8::Local<v8::ObjectTemplate> objTemplate = v8::ObjectTemplate::New();
43 objTemplate->SetInternalFieldCount( BaseWrappedObject::FIELD_COUNT );
45 // property handle intercepts property getters and setters and signals
46 HandleWrapper::AddInterceptsToTemplate( isolate, objTemplate );
48 return handleScope.Escape( objTemplate );
51 v8::Handle<v8::Object> PathConstraintWrapper::WrapPathConstraint( v8::Isolate* isolate, PathConstraint pathConstraint )
53 v8::EscapableHandleScope handleScope( isolate );
54 v8::Local<v8::ObjectTemplate> objectTemplate;
56 objectTemplate = MakePathConstraintTemplate( isolate );
58 // create an instance of the template
59 v8::Local<v8::Object> localObject = objectTemplate->NewInstance();
61 // create the pathconstraint object
62 PathConstraintWrapper* pointer = new PathConstraintWrapper( pathConstraint, Dali::V8Plugin::DaliWrapper::Get().GetDaliGarbageCollector() );
64 // assign the JavaScript object to the wrapper.
65 // This also stores Dali object, in an internal field inside the JavaScript object.
66 pointer->SetJavascriptObject( isolate, localObject );
68 return handleScope.Escape( localObject );
71 PathConstraint PathConstraintWrapper::GetPathConstraint()
73 return mPathConstraint;
77 * Create an initialized PathConstraint handle.
82 void PathConstraintWrapper::NewPathConstraint( const v8::FunctionCallbackInfo< v8::Value >& args)
84 v8::Isolate* isolate = args.GetIsolate();
85 v8::HandleScope handleScope( isolate );
87 if( !args.IsConstructCall() )
89 DALI_SCRIPT_EXCEPTION( isolate, "constructor called without 'new" );
95 Handle pathHandle = V8Utils::GetHandleParameter( PARAMETER_0, parameterFound, isolate, args );
98 DALI_SCRIPT_EXCEPTION( isolate, "bad parameter 0 (Path)" );
101 Dali::Path path = Path::DownCast(pathHandle);
104 Vector2 range = V8Utils::GetVector2Parameter( PARAMETER_1, parameterFound, isolate, args );
105 if( !parameterFound )
107 DALI_SCRIPT_EXCEPTION( isolate, "bad parameter 1 (Range)" );
111 PathConstraint pathConstraint = PathConstraint::New(path, range );
112 v8::Local<v8::Object> localObject = WrapPathConstraint( isolate, pathConstraint );
113 args.GetReturnValue().Set( localObject );
117 } // namespace V8Plugin